Local copy

Dependencies:   C12832_lcd ConfigFile EthernetInterface LM75B MMA7660 MQTTPacket mbed-rtos mbed

Fork of IBMIoTClientExampleForLPC1768 by Sam Danbury

Files at this revision

API Documentation at this revision

Comitter:
samdanbury
Date:
Tue Jun 24 10:29:07 2014 +0000
Parent:
2:25ddff75a8c7
Child:
4:e8de333c1cb4
Commit message:
fixed memory issue

Changed in this revision

src/QuickstartClient.cpp Show annotated file Show diff for this revision Revisions of this file
src/QuickstartClient.h Show annotated file Show diff for this revision Revisions of this file
--- a/src/QuickstartClient.cpp	Mon Jun 23 20:12:18 2014 +0000
+++ b/src/QuickstartClient.cpp	Tue Jun 24 10:29:07 2014 +0000
@@ -18,8 +18,8 @@
     macAddress = mac;
     
     //Generate topic string
-    string str = "iot-2/evt/status/fmt/json";
-    strcpy(topic, str.c_str());
+    memcpy(topic, "iot-2/evt/status/fmt/json", 25);
+    topic[25] = '\0';
     
     loadConfig();
     
@@ -30,38 +30,42 @@
     
     ConfigFile cfg;
     
-    char value[BUFSIZ];
+    char value[30];
+    char value1[30];
+    char value2[30];
+    char value3[30];
 
     if (cfg.read("/local/device.cfg")) {
         quickstartMode = false;
         
-        if (cfg.getValue("org", &value[0], sizeof(value))) {
+        if (cfg.getValue("org", value, sizeof(value))) {
             stringstream ss(value);
             ss >> org;
         } else {
             lcd.printf("No org defined in config\n");
         }
         
-        if (cfg.getValue("type", &value[0], sizeof(value))) {
-            stringstream ss(value);
+        if (cfg.getValue("type", value1, sizeof(value1))) {
+            stringstream ss(value1);
             ss >> type;
         } else {
             lcd.printf("No type defined in config\n");
         }
         
-        if (cfg.getValue("id", &value[0], sizeof(value))) {
-            stringstream ss(value);
+        if (cfg.getValue("id", value2, sizeof(value2))) {
+            stringstream ss(value2);
             ss >> id;
         } else {
             lcd.printf("No id defined in config\n");
         }
         
-        if (cfg.getValue("token", &value[0], sizeof(value))) {
-            stringstream ss(value);
+        if (cfg.getValue("token", value3, sizeof(value3))) {
+            stringstream ss(value3);
             ss >> token;
         } else {
             lcd.printf("No token defined in config\n");
         }
+        
     } else {
         org = "quickstart";
         type = "iotsample-mbed-lpc1768";
@@ -118,18 +122,14 @@
     
     //Construct client ID
     string str = string("d:") + org + ":" + type + ":" + id;
-    char clientId[ strlen(str.c_str()) + 1];
-    strcpy(clientId, str.c_str());
+    char clientId[str.size()];
+    memcpy(clientId, str.c_str(), str.size() + 1);
     
     //Set MQTT connect options
     data.clientID.cstring = clientId;
     data.keepAliveInterval = 20;
     data.cleansession = 1;
     data.MQTTVersion = 3;
-    if (!quickstartMode) {
-        data.password.cstring = token.c_str();
-          
-    }
     
     //Attempt MQTT connect
     len = MQTTSerialize_connect(buf, buflen, &data);
--- a/src/QuickstartClient.h	Mon Jun 23 20:12:18 2014 +0000
+++ b/src/QuickstartClient.h	Tue Jun 24 10:29:07 2014 +0000
@@ -34,7 +34,7 @@
         C12832_LCD lcd;
         TCPSocketConnection mysock;
         string macAddress;
-        char topic[25];
+        char topic[30];
         bool quickstartMode;
         
         string org;