GDP group 24 node core

Dependencies:   EthernetInterface SDFileSystem mbed-rtos mbed snail MbedJSONValue

Revision:
23:b57a47c7862a
Parent:
21:a32666afce7a
Child:
25:fe273397ebb2
diff -r 835a6c6dcfbb -r b57a47c7862a main.cpp
--- a/main.cpp	Tue Jan 13 23:53:24 2015 +0000
+++ b/main.cpp	Tue Jan 27 22:20:46 2015 +0000
@@ -12,7 +12,7 @@
 time_t pollInterval = 30;
 
 
-bool isBasenode = true;
+bool isBasenode = false;
 string fieldID = "testfield";
 
 http h = http();
@@ -88,17 +88,14 @@
     pc.printf("[MAIN] Got sensor data...\r\n");
     snail::sensordata& d = static_cast<snail::sensordata&>(message);
     
-    int value = 0;
-    value += d.payload[0];
-    value = value << 8;
-    value += d.payload[1];
-    
     char sensorID[3];
     sprintf(sensorID, "%i", d.i2cAddress);
     
     MbedJSONValue j;
     j["timestamp"] = (int)time(NULL);
-    j["value"] = value;
+    
+    for (int i = 0; i < d.payloadSize; i++)
+        j["value"][i] = d.payload[i];
     
     #ifdef DEBUG
         pc.printf( ("[MAIN] POSTing sensor reading: " + j.serialize() + "\r\n").c_str() );
@@ -164,7 +161,7 @@
     while (cs != sif->sensors.end() && i < 32)
     {
         localSensors[i].type = cs->second.type;
-        localSensors[i].id = cs->first;
+        localSensors[i].id = cs->second.type;
         i++;
         cs++;
     }
@@ -226,7 +223,7 @@
         pc.printf("\r\n");
         pc.printf("\r\n");
     #endif
-    //sdcard sd = sdcard();
+    sdcard sd = sdcard();
     
     //TODO: read basenode pin
     #ifdef DEBUG
@@ -310,17 +307,17 @@
                     pc.printf("\r\n");
                 #endif
                 
-                string readings_str(data.readings.begin(), data.readings.end());
-                char readings[sizeof(snail::sensordata().payload)];
-                memcpy(readings, readings_str.c_str(), sizeof(readings));
+                int readings[16];
+                for (int i = 0; i < data.readings.size(); i++)
+                    readings[i] = data.readings[i];
                 
                 //TODO: Get real I2C address
-                snail::sensordata message(baseNodeAddress, data.type, data.type, time(NULL), readings, readings_str.size());
+                snail::sensordata message(baseNodeAddress, data.type, data.type, time(NULL), readings, data.readings.size());
                 
                 messageQueue.push(message);
                 
                 //log
-                //sd.write(static_cast<long int>(time(NULL)), data);
+                sd.write(static_cast<long int>(time(NULL)), data);
             }
         }
     }