Contains example code to connect the mbed LPC1768 or FRDM-K64F devices to the IBM Internet of Things Cloud service via ethernet.

Dependencies:   C12832 MQTT LM75B MMA7660

Dependents:   MFT_IoT_demo_USB400 IBM_RFID

Revision:
18:94da9de96d54
Parent:
17:74801ec6a672
Child:
20:b2a425418dcf
diff -r 74801ec6a672 -r 94da9de96d54 main.cpp
--- a/main.cpp	Wed Aug 12 16:16:47 2015 +0000
+++ b/main.cpp	Wed Aug 12 20:50:56 2015 +0000
@@ -32,7 +32,7 @@
 #include "rtos.h"
 
 // Update this to the next number *before* a commit
-#define __APP_SW_REVISION__ "17"
+#define __APP_SW_REVISION__ "18"
 
 // Configuration values needed to connect to IBM IoT Cloud
 #define ORG "quickstart"             // For a registered connection, replace with your org
@@ -157,87 +157,90 @@
 
 void printMenu(int menuItem) 
 {
-    lcd.cls();
-    lcd.locate(0,0);
+    static char last_line1[30] = "", last_line2[30] = "";
+    char line1[30] = "", line2[30] = "";
+        
     switch (menuItem)
     {
         case 0:
-            lcd.printf("IBM IoT Cloud");
-            lcd.locate(0,16);
-            lcd.printf("Scroll with joystick");
+            sprintf(line1, "IBM IoT Cloud");
+            sprintf(line2, "Scroll with joystick");
             break;
         case 1:
-            lcd.printf("Go to:");
-            lcd.locate(0,16);
-            lcd.printf("http://ibm.biz/iotqstart");
+            sprintf(line1, "Go to:");
+            sprintf(line2, "http://ibm.biz/iotqstart");
             break;
         case 2:
-            lcd.printf("Device Identity:");
-            lcd.locate(0,16);
-            lcd.printf("%s", id);
+            sprintf(line1, "Device Identity:");
+            sprintf(line2, "%s", id);
             break;
         case 3:
-            lcd.printf("MQTT Status:");
-            lcd.locate(0,16);
+            sprintf(line1, "MQTT Status:");
             if (mqttConnecting)
-                lcd.printf("Connecting... %d/5", retryAttempt);
+                sprintf(line2, "Connecting... %d/5", retryAttempt);
             else
             {
                 if (connected)
-                    lcd.printf("Connected");
+                    sprintf(line2, "Connected");
                 else
                 {
                     switch (connack_rc)
                     {
                         case MQTT_CLIENTID_REJECTED:
-                            lcd.printf("Clientid rejected");
+                            sprintf(line2, "Clientid rejected");
                             break;
                         case MQTT_BAD_USERNAME_OR_PASSWORD:
-                            lcd.printf("Invalid username or password");
+                            sprintf(line2, "Invalid username or password");
                             break;
                         case MQTT_NOT_AUTHORIZED:
-                            lcd.printf("Not authorized");
+                            sprintf(line2, "Not authorized");
                             break;
                         default:
-                            lcd.printf("Disconnected");
+                            sprintf(line2, "Disconnected");
                     }
                 }
             }
             break;
         case 4:
-            lcd.printf("Ethernet State:");
-            lcd.locate(0,16);
-            lcd.printf(ethernetInitialising ? "Initialising..." : "Initialised");
+            sprintf(line1, "Ethernet State:");
+            sprintf(line2, ethernetInitialising ? "Initializing..." : "Initialized");
             break;
         case 5:
-            lcd.printf("Socket State:");
-            lcd.locate(0,16);
+            sprintf(line1, "Socket State:");
             if (netConnecting)
-                lcd.printf("Connecting... %d/5", retryAttempt);
+                sprintf(line2, "Connecting... %d/5", retryAttempt);
             else
-                lcd.printf(netConnected ? "Connected" : "Disconnected");
+                sprintf(line2, netConnected ? "Connected" : "Disconnected");
             break;
         case 6:
-            lcd.printf("IP Address:");
-            lcd.locate(0,16);
-            lcd.printf("%s", ip_addr);
+            sprintf(line1, "IP Address:");
+            sprintf(line2, "%s", ip_addr);
             break;
         case 7:
-            lcd.printf("Gateway:");
-            lcd.locate(0,16);
-            lcd.printf("%s", gateway_addr);
+            sprintf(line1, "Gateway:");
+            sprintf(line2, "%s", gateway_addr);
             break;
         case 8:
-            lcd.printf("App version:");
-            lcd.locate(0,16);
-            lcd.printf("%s", __APP_SW_REVISION__);
+            sprintf(line1, "App version:");
+            sprintf(line2, "%s", __APP_SW_REVISION__);
             break;
         case 9:
-            lcd.printf("Current Timeout:");
-            lcd.locate(0,16);
-            lcd.printf("%d ms", connectTimeout);
+            sprintf(line1, "Current Timeout:");
+            sprintf(line2, "%d ms", connectTimeout);
             break;
     }
+    
+    if (strcmp(line1, last_line1) != 0 || strcmp(line2, last_line2) != 0)
+    {
+        lcd.cls(); 
+        lcd.locate(0, 0);
+        lcd.printf(line1);
+        strncpy(last_line1, line1, sizeof(last_line1));
+
+        lcd.locate(0,16);
+        lcd.printf(line2);
+        strncpy(last_line2, line2, sizeof(last_line2));
+    }
 }
 
 
@@ -321,7 +324,7 @@
     int rc = ipstack->connect(hostname, IBM_IOT_PORT, connectTimeout);
     if (rc != 0)
     {
-        WARN("IP Stack returned: %d\n", rc);    
+        WARN("IP Stack connect returned: %d\n", rc);    
         return rc;
     }
     netConnected = true;
@@ -477,7 +480,7 @@
     MQTTEthernet ipstack;
     ethernetInitialising = false;
     MQTT::Client<MQTTEthernet, Countdown, MQTT_MAX_PACKET_SIZE> client(ipstack);
-    LOG("Ethernet Initialised.\n"); 
+    LOG("Ethernet Initialized\n"); 
     
     if (quickstartMode)
         getMac(ipstack.getEth(), id, sizeof(id));