Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FP MQTTPacket
Fork of MQTT by
Revision 44:f53a95f9c1d8, committed 2014-09-29
- Comitter:
- kaizen
- Date:
- Mon Sep 29 04:56:42 2014 +0000
- Parent:
- 43:b1ae0ac88df9
- Child:
- 45:ba32a33d6867
- Commit message:
- Modified for using HW_Stack
Changed in this revision
--- 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)
--- 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
--- 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
