IoT Example

Dependencies:   C12832 LM75B MMA7660 MQTT mbed-rtos mbed

Fork of IBMIoTClientEthernetExample by IBM Watson IoT

Revision:
8:7bf351c1b125
Parent:
7:2fb7a98b559c
Child:
9:44c5e1716e64
--- a/main.cpp	Thu Sep 25 18:22:51 2014 +0000
+++ b/main.cpp	Mon Sep 29 11:43:52 2014 +0000
@@ -209,7 +209,7 @@
         data.password.cstring = auth_token;
     }
     
-    if ((rc = client->connect(&data)) == 0) 
+    if ((rc = client->connect(data)) == 0) 
     {       
         connected = true;
         green();    
@@ -248,7 +248,15 @@
 #endif
         int timeout = getConnTimeout(++retryAttempt);
         WARN("Retry attempt number %d waiting %d\n", retryAttempt, timeout);
-        wait(timeout);
+        
+        // if ipstack and client were on the heap we could deconstruct and goto a label where they are constructed
+        //  or maybe just add the proper members to do this disconnect and call attemptConnect(...)
+        
+        // this works - reset the system when the retry count gets to a threshold
+        if (retryAttempt == 5)
+            NVIC_SystemReset();
+        else
+            wait(timeout);
     }
 }
 
@@ -269,7 +277,7 @@
     message.payloadlen = strlen(buf);
     
     LOG("Publishing %s\n", buf);
-    return client->publish(pubTopic, &message);
+    return client->publish(pubTopic, message);
 }
 
 
@@ -380,12 +388,6 @@
     int count = 0;
     while (true)
     {
-        if (!linkStatus()) {
-            NVIC_SystemReset();
-            // if ipstack and client were on the heap we could deconstruct and goto a label where they are constructed
-            //  or maybe just add the proper members to do this disconnect and call attemptConnect(...)
-        }
-        
         if (++count == 100)
         {               // Publish a message every second
             if (publish(&client, &ipstack) != 0)