Sample code that showcases how to use IBMIoTF client library to connect the mbed LPC1768 or FRDM-K64F devices to the IBM Internet of Things Cloud service.

Dependencies:   C12832 IBMIoTF LM75B MMA7660

Revision:
1:e58533b6bc6b
Parent:
0:555ea43ec379
Child:
2:2fc985a92cda
--- a/src/Main.cpp	Fri Nov 06 07:39:04 2015 +0000
+++ b/src/Main.cpp	Fri Nov 06 15:16:46 2015 +0000
@@ -1,14 +1,18 @@
 /*******************************************************************************
-* Copyright (c) 2014 IBM Corporation and other Contributors.
-*
-* All rights reserved. This program and the accompanying materials
-* are made available under the terms of the Eclipse Public License v1.0
-* which accompanies this distribution, and is available at
-* http://www.eclipse.org/legal/epl-v10.html
-*
-* Contributors: Sathiskumar Palaniappan
-* IBM - Initial Contribution
-*******************************************************************************/
+ * Copyright (c) 2015 IBM Corp.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Eclipse Distribution License v1.0 which accompany this distribution.
+ *
+ * The Eclipse Public License is available at
+ *    http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ *   http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *    Sathisumar Palaniappan - initial implementation
+ *******************************************************************************/
 
 #include "stdio.h"
 #include "mbed.h"
@@ -57,28 +61,36 @@
 
     // Set IoT Foundation connection parameters
     char organization[11] = "quickstart";     // For a registered connection, replace with your org
-    char deviceType[9] = "SampleDT";        // For a registered connection, replace with your type
-    char deviceId[8] = "";                  // For a registered connection, replace with your id
-    char method[6] = "token";               // Not required to change as IBM IoTF expects only token for now
+    char deviceType[9] = "SampleDT";        // For a registered connection, replace with your device type
+    char deviceId[15] = "";                  // For a registered connection, replace with your device id
+    char method[6] = "token";               // Not required to change as IBM IoTF expects only "token" for now
     char token[9] = "password";             // For a registered connection, replace with your auth-token
     
     // Create DeviceClient
     IoTF::DeviceClient client(organization, deviceType, deviceId, method, token);
     
-    // Get the MAC address if we are in quickstart mode and device id is not specified
+    // Get the DeviceID(MAC Address) if we are in quickstart mode and device id is not specified
     if((strcmp(organization, QUICKSTART) == 0) && (strcmp("", deviceId) == 0)) {
         char tmpBuf[50];
-        client.getMac(tmpBuf, sizeof(tmpBuf));
-        lcd.printf("Got MAC: %s\n", tmpBuf);
+        client.getDeviceId(tmpBuf, sizeof(tmpBuf));
+        lcd.printf("DeviceID: %s\n", tmpBuf);
         wait(10.0);
     }
     lcd.locate(0,10);
     lcd.printf("Initialized & connecting..\n");
     
-    bool status = client.connect();
-    lcd.cls();
-    lcd.locate(0,0);
-    lcd.printf("connect status: %s\n", status?"true":"false");
+    bool status = false;
+    
+    // keep on retrying till the connection is successful
+    while(status == false) {
+        status = client.connect();
+        lcd.cls();
+        lcd.locate(0,0);
+        lcd.printf("connect status: %s\n", status?"true":"false");
+        if(status == false) {
+            lcd.printf("Retrying..\n");
+        }
+    }
     wait(1.0);
     client.setCommandCallback(processCommand);
       
@@ -138,6 +150,7 @@
     lcd.cls();
     lcd.locate(0,0);
     lcd.printf("blink interval = %d\n", blink_interval);
+    wait(1.0);
 }
 
 void joystickThread(void const *args) {