It's true that it was 'mainly' used to manage network-infrastructure devices (hubs, switches, gateways, DSL modems), but suitable and also used for all kind of network-connected devices. Previous to IOT-related explosion, it was (and still is, in many areas) one of the high-level standards for automated managing of network-deployed devices.I though that SNMP was only used to manage networks.
thanks@takhmin77 try this library with Arduino IDE: https://github.com/MikaelSchultz/Arduino-Snmp-Agent
If it works for you then it is possible to configure it with inline C and then update the "int_value" or "str_value" from the B4R code.
#include <Streaming.h> // Include the Streaming library
#include <Ethernet.h> // Include the Ethernet library
#include <MemoryFree.h>
#include <Agentuino.h>
#include <Flash.h>
//
#define DEBUG
//
static byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
static byte ip[] = { 192, 168,0, 184 };
static byte gateway[] = { 192, 168, 0, 2 };
static byte subnet[] = { 255, 255, 255, 0 };
static byte ServerIP[4] = {192, 168, 0, 64}; // The IP address of the server that will receive the trap
const static char sysUpTime[] PROGMEM = "1.3.6.1.2.1.1.3.0"; // read-only (TimeTicks)
const static char sysName[] PROGMEM = "1.3.6.1.2.1.1.5.0"; // read-write (DisplayString)
static uint32_t locUpTime = 0; // read-only (static)
static char locName[20] = "Amir Reza Amiri"; //read write
uint32_t prevMillis = millis();
char oid[SNMP_MAX_OID_LEN];
SNMP_API_STAT_CODES api_status;
SNMP_ERR_CODES status;
void pduReceived()
{
SNMP_PDU pdu;
Serial << F("UDP Packet Received Start..") << F(" RAM:") << freeMemory() << endl;
api_status = Agentuino.requestPdu(&pdu);
if ( pdu.type == SNMP_PDU_GET || pdu.type == SNMP_PDU_GET_NEXT || pdu.type == SNMP_PDU_SET
&& pdu.error == SNMP_ERR_NO_ERROR && api_status == SNMP_API_STAT_SUCCESS ) {
pdu.OID.toString(oid);
if ( strcmp_P(oid, sysUpTime ) == 0 ) {
if ( pdu.type == SNMP_PDU_SET ) {
pdu.type = SNMP_PDU_RESPONSE;
pdu.error = SNMP_ERR_READ_ONLY;
} else {
status = pdu.VALUE.encode(SNMP_SYNTAX_TIME_TICKS, locUpTime);
pdu.type = SNMP_PDU_RESPONSE;
pdu.error = status;
}
Serial << F("sysUpTime...") << locUpTime << F(" ") << pdu.VALUE.size << endl;
} else if ( strcmp_P(oid, sysName ) == 0 ) {
if ( pdu.type == SNMP_PDU_SET ) {
status = pdu.VALUE.decode(locName, strlen(locName));
pdu.type = SNMP_PDU_RESPONSE;
pdu.error = status;
} else {
status = pdu.VALUE.encode(SNMP_SYNTAX_OCTETS, locName);
pdu.type = SNMP_PDU_RESPONSE;
pdu.error = status;
}
Serial << F("sysName...") << locName << F(" ") << pdu.VALUE.size << endl;
}
else {
pdu.type = SNMP_PDU_RESPONSE;
pdu.error = SNMP_ERR_NO_SUCH_NAME;
}
Agentuino.responsePdu(&pdu);
}
Agentuino.freePdu(&pdu);
Serial << "UDP Packet Received End.." << " RAM:" << freeMemory() << endl;
}
void setup()
{
Serial.begin(9600);
Ethernet.begin(mac, ip);
api_status = Agentuino.begin();
if ( api_status == SNMP_API_STAT_SUCCESS ) {
Agentuino.onPduReceive(pduReceived);
delay(10);
Serial << F("SNMP Agent Initalized...") << endl;
return;
}
delay(10);
Serial << F("SNMP Agent Initalization Problem...") << status << endl;
}
void loop()
{
Agentuino.listen();
if ( millis() - prevMillis > 1000 ) {
prevMillis += 1000;
locUpTime += 100;
}
}
/**
* Agentuino SNMP Agent Library Prototyping...
*
* Copyright 2010 Eric C. Gionet <[email protected]>
*
* @Edit: M. Pivovarsky <[email protected]>
*
*/
#include "Streaming.h" // Include the Streaming library
#include <Ethernet.h> // Include the Ethernet library
#include <SPI.h>
#include "Agentuino.h"
IPAddress address;
static byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEF};
static byte ip[] = {192, 168, 0, 184};
static byte gateway[] = {192, 168, 0, 2};
static byte subnet[] = {255, 255, 255, 0};
static byte RemoteIP[4] = {192, 168, 0, 184}; // The IP address of the host that will receive the trap
void setup() {
Serial.begin(9600);
Serial.println("CPU Start");
pinMode(6, INPUT);
Ethernet.begin(mac,ip);
//Ethernet.begin(mac,ip,gateway,subnet);
IPAddress address = Ethernet.localIP();
for (uint8_t i=0;i<=4;i++) {
my_IP_address[i] = address[i];
Serial.print(my_IP_address[i]);
Serial.print(".");
}
Serial.println("");
api_status = Agentuino.begin();
if (api_status == SNMP_API_STAT_SUCCESS) {
Agentuino.onPduReceive(pduReceived);
delay(10);
Serial << F("SNMP Agent Initalized...") << endl;
return;
}
delay(10);
Serial << F("SNMP Agent Initalization Problem...") << status << endl;
}
void loop() {
// listen/handle for incoming SNMP requests
Agentuino.listen();
// Is pin 6 HIGH, send trap
if (digitalRead(6) == 0) {
Serial.println("Send TRAP");
// send trap
Agentuino.Trap("Arduino SNMP trap", RemoteIP, locUpTime);
//Agentuino.Trap("Arduino SNMP trap", RemoteIP, locUpTime, "1.3.6.1.4.1.28032.1.1.1");
//Agentuino.Trap("Arduino SNMP trap", RemoteIP, locUpTime, "1.3.6.1.4.1.36061.0", "1.3.6.1.4.1.36061.3.1.1.1");
delay(1000);
locUpTime = locUpTime + 100;
}
// sysUpTime - The time (in hundredths of a second) since
// the network management portion of the system was last
// re-initialized.
if (millis() - prevMillis > 1000) {
// increment previous milliseconds
prevMillis += 1000;
// increment up-time counter
locUpTime += 100;
}
}
can i use inline c code ?You will need to wrap this library. It requires some C++ knowledge.