iot Watson compatible

Dependencies:   C12832 LM75B MMA7660 MQTT

Fork of IBMIoTClientEthernetExample by IBM Watson IoT

Files at this revision

API Documentation at this revision

Comitter:
icraggs
Date:
Wed Nov 01 11:07:46 2017 +0000
Parent:
19:d91f7b4ef2a9
Commit message:
Update included libraries, support mbed OS 5.0

Changed in this revision

EthernetInterface.lib Show diff for this revision Revisions of this file
MQTT.lib 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
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show diff for this revision Revisions of this file
mbed.bld Show diff for this revision Revisions of this file
diff -r d91f7b4ef2a9 -r b2a425418dcf EthernetInterface.lib
--- a/EthernetInterface.lib	Mon May 23 13:48:48 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/mbed_official/code/EthernetInterface/#2fc406e2553f
diff -r d91f7b4ef2a9 -r b2a425418dcf MQTT.lib
--- a/MQTT.lib	Mon May 23 13:48:48 2016 +0000
+++ b/MQTT.lib	Wed Nov 01 11:07:46 2017 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/teams/mqtt/code/MQTT/#37f007d2a8ae
+http://mbed.org/teams/mqtt/code/MQTT/#b74b9ef26f33
diff -r d91f7b4ef2a9 -r b2a425418dcf main.cpp
--- a/main.cpp	Mon May 23 13:48:48 2016 +0000
+++ b/main.cpp	Wed Nov 01 11:07:46 2017 +0000
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2014, 2015 IBM Corp.
+ * Copyright (c) 2014, 2017 IBM Corp.
  *
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
@@ -32,7 +32,7 @@
 #include "rtos.h"
 
 // Update this to the next number *before* a commit
-#define __APP_SW_REVISION__ "18"
+#define __APP_SW_REVISION__ "19"
 
 // Configuration values needed to connect to IBM IoT Cloud
 #define ORG "quickstart"             // For a registered connection, replace with your org
@@ -76,9 +76,9 @@
 char* joystickPos = "CENTRE";
 int blink_interval = 0;
 
-char* ip_addr = "";
-char* gateway_addr = "";
-char* host_addr = "";
+const char* ip_addr = "";
+const char* gateway_addr = "n/a";
+const char* host_addr = "";
 int connectTimeout = 1000;
 
 // If we wanted to manually set the MAC address,
@@ -302,29 +302,29 @@
     char hostname[strlen(org) + strlen(iot_ibm) + 1];
     sprintf(hostname, "%s%s", org, iot_ibm);
     EthernetInterface& eth = ipstack->getEth();
-    ip_addr = eth.getIPAddress();
-    gateway_addr = eth.getGateway();
+    ip_addr = eth.get_ip_address();
+    //gateway_addr = EthernetInterface::getGateway();
     
     // Construct clientId - d:org:type:id
     char clientId[strlen(org) + strlen(type) + strlen(id) + 5];
     sprintf(clientId, "d:%s:%s:%s", org, type, id);
     
     // Network debug statements 
-    LOG("=====================================\n");
-    LOG("Connecting Ethernet.\n");
-    LOG("IP ADDRESS: %s\n", eth.getIPAddress());
-    LOG("MAC ADDRESS: %s\n", eth.getMACAddress());
-    LOG("Gateway: %s\n", eth.getGateway());
-    LOG("Network Mask: %s\n", eth.getNetworkMask());
-    LOG("Server Hostname: %s\n", hostname);
-    LOG("Client ID: %s\n", clientId);
-    LOG("=====================================\n");
+    LOG("=====================================\r\n");
+    LOG("Connecting Ethernet.\r\n");
+    LOG("IP ADDRESS: %s\r\n", ip_addr);
+    LOG("MAC ADDRESS: %s\r\n", eth.get_mac_address());
+    //LOG("Gateway: %s\r\n", eth.getGateway());
+    //LOG("Network Mask: %s\r\n", eth.getNetworkMask());
+    LOG("Server Hostname: %s\r\n", hostname);
+    LOG("Client ID: %s\r\n", clientId);
+    LOG("=====================================\r\n");
     
     netConnecting = true;
     int rc = ipstack->connect(hostname, IBM_IOT_PORT, connectTimeout);
     if (rc != 0)
     {
-        WARN("IP Stack connect returned: %d\n", rc);    
+        WARN("IP Stack connect returned: %d\r\n", rc);    
         return rc;
     }
     netConnected = true;
@@ -351,7 +351,7 @@
         displayMessage("Scroll with joystick");
     }
     else
-        WARN("MQTT connect returned %d\n", rc);
+        WARN("MQTT connect returned %d\r\n", rc);
     if (rc >= 0)
         connack_rc = rc;
     mqttConnecting = false;
@@ -374,7 +374,7 @@
     while (!linkStatus()) 
     {
         wait(1.0f);
-        WARN("Ethernet link not present. Check cable connection\n");
+        WARN("Ethernet link not present. Check cable connection\r\n");
     }
         
     while (connect(client, ipstack) != MQTT_CONNECTION_ACCEPTED) 
@@ -385,7 +385,7 @@
         Thread red_thread(flashing_red);
 
         int timeout = getConnTimeout(++retryAttempt);
-        WARN("Retry attempt number %d waiting %d\n", retryAttempt, timeout);
+        WARN("Retry attempt number %d waiting %d\r\n", retryAttempt, timeout);
         
         // if ipstack and client were on the heap we could deconstruct and goto a label where they are constructed
         //  or maybe just add the proper members to do this disconnect and call attemptConnect(...)
@@ -414,14 +414,14 @@
     message.payload = (void*)buf;
     message.payloadlen = strlen(buf);
     
-    LOG("Publishing %s\n", buf);
+    LOG("Publishing %s\r\n", buf);
     return client->publish(pubTopic, message);
 }
 
 
 char* getMac(EthernetInterface& eth, char* buf, int buflen)    // Obtain MAC address
 {   
-    strncpy(buf, eth.getMACAddress(), buflen);
+    strncpy(buf, eth.get_mac_address(), buflen);
 
     char* pos;                                                 // Remove colons from mac address
     while ((pos = strchr(buf, ':')) != NULL)
@@ -437,7 +437,7 @@
     
     sprintf(topic, "%.*s", md.topicName.lenstring.len, md.topicName.lenstring.data);
     
-    LOG("Message arrived on topic %s: %.*s\n",  topic, message.payloadlen, message.payload);
+    LOG("Message arrived on topic %s: %.*s\r\n",  topic, message.payloadlen, message.payload);
           
     // Command topic: iot-2/cmd/blink/fmt/json - cmd is the string between cmd/ and /fmt/
     char* start = strstr(topic, "/cmd/") + 5;
@@ -460,7 +460,7 @@
         }
     }
     else
-        WARN("Unsupported command: %.*s\n", len, start);
+        WARN("Unsupported command: %.*s\r\n", len, start);
 }
 
 
@@ -476,11 +476,11 @@
     Thread yellow_thread(flashing_yellow);
     Thread menu_thread(menu_loop);  
     
-    LOG("***** IBM IoT Client Ethernet Example *****\n");
+    LOG("***** IBM IoT Client Ethernet Example *****\r\n");
     MQTTEthernet ipstack;
     ethernetInitialising = false;
     MQTT::Client<MQTTEthernet, Countdown, MQTT_MAX_PACKET_SIZE> client(ipstack);
-    LOG("Ethernet Initialized\n"); 
+    LOG("Ethernet Initialized\r\n"); 
     
     if (quickstartMode)
         getMac(ipstack.getEth(), id, sizeof(id));
@@ -498,7 +498,7 @@
     {
         int rc = 0;
         if ((rc = client.subscribe("iot-2/cmd/+/fmt/json", MQTT::QOS1, messageArrived)) != 0)
-            WARN("rc from MQTT subscribe is %d\n", rc); 
+            WARN("rc from MQTT subscribe is %d\r\n", rc); 
     }
     
     blink_interval = 0;
@@ -507,7 +507,7 @@
     {
         if (++count == 100)
         {               // Publish a message every second
-            if (publish(&client, &ipstack) != 0) 
+            if (publish(&client, &ipstack) != 0)
                 attemptConnect(&client, &ipstack);   // if we have lost the connection
             count = 0;
         }
diff -r d91f7b4ef2a9 -r b2a425418dcf mbed-os.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Wed Nov 01 11:07:46 2017 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#c9e63f14085f5751ff5ead79a7c0382d50a813a2
diff -r d91f7b4ef2a9 -r b2a425418dcf mbed-rtos.lib
--- a/mbed-rtos.lib	Mon May 23 13:48:48 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/mbed_official/code/mbed-rtos/#a21475017ae2
diff -r d91f7b4ef2a9 -r b2a425418dcf mbed.bld
--- a/mbed.bld	Mon May 23 13:48:48 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/da0ca467f8b5
\ No newline at end of file