gftgtgtf
Fork of MQTT by
Revision 45:b7cebc104c6c, committed 2015-06-28
- Comitter:
- bangbh
- Date:
- Sun Jun 28 22:44:19 2015 +0000
- Parent:
- 44:c299463ae853
- Child:
- 46:88f62eb29442
- Commit message:
- The MQTTEthernet.h and MQTTSocket.h file is changed for the W7500.
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 Sun Jun 28 22:44:19 2015 +0000
@@ -6,12 +6,20 @@
#include "EthernetInterface.h"
#include "MQTTSocket.h"
+
+uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x1E, 0x72, 0x1B};
+const char * ip_addr = "222.98.173.249";
+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 Sun Jun 28 22:44:19 2015 +0000
@@ -6,33 +6,41 @@
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;
};
