Blynk as SNMP Network Monitoring

Hi friends. here my projects for live monitoring your network devices like Modem/Router etc… with SNMP protocol.
the Library:
https://github.com/Niich/Arduino_SNMP

in this project I’m monitoring the Mikrotik RB2011UiAS-2HnD router. the monitoring parameters I tested is Router voltage, RAM usage, Router temperature and Router CPU load.

the parameters can be read from SNMP OID of your Router/Modem.
first you need to enable the SNMP on your Modem/Router. it’s depending with your Modem/Router model which OID for what ! but don’t worry you can finding the specific OID of your Modem/Router with MIB Browser application. you can download it from here: http://www.ireasoning.com/mibbrowser.shtml

after downloading and installing the MIB browser, run the MIB browser then in the address write your router IP address then from operation select walk to listing all of your Modem/Router OID’s.

then find your own OID you want to monitoring and double click on it to showing the OID. for example I want to monitoring the system disk of my Modem/Router. the OID of my system disk Modem/Router is .1.3.6.1.2.1.25.2.3.1.3 ( it’s different for you ).

finally put this in the arduino sketch to reading the parameters from the blynk app.

snmp.addIntegerHandler(".1.3.6.1.2.1.25.2.3.1.3", &ram, true); //ram usage OID of your router or modem SNMP

and

callbackRA = snmp.findCallback(".1.3.6.1.2.1.25.2.3.1.3", false);

don’t forget to put your Modem/Router IP address in this line in the arduino sketch:
IPAddress netAdd = IPAddress(10,5,51,1);

the sketch:

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <WiFiUdp.h>
#include <Arduino_SNMP.h>

char auth[] = "81cc3c5ee9754be8ab6fa4a67d8d3be0";
const char* ssid = "MikroTik Tesla";
const char* password = "12345678";
char server[] = "10.5.51.5";

BlynkTimer timer;

unsigned int temp; //value in octets (we are counting them as bytes)
unsigned int volt;
unsigned int cpu;
unsigned int ram;

// initialise objects needed for SNMP
WiFiUDP udp; // UDP object used to send and recieve packets

SNMPAgent snmp = SNMPAgent("public");  // Starts an SMMPAgent instance with the community string 'public'
SNMPGet GetRequestUp = SNMPGet("public", 0); // Starts an SMMPGet instance with the community string 'public'
SNMPGet GetRequestDown = SNMPGet("public", 0); // Starts an SMMPGet instance with the community string 'public'
ValueCallback* callbackTEM;//blank callback pointer. every OID that you want to send a Get-request for needs one
ValueCallback* callbackVOL;
ValueCallback* callbackCP;
ValueCallback* callbackRA;

IPAddress netAdd = IPAddress(10,5,51,1); // IP address object of the device you want to get info from

void setup() 
{
  // put your setup code here, to run once:
  Serial.begin(115200);
  Blynk.begin(auth, ssid, password, server, 8080);
  Serial.println("");
  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) 
    {
      delay(500);
      Serial.print(".");
    }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("my IP address: ");
  Serial.println(WiFi.localIP());

  snmp.setUDP(&udp);// give snmp a pointer to the UDP object
  snmp.begin();// start the SNMP listener
  snmp.beginMaster(); // start the SNMP sender

  // OID for temp
  snmp.addIntegerHandler(".1.3.6.1.4.1.14988.1.1.3.10.0", &temp, true); // temperature OID of your router or modem SNMP

  // OID for volt
  snmp.addIntegerHandler(".1.3.6.1.4.1.14988.1.1.3.8.0", &volt, true); //voltage OID of your router or modem SNMP

    // OID for cpu
  snmp.addIntegerHandler(".1.3.6.1.2.1.25.3.3.1.2.1", &cpu, true); //cpu usage OID of your router or modem SNMP

    // OID for ram
  snmp.addIntegerHandler(".1.3.6.1.2.1.25.2.3.1.6", &ram, true); //ram usage OID of your router or modem SNMP

  //Create the call back ID's you will need to pass to the SNMP function
  callbackTEM = snmp.findCallback(".1.3.6.1.4.1.14988.1.1.3.10.0", false);    
  callbackVOL = snmp.findCallback(".1.3.6.1.4.1.14988.1.1.3.8.0", false);
  callbackCP = snmp.findCallback(".1.3.6.1.2.1.25.3.3.1.2.1", false);
  callbackRA = snmp.findCallback(".1.3.6.1.2.1.25.2.3.1.6", false);

  timer.setInterval(1000L, getSNMP);

}

void getSNMP(){
  //check to see if it is time to send an SNMP request.
  //if you send requests to often it seens to cause some issues
    
      //see the results of the get-request in the serial monitor
        Serial.print("temp: ");        
        Serial.print(temp);
        Blynk.virtualWrite(V12, temp / 10);
        Serial.println();
        Serial.print("volt: ");
        Serial.print(volt);
        Blynk.virtualWrite(V13, volt / 10);
        Serial.println();
        Serial.print("cpu: ");        
        Serial.print(cpu);
        Blynk.virtualWrite(V14, cpu);
        Serial.println();  
        Serial.print("ram: ");        
        Serial.print(ram);
        Blynk.virtualWrite(V15, ram / 1000);
        Serial.println();
        Serial.println("----------------------");

      //build a SNMP get-request
      GetRequestDown.addOIDPointer(callbackTEM);                
      GetRequestDown.setIP(WiFi.localIP()); //IP of the arduino                
      GetRequestDown.setUDP(&udp);
      GetRequestDown.setRequestID(rand() % 5555);
      GetRequestDown.sendTo(netAdd); //IP of the remote client
      GetRequestDown.clearOIDList();   
      snmp.resetSetOccurred();
      
      GetRequestUp.addOIDPointer(callbackVOL);                
      GetRequestUp.setIP(WiFi.localIP());                 
      GetRequestUp.setUDP(&udp);
      GetRequestUp.setRequestID(rand() % 5555);                
      GetRequestUp.sendTo(netAdd);               
      GetRequestUp.clearOIDList();
      snmp.resetSetOccurred();

      GetRequestDown.addOIDPointer(callbackCP);                
      GetRequestDown.setIP(WiFi.localIP());                 
      GetRequestDown.setUDP(&udp);
      GetRequestDown.setRequestID(rand() % 5555);                
      GetRequestDown.sendTo(netAdd);               
      GetRequestDown.clearOIDList();
      snmp.resetSetOccurred();

      GetRequestUp.addOIDPointer(callbackRA);                
      GetRequestUp.setIP(WiFi.localIP());                 
      GetRequestUp.setUDP(&udp);
      GetRequestUp.setRequestID(rand() % 5555);                
      GetRequestUp.sendTo(netAdd);               
      GetRequestUp.clearOIDList();
      snmp.resetSetOccurred();
}

void loop() {
  Blynk.run();
  timer.run();
  snmp.loop();
}

the screenshot:

Good luck :wink:

5 Likes

I love it!
I never knew this library existed

How well does the library handle a router reload?

Are you having good luck so far with that low of a polling interval?

timer.setInterval(1000L, getSNMP);
1 Like

Thanks. Cool (old and new) technology blend!

1 Like

I could hardly to find this library :sweat_smile: But I succeeded :yum:
yeah the data is loading without any problem with this interval.

Thank you. you’re welcome :rose:

I had a chance to implement SNMP management for one of industrial devices in the past. Nightmare.

2 Likes

What modifications are needed in the code to display the information on the serial monitor, using ethernet shild.

The sketch already has the ability to print the data to the serial monitor as well as to the Blynk app.
If you want to convert the code to work with an Arduino and Ethernet shield instead of an ESP8266 based device then you’d need to change to using the Blynk Ethernet library and change the WiFi connection code for Ethernet code.
If you look at the Sketch Builder examples you’ll be able to see the differences between the two types of hardware and connection methods and that will allow you to modify your sketch.

Or, simply order a NodeMCU or Wemos D1 Mini and run the sketch as it is. This approach will also save you the hassle of trying to get the Arduino Ethernet shield working reliably over an extended period of time.

Pete.

1 Like