mbed Weather Platform firmware http://mbed.org/users/okini3939/notebook/mbed-weather-platform-firmware/

Dependencies:   ChaNFSSD EthernetNetIf I2CLEDDisp Agentbed ChaNFSUSB ILinterpreter mbed BMP085 WeatherMeters ConfigFile ChaNFS I2CLCD

Committer:
okini3939
Date:
Mon Jul 04 15:16:45 2011 +0000
Revision:
0:bdb53686c194
Child:
1:6c7141895545

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
okini3939 0:bdb53686c194 1 /**
okini3939 0:bdb53686c194 2 * Agentbed SNMP Server
okini3939 0:bdb53686c194 3 * Modified for mbed, 2011 Suga.
okini3939 0:bdb53686c194 4 *
okini3939 0:bdb53686c194 5 * Agentuino SNMP Agent Library Prototyping...
okini3939 0:bdb53686c194 6 * Copyright 2010 Eric C. Gionet <lavco_eg@hotmail.com>
okini3939 0:bdb53686c194 7 */
okini3939 0:bdb53686c194 8 #include "mbed.h"
okini3939 0:bdb53686c194 9 #include "EthernetNetIf.h"
okini3939 0:bdb53686c194 10 #include "weather.h"
okini3939 0:bdb53686c194 11 #ifdef USE_SNMP
okini3939 0:bdb53686c194 12 #include "Agentbed.h"
okini3939 0:bdb53686c194 13
okini3939 0:bdb53686c194 14 static AgentbedClass Agentbed;
okini3939 0:bdb53686c194 15
okini3939 0:bdb53686c194 16 // RFC1213-MIB OIDs
okini3939 0:bdb53686c194 17 // .iso (.1)
okini3939 0:bdb53686c194 18 // .iso.org (.1.3)
okini3939 0:bdb53686c194 19 // .iso.org.dod (.1.3.6)
okini3939 0:bdb53686c194 20 // .iso.org.dod.internet (.1.3.6.1)
okini3939 0:bdb53686c194 21 // .iso.org.dod.internet.mgmt (.1.3.6.1.2)
okini3939 0:bdb53686c194 22 // .iso.org.dod.internet.mgmt.mib-2 (.1.3.6.1.2.1)
okini3939 0:bdb53686c194 23 // .iso.org.dod.internet.mgmt.mib-2.system (.1.3.6.1.2.1.1)
okini3939 0:bdb53686c194 24 // .iso.org.dod.internet.mgmt.mib-2.system.sysDescr (.1.3.6.1.2.1.1.1)
okini3939 0:bdb53686c194 25 const char sysDescr[] = "1.3.6.1.2.1.1.1.0"; // read-only (DisplayString)
okini3939 0:bdb53686c194 26 // .iso.org.dod.internet.mgmt.mib-2.system.sysObjectID (.1.3.6.1.2.1.1.2)
okini3939 0:bdb53686c194 27 const char sysObjectID[] = "1.3.6.1.2.1.1.2.0"; // read-only (ObjectIdentifier)
okini3939 0:bdb53686c194 28 // .iso.org.dod.internet.mgmt.mib-2.system.sysUpTime (.1.3.6.1.2.1.1.3)
okini3939 0:bdb53686c194 29 const char sysUpTime[] = "1.3.6.1.2.1.1.3.0"; // read-only (TimeTicks)
okini3939 0:bdb53686c194 30 // .iso.org.dod.internet.mgmt.mib-2.system.sysContact (.1.3.6.1.2.1.1.4)
okini3939 0:bdb53686c194 31 const char sysContact[] = "1.3.6.1.2.1.1.4.0"; // read-write (DisplayString)
okini3939 0:bdb53686c194 32 // .iso.org.dod.internet.mgmt.mib-2.system.sysName (.1.3.6.1.2.1.1.5)
okini3939 0:bdb53686c194 33 const char sysName[] = "1.3.6.1.2.1.1.5.0"; // read-write (DisplayString)
okini3939 0:bdb53686c194 34 // .iso.org.dod.internet.mgmt.mib-2.system.sysLocation (.1.3.6.1.2.1.1.6)
okini3939 0:bdb53686c194 35 const char sysLocation[] = "1.3.6.1.2.1.1.6.0"; // read-write (DisplayString)
okini3939 0:bdb53686c194 36 // .iso.org.dod.internet.mgmt.mib-2.system.sysServices (.1.3.6.1.2.1.1.7)
okini3939 0:bdb53686c194 37 const char sysServices[] = "1.3.6.1.2.1.1.7.0"; // read-only (Integer)
okini3939 0:bdb53686c194 38 //
okini3939 0:bdb53686c194 39 // Arduino defined OIDs
okini3939 0:bdb53686c194 40 // .iso.org.dod.internet.private (.1.3.6.1.4)
okini3939 0:bdb53686c194 41 // .iso.org.dod.internet.private.enterprises (.1.3.6.1.4.1)
okini3939 0:bdb53686c194 42 // .iso.org.dod.internet.private.enterprises.arduino (.1.3.6.1.4.1.36582)
okini3939 0:bdb53686c194 43 const char enterprises[] = "1.3.6.1.4.1.36582."; // read-only (Integer)
okini3939 0:bdb53686c194 44 //
okini3939 0:bdb53686c194 45 //
okini3939 0:bdb53686c194 46 // RFC1213 local values
okini3939 0:bdb53686c194 47 static char locDescr[] = "mbed Weather Platform"; // read-only (static)
okini3939 0:bdb53686c194 48 static char locObjectID[] = "1.3.6.1.4.1.36582"; // read-only (static)
okini3939 0:bdb53686c194 49 #endif
okini3939 0:bdb53686c194 50 volatile uint32_t locUpTime = 0; // read-only (static)
okini3939 0:bdb53686c194 51 #ifdef USE_SNMP
okini3939 0:bdb53686c194 52 static char locContact[] = "<root@weather>"; // should be stored/read from EEPROM - read/write (not done for simplicity)
okini3939 0:bdb53686c194 53 static char locName[] = "weather.mbed"; // should be stored/read from EEPROM - read/write (not done for simplicity)
okini3939 0:bdb53686c194 54 static char locLocation[] = "weather"; // should be stored/read from EEPROM - read/write (not done for simplicity)
okini3939 0:bdb53686c194 55 static int32_t locServices = 7; // read-only (static)
okini3939 0:bdb53686c194 56
okini3939 0:bdb53686c194 57 static char oid[SNMP_MAX_OID_LEN];
okini3939 0:bdb53686c194 58 static SNMP_API_STAT_CODES api_status;
okini3939 0:bdb53686c194 59 static SNMP_ERR_CODES status;
okini3939 0:bdb53686c194 60
okini3939 0:bdb53686c194 61
okini3939 0:bdb53686c194 62 void pduReceived()
okini3939 0:bdb53686c194 63 {
okini3939 0:bdb53686c194 64 SNMP_PDU pdu;
okini3939 0:bdb53686c194 65 //
okini3939 0:bdb53686c194 66 LED_NET_ON;
okini3939 0:bdb53686c194 67 api_status = Agentbed.requestPdu(&pdu);
okini3939 0:bdb53686c194 68 //
okini3939 0:bdb53686c194 69 if ( pdu.type == SNMP_PDU_GET || pdu.type == SNMP_PDU_GET_NEXT || pdu.type == SNMP_PDU_SET
okini3939 0:bdb53686c194 70 && pdu.error == SNMP_ERR_NO_ERROR && api_status == SNMP_API_STAT_SUCCESS ) {
okini3939 0:bdb53686c194 71 //
okini3939 0:bdb53686c194 72 pdu.OID.toString(oid);
okini3939 0:bdb53686c194 73 //
okini3939 0:bdb53686c194 74 pdu.error = SNMP_ERR_READ_ONLY;
okini3939 0:bdb53686c194 75 //
okini3939 0:bdb53686c194 76 if ( strcmp(oid, sysDescr ) == 0 ) {
okini3939 0:bdb53686c194 77 // handle sysDescr (set/get) requests
okini3939 0:bdb53686c194 78 if ( pdu.type == SNMP_PDU_GET ) {
okini3939 0:bdb53686c194 79 // response packet from get-request - locDescr
okini3939 0:bdb53686c194 80 status = pdu.VALUE.encode(SNMP_SYNTAX_OCTETS, locDescr);
okini3939 0:bdb53686c194 81 pdu.error = status;
okini3939 0:bdb53686c194 82 }
okini3939 0:bdb53686c194 83 } else if ( strcmp(oid, sysObjectID ) == 0 ) {
okini3939 0:bdb53686c194 84 // handle sysName (set/get) requests
okini3939 0:bdb53686c194 85 if ( pdu.type == SNMP_PDU_GET ) {
okini3939 0:bdb53686c194 86 // response packet from get-request - locUpTime
okini3939 0:bdb53686c194 87 status = pdu.VALUE.encode(SNMP_SYNTAX_OCTETS, locObjectID);
okini3939 0:bdb53686c194 88 pdu.error = status;
okini3939 0:bdb53686c194 89 }
okini3939 0:bdb53686c194 90 } else if ( strcmp(oid, sysUpTime ) == 0 ) {
okini3939 0:bdb53686c194 91 // handle sysName (set/get) requests
okini3939 0:bdb53686c194 92 if ( pdu.type == SNMP_PDU_GET ) {
okini3939 0:bdb53686c194 93 // response packet from get-request - locUpTime
okini3939 0:bdb53686c194 94 status = pdu.VALUE.encode(SNMP_SYNTAX_TIME_TICKS, locUpTime);
okini3939 0:bdb53686c194 95 pdu.error = status;
okini3939 0:bdb53686c194 96 }
okini3939 0:bdb53686c194 97 } else if ( strcmp(oid, sysName ) == 0 ) {
okini3939 0:bdb53686c194 98 // handle sysName (set/get) requests
okini3939 0:bdb53686c194 99 if ( pdu.type == SNMP_PDU_GET ) {
okini3939 0:bdb53686c194 100 // response packet from get-request - locName
okini3939 0:bdb53686c194 101 status = pdu.VALUE.encode(SNMP_SYNTAX_OCTETS, locName);
okini3939 0:bdb53686c194 102 pdu.error = status;
okini3939 0:bdb53686c194 103 }
okini3939 0:bdb53686c194 104 } else if ( strcmp(oid, sysContact ) == 0 ) {
okini3939 0:bdb53686c194 105 // handle sysContact (set/get) requests
okini3939 0:bdb53686c194 106 if ( pdu.type == SNMP_PDU_GET ) {
okini3939 0:bdb53686c194 107 // response packet from get-request - locContact
okini3939 0:bdb53686c194 108 status = pdu.VALUE.encode(SNMP_SYNTAX_OCTETS, locContact);
okini3939 0:bdb53686c194 109 pdu.error = status;
okini3939 0:bdb53686c194 110 }
okini3939 0:bdb53686c194 111 } else if ( strcmp(oid, sysLocation ) == 0 ) {
okini3939 0:bdb53686c194 112 // handle sysLocation (set/get) requests
okini3939 0:bdb53686c194 113 if ( pdu.type == SNMP_PDU_GET ) {
okini3939 0:bdb53686c194 114 // response packet from get-request - locLocation
okini3939 0:bdb53686c194 115 status = pdu.VALUE.encode(SNMP_SYNTAX_OCTETS, locLocation);
okini3939 0:bdb53686c194 116 pdu.error = status;
okini3939 0:bdb53686c194 117 }
okini3939 0:bdb53686c194 118 } else if ( strcmp(oid, sysServices) == 0 ) {
okini3939 0:bdb53686c194 119 // handle sysServices (set/get) requests
okini3939 0:bdb53686c194 120 if ( pdu.type == SNMP_PDU_GET ) {
okini3939 0:bdb53686c194 121 // response packet from get-request - locServices
okini3939 0:bdb53686c194 122 status = pdu.VALUE.encode(SNMP_SYNTAX_INT, locServices);
okini3939 0:bdb53686c194 123 pdu.error = status;
okini3939 0:bdb53686c194 124 }
okini3939 0:bdb53686c194 125 } else if ( strncmp(oid, enterprises, strlen(enterprises)) == 0 ) {
okini3939 0:bdb53686c194 126 // handle enterprises (set/get) requests
okini3939 0:bdb53686c194 127 if ( pdu.type == SNMP_PDU_GET ) {
okini3939 0:bdb53686c194 128 // response packet from get-request - enterprises
okini3939 0:bdb53686c194 129 switch (oid[strlen(enterprises)]) {
okini3939 0:bdb53686c194 130 case '0':
okini3939 0:bdb53686c194 131 status = pdu.VALUE.encode(SNMP_SYNTAX_OPAQUE_FLOAT, sensor.pres);
okini3939 0:bdb53686c194 132 break;
okini3939 0:bdb53686c194 133 case '1':
okini3939 0:bdb53686c194 134 status = pdu.VALUE.encode(SNMP_SYNTAX_OPAQUE_FLOAT, sensor.temp);
okini3939 0:bdb53686c194 135 break;
okini3939 0:bdb53686c194 136 case '2':
okini3939 0:bdb53686c194 137 status = pdu.VALUE.encode(SNMP_SYNTAX_OPAQUE_FLOAT, sensor.humi);
okini3939 0:bdb53686c194 138 break;
okini3939 0:bdb53686c194 139 case '3':
okini3939 0:bdb53686c194 140 status = pdu.VALUE.encode(SNMP_SYNTAX_OPAQUE_FLOAT, sensor.anemo);
okini3939 0:bdb53686c194 141 break;
okini3939 0:bdb53686c194 142 case '4':
okini3939 0:bdb53686c194 143 status = pdu.VALUE.encode(SNMP_SYNTAX_OPAQUE_FLOAT, sensor.vane);
okini3939 0:bdb53686c194 144 break;
okini3939 0:bdb53686c194 145 case '5':
okini3939 0:bdb53686c194 146 status = pdu.VALUE.encode(SNMP_SYNTAX_OPAQUE_FLOAT, sensor.rain);
okini3939 0:bdb53686c194 147 break;
okini3939 0:bdb53686c194 148 case '6':
okini3939 0:bdb53686c194 149 status = pdu.VALUE.encode(SNMP_SYNTAX_OPAQUE_FLOAT, sensor.light);
okini3939 0:bdb53686c194 150 break;
okini3939 0:bdb53686c194 151 case '7':
okini3939 0:bdb53686c194 152 status = pdu.VALUE.encode(SNMP_SYNTAX_OPAQUE_FLOAT, sensor.uv);
okini3939 0:bdb53686c194 153 break;
okini3939 0:bdb53686c194 154 case '8':
okini3939 0:bdb53686c194 155 status = pdu.VALUE.encode(SNMP_SYNTAX_OPAQUE_FLOAT, sensor.moist);
okini3939 0:bdb53686c194 156 break;
okini3939 0:bdb53686c194 157 case '9':
okini3939 0:bdb53686c194 158 status = pdu.VALUE.encode(SNMP_SYNTAX_OPAQUE_FLOAT, sensor.temp2);
okini3939 0:bdb53686c194 159 break;
okini3939 0:bdb53686c194 160 }
okini3939 0:bdb53686c194 161 pdu.error = status;
okini3939 0:bdb53686c194 162 }
okini3939 0:bdb53686c194 163 } else {
okini3939 0:bdb53686c194 164 // oid does not exist
okini3939 0:bdb53686c194 165 //
okini3939 0:bdb53686c194 166 // response packet - object not found
okini3939 0:bdb53686c194 167 pdu.error = SNMP_ERR_NO_SUCH_NAME;
okini3939 0:bdb53686c194 168 }
okini3939 0:bdb53686c194 169 //
okini3939 0:bdb53686c194 170 pdu.type = SNMP_PDU_RESPONSE;
okini3939 0:bdb53686c194 171
okini3939 0:bdb53686c194 172 Agentbed.responsePdu(&pdu);
okini3939 0:bdb53686c194 173 }
okini3939 0:bdb53686c194 174 //
okini3939 0:bdb53686c194 175 Agentbed.freePdu(&pdu);
okini3939 0:bdb53686c194 176 //
okini3939 0:bdb53686c194 177 //Serial << "UDP Packet Received End.." << " RAM:" << freeMemory() << endl;
okini3939 0:bdb53686c194 178 }
okini3939 0:bdb53686c194 179 #endif
okini3939 0:bdb53686c194 180
okini3939 0:bdb53686c194 181 int snmp_init (char *commname) {
okini3939 0:bdb53686c194 182 #ifdef USE_SNMP
okini3939 0:bdb53686c194 183 Agentbed.begin(commname, "None", SNMP_DEFAULT_PORT, eth);
okini3939 0:bdb53686c194 184 Agentbed.onPduReceive(pduReceived);
okini3939 0:bdb53686c194 185 #endif
okini3939 0:bdb53686c194 186 return 0;
okini3939 0:bdb53686c194 187 }
okini3939 0:bdb53686c194 188