GDP group 24 node core

Dependencies:   EthernetInterface SDFileSystem mbed-rtos mbed snail MbedJSONValue

Files at this revision

API Documentation at this revision

Comitter:
Trumple
Date:
Wed Jan 28 21:11:59 2015 +0000
Parent:
28:9c8d472c44b7
Child:
30:631bd0aa4dc2
Commit message:
Tidy code, add address macros

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Wed Jan 28 20:52:44 2015 +0000
+++ b/main.cpp	Wed Jan 28 21:11:59 2015 +0000
@@ -7,6 +7,10 @@
 #include <map>
 
 #define DEBUG
+#define API_IP "178.62.84.55"
+#define API_PORT 8888
+#define API_TIME_IP "81.4.121.72"
+#define API_TIME_PORT 80
 
 time_t lastPollTime = 0;
 time_t pollInterval = 30;
@@ -68,17 +72,17 @@
         {
             char sensorIDBuffer[3];
             sprintf(sensorIDBuffer, "%i", request.sensors[i].id);
-            char fBuffer[3];
-            sprintf(fBuffer, "%i", request.sensors[i].type);
+            char typeBuffer[3];
+            sprintf(typeBuffer, "%i", request.sensors[i].type);
             j["sensors"][i]["sensorID"] = string(sensorIDBuffer);
-            j["sensors"][i]["sensortype"] = string(fBuffer);
+            j["sensors"][i]["sensortype"] = string(typeBuffer);
         }
         
         string address = addressToString(request.source);
         #ifdef DEBUG
             pc.printf( ("[MAIN] POSTing startup information: " + j.serialize() + "\r\n").c_str() );
         #endif
-        h.post("178.62.84.55", 8888, "/field/" + string(localAddress) + "/" + address + "/startup/", j.serialize()).c_str();
+        h.post(API_IP, API_PORT, "/field/" + string(localAddress) + "/" + address + "/startup/", j.serialize()).c_str();
         
         snail::joinnetworkreply reply(request.source, time(NULL), localAddress);
         xbee.send(reply, sizeof(reply));
@@ -103,7 +107,7 @@
         pc.printf( ("[MAIN] POSTing sensor reading: " + j.serialize() + "\r\n").c_str() );
     #endif
     
-    h.post("178.62.84.55", 8888, "/field/" + string(localAddress) + "/" + addressToString(d.source) + "/" + sensorID + "/", j.serialize()).c_str();
+    h.post(API_IP, API_PORT, "/field/" + string(localAddress) + "/" + addressToString(d.source) + "/" + sensorID + "/", j.serialize()).c_str();
 }
 
 void handleNetworkParametersTimeout()
@@ -252,7 +256,7 @@
     
     if (isBasenode)
     {   
-        string timestampStr = h.get("time.bitnode.co.uk", 80, "/");
+        string timestampStr = h.get(API_TIME_IP, API_TIME_PORT, "/");
         time_t timestamp = atoi(timestampStr.c_str());
         
         set_time(timestamp);