doc_fbi
Published © GPL3+

SNMP Environmental Monitor

A server room temperature meter.

BeginnerWork in progress14,430
SNMP Environmental Monitor

Things used in this project

Hardware components

Arduino Ethernet Shield 2
Arduino Ethernet Shield 2
×1
Temperature Sensor
Temperature Sensor
×4
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1
Jumper wires (generic)
Jumper wires (generic)
×6
Arduino UNO
Arduino UNO
×1

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

v2

Code

v3

C#
#include <Streaming.h>        
#include <Ethernet.h>          
#include <SPI.h>
#include <MemoryFree.h>
#include <Agentuino.h> 

 int raw2 = 0;
 int raw3 = 0;
 int raw4 = 0;
 int raw5 = 0;
 float temp2 = 0;
 float temp3 = 0;
 float temp4 = 0;
 float temp5 = 0;

const char  reg= "C";                                        //C=Temperature in Centigrade, F=Temperature in Farenheight
static byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };  //Mac Address for Arduino Ethernet Shield
static byte ip[] = { 192, 168, 111, 33 };                    //IP Address for Arduino Ethernet Shield
static byte gateway[] = { 192, 168, 111, 1 };
static byte subnet[] = { 255, 255, 255, 0 };

const int a2 = A2;                                     
const int a3 = A3;   
const int a4 = A4;   
const int a5 = A5; 


int term2=0;                                                 
int term3=0;                                                 
int term4=0;                                                 
int term5=0;                                                 

 


const char sysDescr[] PROGMEM      = "1.3.6.1.2.1.1.1.0";  // System Description
const char sysContact[] PROGMEM    = "1.3.6.1.2.1.1.4.0";  // System Contact
const char sysName[] PROGMEM       = "1.3.6.1.2.1.1.5.0";  // System Name
const char sysLocation[] PROGMEM   = "1.3.6.1.2.1.1.6.0";  // System Location
const char sysServices[] PROGMEM   = "1.3.6.1.2.1.1.7.0";  // System Services

  

//My Custom OID's


const char temperature2[]       PROGMEM     = "1.3.6.1.3.2016.5.0.2";     //Temperature in Celsius
const char temperature3[]       PROGMEM     = "1.3.6.1.3.2016.5.0.3";     //Temperature in Celsius
const char temperature4[]       PROGMEM     = "1.3.6.1.3.2016.5.0.4";     //Temperature in Celsius
const char temperature5[]       PROGMEM     = "1.3.6.1.3.2016.5.0.5";     //Temperature in Celsius
 

// RFC1213 local values

static char locDescr[]              = "SNMP Temperature monitoring";                 // read-only (static)
static char locContact[50]          = "radio-portal.ru";             
static char locName[20]             = "ServerRoom";                              
static char locLocation[20]         = "Planet Earth";                          
static int32_t locServices          = 2;                                             // read-only (static)

 
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;
  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, sysDescr ) == 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_OCTETS, locDescr);
        pdu.type = SNMP_PDU_RESPONSE;
        pdu.error = status;
      } 
    } 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;
      }
    } else if ( strcmp_P(oid, sysContact ) == 0 ) {
      if ( pdu.type == SNMP_PDU_SET ) {
        status = pdu.VALUE.decode(locContact, strlen(locContact)); 
        pdu.type = SNMP_PDU_RESPONSE;
        pdu.error = status;
      } else {
        status = pdu.VALUE.encode(SNMP_SYNTAX_OCTETS, locContact);
        pdu.type = SNMP_PDU_RESPONSE;
        pdu.error = status;
      }
    } else if ( strcmp_P(oid, sysLocation ) == 0 ) {
      if ( pdu.type == SNMP_PDU_SET ) {
        status = pdu.VALUE.decode(locLocation, strlen(locLocation)); 
        pdu.type = SNMP_PDU_RESPONSE;
        pdu.error = status;
      } else {
        status = pdu.VALUE.encode(SNMP_SYNTAX_OCTETS, locLocation);
        pdu.type = SNMP_PDU_RESPONSE;
        pdu.error = status;
      }
    } else if ( strcmp_P(oid, sysServices) == 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_INT, locServices);
        pdu.type = SNMP_PDU_RESPONSE;
        pdu.error = status;
      }

    }

    else if ( strcmp_P(oid, temperature2 ) == 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_INT, term2);
        pdu.type = SNMP_PDU_RESPONSE;
        pdu.error = status;
      }
    } 
    

  
        else if ( strcmp_P(oid, temperature3 ) == 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_INT, term3);
        pdu.type = SNMP_PDU_RESPONSE;
        pdu.error = status;
      }
    } 
    

        else if ( strcmp_P(oid, temperature4 ) == 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_INT, term4);
        pdu.type = SNMP_PDU_RESPONSE;
        pdu.error = status;
      }
    } 
    

            else if ( strcmp_P(oid, temperature5 ) == 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_INT, term5);
        pdu.type = SNMP_PDU_RESPONSE;
        pdu.error = status;
      }
    } 
    

    else {
      pdu.type = SNMP_PDU_RESPONSE;
      pdu.error = SNMP_ERR_NO_SUCH_NAME;
    }
    Agentuino.responsePdu(&pdu);
  }
   Agentuino.freePdu(&pdu);
}
 

void setup()
{
  Ethernet.begin(mac);                     //Initialize Ethernet Shield
  api_status = Agentuino.begin();              //Begin Snmp agent on Ethernet shield
  pinMode( A2, INPUT );
  pinMode( A3, INPUT );
  pinMode( A4, INPUT );
  pinMode( A5, INPUT );
  if ( api_status == SNMP_API_STAT_SUCCESS ) {
    Agentuino.onPduReceive(pduReceived);
    delay(10);
    return;
  }
  delay(10);
}


void loop()
{ 
 
Agentuino.listen();                                 

float kPinTemp2 = analogRead(a2);                    
float kPinTemp3 = analogRead(a3);  
float kPinTemp4 = analogRead(a4);  
float kPinTemp5 = analogRead(a5);  

float terme2=( kPinTemp2/1023.0 )*5.0*1000/10;       
float terme3=( kPinTemp3/1023.0 )*5.0*1000/10; 
float terme4=( kPinTemp4/1023.0 )*5.0*1000/10; 
float terme5=( kPinTemp5/1023.0 )*5.0*1000/10; 

if ( reg  == "F" ) {
float terme2=((terme2 ) * 9.0 / 5.0) + 32.0;      
float terme3=((terme3 ) * 9.0 / 5.0) + 32.0; 
float terme4=((terme4 ) * 9.0 / 5.0) + 32.0;  
float terme5=((terme5 ) * 9.0 / 5.0) + 32.0; 
}

 term2=(int)terme2;                                 
 term3=(int)terme3;
 term4=(int)terme4;
 term5=(int)terme5;
;                               
}

Credits

doc_fbi

doc_fbi

3 projects • 4 followers

Comments