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 20:40:15 2015 +0000
Parent:
26:172b585fbb10
Child:
28:9c8d472c44b7
Commit message:
Add check for presence of Ethernet connection to determine node type

Changed in this revision

http.cpp Show annotated file Show diff for this revision Revisions of this file
http.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/http.cpp	Wed Jan 28 20:22:48 2015 +0000
+++ b/http.cpp	Wed Jan 28 20:40:15 2015 +0000
@@ -17,6 +17,11 @@
     #endif
 }
 
+bool http::isEthernetConnected()
+{
+    return string(eth.getIPAddress()).size() > 0;
+}
+
 string http::get(string address, int port, string url, int replyTimeout)
 {
     #ifdef DEBUG
--- a/http.h	Wed Jan 28 20:22:48 2015 +0000
+++ b/http.h	Wed Jan 28 20:40:15 2015 +0000
@@ -10,6 +10,7 @@
         string get(string address, int port, string url, int replyTimeout = 20);
         string post(string address, int port, string url, string jsonPayload, int replyTimeout = 20);
         string parse(string httpReply);
+        bool isEthernetConnected();
         void connect();
     
     private:
--- a/main.cpp	Wed Jan 28 20:22:48 2015 +0000
+++ b/main.cpp	Wed Jan 28 20:40:15 2015 +0000
@@ -238,12 +238,14 @@
         pc.printf("\r\n");
     #endif
     sdcard sd = sdcard();
+    h.connect();
     
     //commissioning button
     commissioningInput.fall(commissioningFall);
     commissioningInput.rise(commissioningRise);
     
     //check if local node is basenode
+    isBasenode = h.isEthernetConnected();
     #ifdef DEBUG
         pc.printf("[MAIN] Basenode status: %i\r\n", isBasenode);
     #endif
@@ -251,9 +253,7 @@
     getLocalAddress();
     
     if (isBasenode)
-    {
-        h.connect();
-        
+    {   
         string timestampStr = h.get("time.bitnode.co.uk", 80, "/");
         time_t timestamp = atoi(timestampStr.c_str());