#pragma once #include <SNMP.h> using SNMP::IntegerBER; using SNMP::OctetStringBER; using SNMP::OpaqueBER; using SNMP::OpaqueFloatBER; using SNMP::VarBind; using SNMP::VarBindList; class MPOD { public: // Simple helper class to handle OIDs class OID { public: enum { OUTPUTSTATUS, OUTPUTMEASUREMENTSENSEVOLTAGE, OUTPUTMEASUREMENTCURRENT, OUTPUTSWITCH, OUTPUTVOLTAGE, OUTPUTCURRENT, OUTPUTVOLTAGERISERATE, UNKNOWN, COUNT = UNKNOWN, }; static inline const char *NAMES[] = { // These are incomplete SNMP commands needing to be // formatted with the channel id after the final dot "1.3.6.1.4.1.19947.1.3.2.1.4.", "1.3.6.1.4.1.19947.1.3.2.1.5.", "1.3.6.1.4.1.19947.1.3.2.1.7.", "1.3.6.1.4.1.19947.1.3.2.1.9.", "1.3.6.1.4.1.19947.1.3.2.1.10.", "1.3.6.1.4.1.19947.1.3.2.1.12.", "1.3.6.1.4.1.19947.1.3.2.1.13.", }; // Returns index of OID equals to name // Returns UNKNOWN if none static unsigned int match(const char *name) { for (unsigned int index = 0; index < COUNT; ++index) { if (strstr(name, NAMES[index])) { return index; } } return UNKNOWN; } }; // Create an SNMP SETREQUEST message to setup MPOD MPOD(); SNMP::Message* read(const uint16_t); SNMP::Message* output(const uint16_t, const bool); bool message(const SNMP::Message*); bool isOn() const; bool isRampingUp() const; bool isRampingDown() const; float getMeasurementSenseVoltage() const; float getMeasurementCurrent() const; float getVoltage() const; float getCurrent() const; float getVoltageRiseRate() const; uint16_t getChannel() const; String toJSON(); private: unsigned int getIntegerFromVarBind(const VarBind*); float getFloatFromVarBind(const VarBind*); uint16_t _channel; bool _on; bool _rampingUp; bool _rampingDown; float _measurementSenseVoltage; float _measurementCurrent; float _voltage; float _current; float _voltageRiseRate; }; extern SNMP::Manager snmp; extern MPOD mpod; // Event handler to process SNMP messages void onSNMPMessage(const SNMP::Message *message, const IPAddress remote, const uint16_t port); void initializeSNMP();