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:
rajathishere
Date:
Wed Jul 02 12:02:47 2014 +0000
Parent:
11:0fa63599f5a0
Child:
13:65e87bd958bd
Commit message:
Added auth-method support

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	Wed Jul 02 10:37:56 2014 +0000
+++ b/src/QuickstartClient.cpp	Wed Jul 02 12:02:47 2014 +0000
@@ -39,7 +39,7 @@
     char value1[30];
     char value2[30];
     char value3[30];
-    
+    char value4[30];
     if (cfg.read("/local/device.cfg")) {
         quickstartMode = false;
         
@@ -64,8 +64,15 @@
             lcd.printf("No id defined in config\n");
         }
         
-        if (cfg.getValue("token", value3, sizeof(value3))) {
+        if (cfg.getValue("auth-method", value3, sizeof(value3))) {
             stringstream ss(value3);
+            ss >> authMethod;
+        } else {
+            lcd.printf("No auth method defined in config\n");
+        }
+        
+        if (cfg.getValue("auth-token", value4, sizeof(value4))) {
+            stringstream ss(value4);
             ss >> token;
         } else {
             lcd.printf("No token defined in config\n");
@@ -137,10 +144,16 @@
     data.cleansession = 1;
     data.MQTTVersion = 3;
     if (!quickstartMode) {
-        data.username.cstring = clientId;
-        char* authToken= new char[token.size()];
-        memcpy(authToken, token.c_str(), token.size()+1);
-        data.password.cstring =  authToken;
+        if ( ! authMethod.compare("token") ) {
+            data.username.cstring = clientId;
+            char* authToken= new char[token.size()];
+            memcpy(authToken, token.c_str(), token.size()+1);
+            data.password.cstring =  authToken;
+        }
+        else {
+            lcd.printf("Exiting\n");
+            exit(-1);
+        }
     }
     
     //Attempt MQTT connect
--- a/src/QuickstartClient.h	Wed Jul 02 10:37:56 2014 +0000
+++ b/src/QuickstartClient.h	Wed Jul 02 12:02:47 2014 +0000
@@ -41,6 +41,7 @@
         string org;
         string type;
         string id;
+        string authMethod;
         string token;
                 
         QuickstartClient(string mac);