24 static constexpr uint16_t
SNMP = 161;
25 static constexpr uint16_t
Trap = 162;
50 using Event = void (*)(
const Message*,
const IPAddress,
const uint16_t);
61 return _udp->begin(_port);
74 if (_udp->parsePacket()) {
76 message->
parse(*_udp);
77 _onMessage(message, _udp->remoteIP(), _udp->remotePort());
81 if (_udp->parsePacket()) {
82 uint32_t length = _udp->available();
83 uint8_t *buffer =
static_cast<uint8_t*
>(malloc(length));
85 _udp->read(buffer, length);
87 message->
parse(buffer);
89 _onMessage(message, _udp->remoteIP(), _udp->remotePort());
106 bool send(
Message *message,
const IPAddress ip,
const uint16_t port) {
108 _udp->beginPacket(ip, port);
109 message->
build(*_udp);
110 return _udp->endPacket();
112 uint32_t length = message->
getSize(
true);
113 uint8_t *buffer =
static_cast<uint8_t*
>(malloc(length));
114 message->
build(buffer);
115 _udp->beginPacket(ip, port);
116 _udp->write(buffer, length);
118 return _udp->endPacket();
Agent()
Creates an SNMP agent.
Manager()
Creates an SNMP manager.
void build()
Builds the message.
virtual const unsigned int getSize(const bool refresh=false)
Gets the size of the message.
void parse()
Parses the message.
void loop()
Network read operation.
bool send(Message *message, const IPAddress ip, const uint16_t port)
Network write operation.
void(*)(const Message *, const IPAddress, const uint16_t) Event
On message event user handler type.
bool begin(UDP &udp)
Initializes network.
SNMP(const uint16_t port)
Creates an SNMP object.
void onMessage(Event event)
Sets on message event user handler.
Helper struct to handle UDP ports.
static constexpr uint16_t SNMP
Helper struct to handle trap PDU.