#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[] = { "1.3.6.1.4.1.19947.1.3.2.1.4.1", "1.3.6.1.4.1.19947.1.3.2.1.5.1", "1.3.6.1.4.1.19947.1.3.2.1.7.1", "1.3.6.1.4.1.19947.1.3.2.1.9.1", "1.3.6.1.4.1.19947.1.3.2.1.10.1", "1.3.6.1.4.1.19947.1.3.2.1.12.1", "1.3.6.1.4.1.19947.1.3.2.1.13.1", }; // 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 (strcmp(NAMES[index], name) == 0) { return index; } } return UNKNOWN; } }; // Create an SNMP SETREQUEST message to setup MPOD MPOD(); SNMP::Message* setup(); SNMP::Message* read(); SNMP::Message* output(const bool); bool message(const SNMP::Message*); bool isOn() const; bool isUp() const; bool isDown() const; float getMeasurementSenseVoltage() const; float getMeasurementCurrent() const; float getVoltage() const; float getCurrent() const; float getVoltageRiseRate() const; private: unsigned int getIntegerFromVarBind(const VarBind*); float getFloatFromVarBind(const VarBind*); bool _on; bool _up; bool _down; 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();