...

Dependencies:   C12832 EthernetInterface MbedJSONValue WebSocketClient mbed-rtos mbed

Fork of microServiceBus_node by Mikael Hakansson

Revision:
1:b182b5dc15e7
Parent:
0:e542df4c4901
Child:
2:fe293fbcf3e3
--- a/main.cpp	Thu Aug 25 13:53:00 2016 +0000
+++ b/main.cpp	Sun Apr 23 12:15:25 2017 +0000
@@ -4,13 +4,11 @@
 #include "MbedJSONValue.h"
 #include "C12832.h"
 #include <string>
-#include "bootloader.h"
-
 
 C12832 lcd(D11, D13, D12, D7, D10);
 Serial pc1(USBTX, USBRX); // tx, rx
 
-string _organizationId = "74ff8902-2057-499a-bca8-36a699c2458f";
+string _organizationId = "5f5967d9-4020-40d9-86e7-e813664d0397"; // AXIANS
 
 int main() {
     
@@ -20,9 +18,9 @@
     eth.init(); //Use DHCP
     eth.connect();
     pc1.printf("IP Address is %s\r\n", eth.getIPAddress());
+    pc1.printf("MAC Address is %s\r\n", eth.getMACAddress());
  
-    //Websocket ws("ws://microservicebus-northeurope-stage.azurewebsites.net/Services/WsHandler.ashx?id=42");
-    Websocket ws("ws://192.168.1.64/Services/WsHandler.ashx?id=42");
+    Websocket ws("ws://microservicebus-northeurope-stage.azurewebsites.net/Services/WsHandler.ashx?id=42");
     bool connected;
     connected = ws.connect();
     
@@ -37,15 +35,18 @@
         exit(0); 
     }
     
-    //while (!ws.connect());
     char str[10000];
     
+    // Create signIn message
     MbedJSONValue signInJson;
-    signInJson["nodeName"] = eth.getMACAddress();
+    signInJson["macAddress"] = eth.getMACAddress();
+    signInJson["ip"] = eth.getIPAddress();
+    /*
     signInJson["organizationId"] = _organizationId;
     signInJson["machineName"] = eth.getMACAddress();
-    signInJson["ip"] = eth.getIPAddress();
+    */
     
+    // Submit signIn message
     char buf[256];
     snprintf(buf, sizeof buf, "signIn::%s", signInJson.serialize());
     ws.send(buf);
@@ -59,22 +60,42 @@
             
             string msg(str);
             
-            if (msg.find("broadcast::") == 0)
-            {
-                pc1.printf("Broadcast: ");
-                pc1.printf(str);
-                pc1.printf("\r\n");
-            }
-            else if (msg.find("signInMessage::") == 0)
+            if (msg.find("signInMessage::") == 0)
             {
                 pc1.printf("Sign In successfully\r\n");
-            }
-            else if (msg.find("reboot::") == 0)
-            {
-                pc1.printf("Disconnecting...\r\n");
-                eth.disconnect();
-                pc1.printf("\r\nCalling bootloader...\r\n");
-                write_flash();
+                //pc1.printf("response: %s\r\n", str);
+                
+                msg.replace(0,15,"");
+                MbedJSONValue pingRequestJson;
+                const  char * json = msg.c_str();
+                parse(pingRequestJson, json);
+                std::string organizationId;
+                std::string hubProvider;
+                std::string messagingToken;
+                std::string state;
+                std::string protocol;
+                std::string binaryUri;
+                std::string binaryVersion;
+                bool debug;
+                
+                organizationId = pingRequestJson["organizationId"].get<std::string>();
+                hubProvider = pingRequestJson["hubProvider"].get<std::string>();
+                messagingToken = pingRequestJson["messagingToken"].get<std::string>();
+                state = pingRequestJson["state"].get<std::string>();
+                protocol = pingRequestJson["protocol"].get<std::string>();
+                binaryUri = pingRequestJson["binaryUri"].get<std::string>();
+                binaryVersion = pingRequestJson["binaryVersion"].get<std::string>();
+                debug = pingRequestJson["debug"].get<bool>();
+                
+                pc1.printf("organizationId: %s\r\n", organizationId);
+                pc1.printf("hubProvider: %s\r\n", hubProvider);
+                pc1.printf("messagingToken: %s\r\n", messagingToken);
+                pc1.printf("state: %s\r\n", state);
+                pc1.printf("protocol: %s\r\n", protocol);
+                pc1.printf("binaryUri: %s\r\n", binaryUri);
+                pc1.printf("binaryVersion: %s\r\n", binaryVersion);
+                pc1.printf("debug: %s\r\n", debug);
+                
             }
             else if (msg.find("errorMessage::") == 0)
             {
@@ -82,28 +103,6 @@
                 pc1.printf(str);
                 pc1.printf("\r\n");
             }
-            else if (msg.find("ping::") == 0)
-            {
-                msg.replace(0,6,"");
-                pc1.printf("ping from:");
-                pc1.printf(msg.c_str());
-                pc1.printf("\r\n");
-                
-                MbedJSONValue pingRequestJson;
-                const  char * json = msg.c_str();
-                parse(pingRequestJson, json);
-                std::string connectionid;
-                connectionid = pingRequestJson["connectionid"].get<std::string>();
-                
-                MbedJSONValue pingResponseJson;
-                pingResponseJson["nodeName"] = eth.getMACAddress();
-                pingResponseJson["organizationId"] = _organizationId;
-                pingResponseJson["connectionid"] = connectionid;
-                pingResponseJson["status"] = "online";
-                
-                snprintf(buf, sizeof buf, "pingResponse::%s", pingResponseJson.serialize());
-                ws.send(buf);
-            }
         }
         
     }