Had to fork with a different name, because of some incompatibility issues.

Dependencies:   MQTT

Revision:
19:85e9bc1a3a6a
Parent:
18:ce12e2072cbb
Child:
23:1523bdaba8c8
--- a/DeviceClient.cpp	Sun Oct 20 23:21:52 2019 -0400
+++ b/DeviceClient.cpp	Sat Nov 30 20:26:45 2019 -0400
@@ -16,9 +16,13 @@
  *    Lokesh K Haralakatta - Port to mbed OS 5 support
  *    Lokesh K Haralakatta - Added SSL/TLS Support
  *******************************************************************************/
+
+#include "mbed.h"
 #include "MQTTClient.h"
 #include "DeviceClient.h"
 
+//Addedd the use of mutexes and semaphores
+
 // need a wrapper since K64F and LPC1768 wont have the same name for mii read methods
 #if defined(TARGET_UBLOX_C027) || defined(TARGET_K64F) || defined(TARGET_DISCO_F746NG)
 
@@ -55,7 +59,7 @@
 {
     LOG("Constructor#2 called:: org=%s, type=%s, id=%s\r\n", (org==NULL)?"NULL":org,
                     (deviceType==NULL)?"NULL":deviceType, (deviceId==NULL)?"NULL":deviceId);
-
+    
     if(strcmp(this->org, QUICKSTART) != 0) {
         WARN("Registered flow must provide valid token\r\n");
     }
@@ -71,7 +75,7 @@
     // Don't print token for security reasons
     LOG("Constructor#3 called:: org=%s, type=%s, id=%s\r\n", (org==NULL)?"NULL":org,
                     (deviceType==NULL)?"NULL":deviceType, (deviceId==NULL)?"NULL":deviceId);
-
+    
     mqttNetwork = new MQTTNetwork();
     mqttClient = new MQTT::Client<MQTTNetwork, Countdown>(*mqttNetwork);
 }
@@ -149,12 +153,12 @@
        if(rc == true)
        {
           connected = true;
-          LOG("Device Client Connected to %s:%d\r\n",hostname,port);
+          LOG("Device Client Connected to %s:%d\r\n",hostname,port);          
         }
     }
     else
        LOG("No IP Assigned to Network Interface...\r\n");
-
+       
     return rc;
 }
 
@@ -167,6 +171,7 @@
 bool DeviceClient::reConnect()
 {
     LOG("DeviceClient::reConnect() entry and connected = %s\r\n",(connected == true)?"true":"false");
+    
     if(connected == true)
     {
         disconnect();
@@ -238,7 +243,7 @@
     LOG("Server Hostname: %s\r\n", hostname);
     LOG("Server Port: %d\r\n", port);
     LOG("Client ID: %s\r\n", clientId);
-    LOG("=====================================\r\n");
+    LOG("=====================================\r\n");    
 }
 
 int DeviceClient::getConnTimeout(int attemptNumber)
@@ -287,6 +292,7 @@
     message.payloadlen = strlen(data);
 
     LOG("Publishing %s\r\n", data);
+    
     int rc = mqttClient->publish(topic, message);
     return rc == 0;
 }
@@ -326,7 +332,7 @@
     sprintf(topic, "%.*s", md.topicName.lenstring.len, md.topicName.lenstring.data);
 
     LOG("Message arrived on topic %s: Length: %ul. Payload: %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;
     int len = strstr(topic, "/fmt/") - start;