mbed based IoT Gateway More details http://blog.thiseldo.co.uk/wp-filez/IoTGateway.pdf

Dependencies:   NetServices FatFileSystem csv_parser mbed MQTTClient RF12B DNSResolver SDFileSystem

Revision:
5:0dbc27a7af55
Parent:
4:d460406ac780
--- a/Routing/IoTRouting.cpp	Tue May 01 21:43:40 2012 +0000
+++ b/Routing/IoTRouting.cpp	Wed May 09 20:29:30 2012 +0000
@@ -257,17 +257,17 @@
 }
 
 PayloadRouting* IoTRouting::getRouting( short nodeId, short sensorId ) {
-    printf("Getting routing info for node %d, sensor %d - ", nodeId, sensorId);
+//    printf("Getting routing info for node %d, sensor %d - ", nodeId, sensorId);
     for ( short i=0; i<(short)_routing.size(); i++ ) {
 
         PayloadRouting *pr = (PayloadRouting*)_routing.at(i);
 //        printf("Node %d, sensor %d\n", pr->nodeId, pr->sensorId);
         if ( pr->nodeId == nodeId &&  pr->sensorId == sensorId ) {
-            printf("Found!\n");
+//            printf("Found!\n");
             return pr;
         }
     }
-    printf("NOT found\n");
+//    printf("NOT found\n");
     // Add to routing list
     addRoutingToList( nodeId, sensorId, 1.0, OUTPUT_UNKNOWN,"","","","");
     // Save Routing list
@@ -278,16 +278,16 @@
 
 
 short IoTRouting::getPayloadType(  uint8_t *data, short dataLen ) {
-    printf("Getting payload type, size is %d -  ",(int)_nodeDefList.size() );
+//    printf("Getting payload type, size is %d -  ",(int)_nodeDefList.size() );
     for (short i=0; i<(int)_nodeDefList.size(); i++) {
 //    printf("%d, %ld, ",i, (int)_nodeDefList.at(i));
         IoTNodeDef *nd = (IoTNodeDef*)_nodeDefList.at(i);
         if ( nd->groupId == data[0] && nd->nodeId == (data[1] & 0x1f) && nd->length == data[2] ) {
-            printf("Found %d\n", nd->type);
+//            printf("Found %d\n", nd->type);
             return nd->type;
         }
     }
-    printf("NOT found\n");
+//    printf("NOT found\n");
     // Add to node list
     addNodeToList(data[0], data[1] & 0x1f, data[2], PAYLOAD_TYPE_UNKNOWN );
     // Save NodeList
@@ -295,6 +295,7 @@
     return PAYLOAD_TYPE_UNKNOWN;
 }
 
+#define TMPBUF_SIZE 20
 
 bool IoTRouting::routePayload( uint8_t *data, short dataLen ) {
     bool routed = false;
@@ -303,7 +304,7 @@
     PayloadV1 pv1;
     PayloadV2 pv2;
     PayloadRouting *pr = NULL;
-    char tmpBuf[42];
+    char tmpBuf[TMPBUF_SIZE];
 
     pachubeOutput->init();      // Just to be sure
     printf("routePayload: ");
@@ -327,8 +328,8 @@
                 if ( pr != NULL ) {
                     if ( pr->output != NULL ) {
 //                        printf("Pachube %d, %d, %f, %s, %s\n",pr->nodeId, pr->sensorId, pr->factor, pr->param1, pr->param2);
-                        snprintf(tmpBuf, DATABUF_SIZE, "%.3f", (float)(psimp.reading(n) * pr->factor));
-                        printf("Add to output %s, %s, %s\n", pr->param1, pr->param2, tmpBuf );
+                        snprintf(tmpBuf, TMPBUF_SIZE, "%.3f", (float)(psimp.reading(n) * pr->factor));
+//                        printf("Add to output %s, %s, %s\n", pr->param1, pr->param2, tmpBuf );
                         pr->output->addReading( pr->param1, pr->param2,tmpBuf );
                     }
                 }
@@ -352,7 +353,7 @@
                     printf("LOW Battery detected\n");
                 }
                 if ( pr->output != NULL ) {
-                    snprintf(tmpBuf, DATABUF_SIZE, "%d", (int)( data[3] & STATUS_LOW_BATTERY ));
+                    snprintf(tmpBuf, TMPBUF_SIZE, "%d", (int)( data[3] & STATUS_LOW_BATTERY ));
                     pr->output->addReading( pr->param1, pr->param2, tmpBuf );
                     }
             }
@@ -363,7 +364,7 @@
                     tmpBuf[0] = '\0';
 //                    printf("Pachube %d, %d, %f, %s, %s\n",pr->nodeId, pr->sensorId, pr->factor, pr->param1, pr->param2);
                     if ( pr->output != NULL ) {
-                        snprintf(tmpBuf, DATABUF_SIZE, "%.3f", (float)(pv1.reading(n) * pr->factor));
+                        snprintf(tmpBuf, TMPBUF_SIZE, "%.3f", (float)(pv1.reading(n) * pr->factor));
                         pr->output->addReading( pr->param1, pr->param2, tmpBuf );
                     }
                     printf("%d: %d - %s\n", n, pv1.sensorId(n), tmpBuf );
@@ -387,7 +388,7 @@
                     printf("LOW Battery detected\n");
                 }
                 if ( pr->output != NULL ) {
-                    snprintf(tmpBuf, DATABUF_SIZE, "%d", (int)( data[3] & STATUS_LOW_BATTERY ));
+                    snprintf(tmpBuf, TMPBUF_SIZE, "%d", (int)( data[3] & STATUS_LOW_BATTERY ));
                     pr->output->addReading( pr->param1, pr->param2, tmpBuf );
                 }
                 // Need to update add reading to detect change in feed ID and send.
@@ -407,13 +408,13 @@
 
                         switch ( pv2.readingType( n ) ) {
                             case V2_DATATYPE_BYTE:
-                                snprintf(tmpBuf, DATABUF_SIZE, "%.3f", (float)(pv2.readingByte(n) * pr->factor));
+                                snprintf(tmpBuf, TMPBUF_SIZE, "%.3f", (float)(pv2.readingByte(n) * pr->factor));
                                 break;
                             case V2_DATATYPE_SHORT:
-                                snprintf(tmpBuf, DATABUF_SIZE, "%.3f", (float)(pv2.readingShort(n) * pr->factor));
+                                snprintf(tmpBuf, TMPBUF_SIZE, "%.3f", (float)(pv2.readingShort(n) * pr->factor));
                                 break;
                             case V2_DATATYPE_LONG:
-                                snprintf(tmpBuf, DATABUF_SIZE, "%.3f", (float)(pv2.readingLong(n) * pr->factor));
+                                snprintf(tmpBuf, TMPBUF_SIZE, "%.3f", (float)(pv2.readingLong(n) * pr->factor));
                                 break;
                             case V2_DATATYPE_STRING:
                                 break;