for WIZwiki-W7500 board

Dependencies:   FP MQTTPacket

Dependents:   IBMIoTClientEthernetExample_WIZnet

Fork of MQTT by MQTT

Files at this revision

API Documentation at this revision

Comitter:
hkjung
Date:
Mon Jun 29 11:55:39 2015 +0000
Parent:
44:c299463ae853
Child:
46:72659bc4048b
Commit message:
for WIZwiki-W7500 board

Changed in this revision

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
--- a/MQTTEthernet.h	Mon Oct 06 11:41:05 2014 +0000
+++ b/MQTTEthernet.h	Mon Jun 29 11:55:39 2015 +0000
@@ -6,12 +6,20 @@
 #include "EthernetInterface.h"
 #include "MQTTSocket.h"
 
+//uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x1D, 0x69, 0xF3};
+uint8_t mac_addr[6] = {0x00, 0x02, 0xf7, 0xf2, 0x05, 0x00};
+const char * ip_addr = "222.98.173.213";
+const char * gw_addr = "222.98.173.254";
+const char * snmask = "255.255.255.192";
+
 class MQTTEthernet : public MQTTSocket
 {
 public:    
     MQTTEthernet()
     {
-        eth.init();                          // Use DHCP
+        wait(1);
+        this->createSocket();
+        eth.init(mac_addr,ip_addr,snmask,gw_addr);                          // Use DHCP
         eth.connect();
     }
     
--- a/MQTTSocket.h	Mon Oct 06 11:41:05 2014 +0000
+++ b/MQTTSocket.h	Mon Jun 29 11:55:39 2015 +0000
@@ -3,7 +3,7 @@
 
 #include "MQTTmbed.h"
 #include "TCPSocketConnection.h"
-
+/*
 class MQTTSocket
 {
 public:    
@@ -35,7 +35,47 @@
     TCPSocketConnection mysock; 
     
 };
+*/
 
+class MQTTSocket
+{
+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);
+    }
+
+    int read(unsigned char* buffer, int len, int timeout)
+    {
+        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);
+    }
+    
+    int disconnect()
+    {
+        return mysock->close();
+    }
+
+protected:
+    void createSocket() { mysock = new TCPSocketConnection(); }
+private:
+
+    TCPSocketConnection *mysock; 
+    
+};
 
 
 #endif