Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#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();