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

Files at this revision

API Documentation at this revision

Comitter:
xinlei
Date:
Fri May 15 10:13:19 2015 +0000
Parent:
110:b7a403dbceb6
Child:
112:8ab3899c4e3d
Commit message:
bugfix for factory reset has no effect

Changed in this revision

C027_Support.lib Show annotated file Show diff for this revision Revisions of this file
config/ConfigSync.cpp Show annotated file Show diff for this revision Revisions of this file
config/ConfigSync.h Show annotated file Show diff for this revision Revisions of this file
io/Storage.cpp Show annotated file Show diff for this revision Revisions of this file
io/Storage.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/C027_Support.lib	Wed May 13 15:00:24 2015 +0000
+++ b/C027_Support.lib	Fri May 15 10:13:19 2015 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/users/xinlei/code/C027_Support/#246587b92b3b
+http://developer.mbed.org/users/xinlei/code/C027_Support/#b43dbe49091c
--- a/config/ConfigSync.cpp	Wed May 13 15:00:24 2015 +0000
+++ b/config/ConfigSync.cpp	Fri May 15 10:13:19 2015 +0000
@@ -8,7 +8,7 @@
 #define INTERVAL_KEY "interval"
 #define DEFAULT_INTERVAL "20"
 
-bool validateConfiguration(Dict& d)
+static bool validateConfiguration(const Dict& d)
 {
         const Dict::Item *p = d.get(INTERVAL_KEY);
         if (p) {
@@ -61,10 +61,12 @@
 void ConfigSync::loadConfiguration()
 {
         char buf[(MAX_KEY_LEN+MAX_VALUE_LEN+4)*MAX_ITEM_SIZE+1];
+        resetConfiguration();
         int l = loadConfigFile(buf, sizeof(buf));
-        if (l > 0) {
+        if (l > 0)
                 updateConfiguration(buf);
-        }
+        else
+                saveConfiguration();
 }
 
 void ConfigSync::saveConfiguration() const
@@ -72,8 +74,7 @@
         char s[(MAX_KEY_LEN+MAX_VALUE_LEN+3)*dict.size()+1];
         size_t l = dict.dump(s);
         if (l) {
-                if (!saveConfigFile(s, l)) {
+                if (!saveConfigFile(s, l))
                         aError("Save config.\n");
-                }
         }
 }
\ No newline at end of file
--- a/config/ConfigSync.h	Wed May 13 15:00:24 2015 +0000
+++ b/config/ConfigSync.h	Fri May 15 10:13:19 2015 +0000
@@ -10,7 +10,6 @@
 public:
         virtual ~ConfigSync() {}
         virtual bool init() {
-                resetConfiguration();
                 loadConfiguration();
                 return true;
         }
--- a/io/Storage.cpp	Wed May 13 15:00:24 2015 +0000
+++ b/io/Storage.cpp	Fri May 15 10:13:19 2015 +0000
@@ -10,17 +10,16 @@
 {
     char buffer[len*2+3];
     int res = pMdm->readFile(CREDENTIALS_FILE, buffer, sizeof(buffer));
-    if (res < 0) {
+    if (res <= 0) {
         return false;
     } else {
         buffer[res] = 0;
-        int l = 0;
-        sscanf(buffer, "%s\n%s\n%n", username, password, &l);
-        return res==l;
+        int l = sscanf(buffer, "%s\n%s\n", username, password);
+        return l==2;
     }
 }
 
-bool delCredential()
+bool resetCredential()
 {
     return pMdm->delFile(CREDENTIALS_FILE);
 }
@@ -29,7 +28,7 @@
 {
     char buffer[len*2+3];
     int res = snprintf(buffer, sizeof(buffer), "%s\n%s\n", username, password);
-    delCredential();
+    pMdm->delFile(CREDENTIALS_FILE);
     return pMdm->writeFile(CREDENTIALS_FILE, buffer, res)==res;
 }
 
@@ -41,13 +40,8 @@
     return res;
 }
 
-bool delConfigFile()
-{
-    return pMdm->delFile(CONFIGURATION_FILE);
-}
-
 bool saveConfigFile(char *cfg, size_t len)
 {
-    delConfigFile();
+    pMdm->delFile(CONFIGURATION_FILE);
     return pMdm->writeFile(CONFIGURATION_FILE, cfg, len)==len;
 }
--- a/io/Storage.h	Wed May 13 15:00:24 2015 +0000
+++ b/io/Storage.h	Fri May 15 10:13:19 2015 +0000
@@ -7,7 +7,7 @@
 bool loadCredential(char *username, char *password, size_t len);
 
 /** saves credentials to persistent memory */
-bool delCredential();
+bool resetCredential();
 
 /** removes credentials from persistent memory */
 bool saveCredential(char *username, char *password, size_t len);
@@ -18,6 +18,4 @@
 /** saves configuration to persistent memory */
 bool saveConfigFile(char *cfg, size_t len);
 
-/** removes configuration from persistent memory */
-bool delConfigFile();
 #endif
\ No newline at end of file
--- a/main.cpp	Wed May 13 15:00:24 2015 +0000
+++ b/main.cpp	Fri May 15 10:13:19 2015 +0000
@@ -87,8 +87,6 @@
     pMdm = &mdm;
     InterruptIn joystickUp(A2);
     InterruptIn joystickDown(A3);
-    joystickUp.rise(&enableDebug);
-    joystickDown.rise(&disableDebug);
 
 //    CyaSSL_Init();
 //    pCtx = CyaSSL_CTX_new(CyaTLSv1_2_client_method());
@@ -108,15 +106,18 @@
         shutdown();
         return 2;
     }
-
+    joystickUp.rise(&enableDebug);
+    joystickDown.rise(&disableDebug);
+    
     DigitalIn fireButton(D4);
     if (fireButton) {
-        if (delCredential()) {
+        LCDDisplay::inst().setLines("Factory resetting...");
+        Thread::wait(2000); // wait for Disk I/O to be ready
+        if (resetCredential()) {
             LCDDisplay::inst().setLines("Reset Success");
         } else {
             LCDDisplay::inst().setLines("Reset Failure");
         }
-        Thread::wait(2000);
         shutdown();
         return 0;
     }