An API for using MQTT over multiple transports

Dependencies:   FP MQTTPacket

Dependents:   IBMIoTClientEthernetExample_W5500 IBMIoTClientEthernetExample_W5200

Fork of MQTT by MQTT

Files at this revision

API Documentation at this revision

Comitter:
kaizen
Date:
Mon Sep 29 04:56:42 2014 +0000
Parent:
43:b1ae0ac88df9
Commit message:
Modified for using HW_Stack

Changed in this revision

MQTTClient.h Show annotated file Show diff for this revision Revisions of this file
MQTTEthernet.h Show annotated file Show diff for this revision Revisions of this file
MQTTSocket.h Show annotated file Show diff for this revision Revisions of this file
diff -r b1ae0ac88df9 -r f53a95f9c1d8 MQTTClient.h
--- a/MQTTClient.h	Fri Sep 26 08:04:47 2014 +0000
+++ b/MQTTClient.h	Mon Sep 29 04:56:42 2014 +0000
@@ -533,7 +533,7 @@
 
     if (options == 0)
         options = &default_options; // set default options if none were supplied
-    
+
     this->keepAliveInterval = options->keepAliveInterval;
     ping_timer.countdown(this->keepAliveInterval);
     if ((len = MQTTSerialize_connect(buf, MAX_MQTT_PACKET_SIZE, options)) <= 0)
diff -r b1ae0ac88df9 -r f53a95f9c1d8 MQTTEthernet.h
--- a/MQTTEthernet.h	Fri Sep 26 08:04:47 2014 +0000
+++ b/MQTTEthernet.h	Mon Sep 29 04:56:42 2014 +0000
@@ -1,24 +1,19 @@
-
 #if !defined(MQTTETHERNET_H)
 #define MQTTETHERNET_H
 
 #include "MQTT_mbed.h"
+#include "MQTTSocket.h"
 #include "../W5500Interface/EthernetInterface.h"
-#include "MQTTSocket.h"
 
 class MQTTEthernet : public MQTTSocket
 {
 public:    
-//    MQTTEthernet()
-//    {
-//        eth.init();                          // Use DHCP
-//        eth.connect();
-//    }
-    
     MQTTEthernet(SPI* spi, PinName cs, PinName reset): eth(spi, cs, reset)
     {
+        wait(1);
+        this->createSocket();
         eth.init();
-        eth.connect();
+       eth.connect();
     }
     
     EthernetInterface& getEth()
@@ -32,10 +27,8 @@
     }
     
 private:
-
     EthernetInterface eth;
     
 };
 
-
 #endif
diff -r b1ae0ac88df9 -r f53a95f9c1d8 MQTTSocket.h
--- a/MQTTSocket.h	Fri Sep 26 08:04:47 2014 +0000
+++ b/MQTTSocket.h	Mon Sep 29 04:56:42 2014 +0000
@@ -6,36 +6,45 @@
 
 class MQTTSocket
 {
-public:    
+public:                        
+    ~MQTTSocket()
+    {   
+        if(mysock)
+            delete mysock;
+    }   
+
     int connect(char* hostname, int port, int timeout=1000)
-    {
-        mysock.set_blocking(false, timeout);    // 1 second Timeout 
-        return mysock.connect(hostname, port);
-    }
+    {   
+        mysock->set_blocking(false, timeout);    // 1 second Timeout
+        return mysock->connect(hostname, port);
+    }   
 
     int read(unsigned char* buffer, int len, int timeout)
-    {
-        mysock.set_blocking(false, timeout);  
-        return mysock.receive((char*)buffer, len);
-    }
-    
+    {   
+        mysock->set_blocking(false, timeout);
+        return mysock->receive((char*)buffer, len);
+    }   
+        
     int write(unsigned char* buffer, int len, int timeout)
-    {
-        mysock.set_blocking(false, timeout);  
-        return mysock.send((char*)buffer, len);
-    }
-    
+    {   
+        mysock->set_blocking(false, timeout);
+        return mysock->send((char*)buffer, len);
+    }   
+        
     int disconnect()
-    {
-        return mysock.close();
-    }
-    
+    {   
+        return mysock->close();
+    }   
+           
+protected:
+    void createSocket() { mysock = new TCPSocketConnection(); }
+
 private:
 
-    TCPSocketConnection mysock; 
-    
+    TCPSocketConnection *mysock;
+        
 };
 
 
 
-#endif
+#endif
\ No newline at end of file