An API for using MQTT over multiple transports for mbed OS 5

Dependencies:   FP MQTTPacket

Fork of MQTT by MQTT

Committer:
icraggs
Date:
Tue May 20 15:03:29 2014 +0000
Revision:
29:833386b16f3e
Child:
31:a51dd239b78e
Refactor header locations and separation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
icraggs 29:833386b16f3e 1
icraggs 29:833386b16f3e 2 #if !defined(MQTTETHERNET_H)
icraggs 29:833386b16f3e 3 #define MQTTETHERNET_H
icraggs 29:833386b16f3e 4
icraggs 29:833386b16f3e 5 #include "MQTT_mbed.h"
icraggs 29:833386b16f3e 6 #include "EthernetInterface.h"
icraggs 29:833386b16f3e 7
icraggs 29:833386b16f3e 8 class MQTTEthernet
icraggs 29:833386b16f3e 9 {
icraggs 29:833386b16f3e 10 public:
icraggs 29:833386b16f3e 11 MQTTEthernet()
icraggs 29:833386b16f3e 12 {
icraggs 29:833386b16f3e 13 eth.init(); // Use DHCP
icraggs 29:833386b16f3e 14 eth.connect();
icraggs 29:833386b16f3e 15 mysock.set_blocking(false, 1000); // 1 second Timeout
icraggs 29:833386b16f3e 16 }
icraggs 29:833386b16f3e 17
icraggs 29:833386b16f3e 18 int connect(char* hostname, int port)
icraggs 29:833386b16f3e 19 {
icraggs 29:833386b16f3e 20 return mysock.connect(hostname, port);
icraggs 29:833386b16f3e 21 }
icraggs 29:833386b16f3e 22
icraggs 29:833386b16f3e 23 int read(char* buffer, int len, int timeout)
icraggs 29:833386b16f3e 24 {
icraggs 29:833386b16f3e 25 mysock.set_blocking(false, timeout);
icraggs 29:833386b16f3e 26 return mysock.receive(buffer, len);
icraggs 29:833386b16f3e 27 }
icraggs 29:833386b16f3e 28
icraggs 29:833386b16f3e 29 int write(char* buffer, int len, int timeout)
icraggs 29:833386b16f3e 30 {
icraggs 29:833386b16f3e 31 mysock.set_blocking(false, timeout);
icraggs 29:833386b16f3e 32 return mysock.send(buffer, len);
icraggs 29:833386b16f3e 33 }
icraggs 29:833386b16f3e 34
icraggs 29:833386b16f3e 35 int disconnect()
icraggs 29:833386b16f3e 36 {
icraggs 29:833386b16f3e 37 return mysock.close();
icraggs 29:833386b16f3e 38 }
icraggs 29:833386b16f3e 39
icraggs 29:833386b16f3e 40 private:
icraggs 29:833386b16f3e 41
icraggs 29:833386b16f3e 42 EthernetInterface eth;
icraggs 29:833386b16f3e 43 TCPSocketConnection mysock;
icraggs 29:833386b16f3e 44
icraggs 29:833386b16f3e 45 };
icraggs 29:833386b16f3e 46
icraggs 29:833386b16f3e 47
icraggs 29:833386b16f3e 48
icraggs 29:833386b16f3e 49 #endif