Official reference client implementation for Cumulocity SmartREST on u-blox C027.

Dependencies:   C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed

Fork of MbedSmartRestMain by Vincent Wochnik

Revision:
109:2ec12f10ebf4
Parent:
106:c61f0d62b625
Child:
122:68217ccb8cd1
--- a/operation/ReportThread.cpp	Wed May 13 13:03:20 2015 +0000
+++ b/operation/ReportThread.cpp	Wed May 13 13:54:17 2015 +0000
@@ -7,29 +7,36 @@
 {
     sock.setBlocking(3000);
     while (true) {
+        dict.clear();
         osEvent e = ipool.get();
         if (e.status == osEventMail) {
             Operation *op = (Operation*)e.value.p;
-            long id = op->identifier;
-            OperationState state = op->state;
+            dict.set(op->identifier, op->state);
             ipool.free(op);
-            int l = snprintf(buf2, sizeof(buf2), fmt2, id, strOperationState(state));
-            for (unsigned short i = 0; i < 10; ++i) {
+            while (!dict.full()) {
                 osEvent e = ipool.get(200);
                 if (e.status == osEventMail) {
                     op = (Operation*)e.value.p;
-                    id = op->identifier;
-                    OperationState state = op->state;
+                    dict.set(op->identifier, op->state);
                     ipool.free(op);
-                    l += snprintf(buf2+l, sizeof(buf2)-l, fmt2, id, strOperationState(state));
                 } else {
                     break;
                 }
             }
+            int l = 0;
+            for (unsigned short i = 0; i < dict.size(); ++i) {
+                const long id = dict[i].identifier;
+                const OperationState state = dict[i].state;
+                l += snprintf(buf2+l, sizeof(buf2)-l, fmt2, id, strOperationState(state));
+            }
             l = snprintf(buf, sizeof(buf), fmtSmartRest, uri, l, buf2);
-            l = sock.sendOnly(buf, l);
-            if (l < 0) {
-                aError("Report: <%ld, %s>\n", id, strOperationState(state));
+            for (unsigned i = 0; i < 3; ++i) {
+                int l2 = sock.sendOnly(buf, l);
+                if (l2 < 0) {
+                    aError("Report: op state\n");
+                    Thread::wait(3000);
+                } else
+                    break;
             }
         }
     }