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

Dependencies:   FP MQTTPacket

Fork of MQTT by MQTT

Committer:
JPlenert
Date:
Mon Jan 30 19:26:31 2017 +0000
Revision:
47:a38f394916ff
Parent:
43:21da1f744243
Needed changed for mbed OS 5

Who changed what in which revision?

UserRevisionLine numberNew contents of line
icraggs 31:a51dd239b78e 1 #if !defined(MQTTSOCKET_H)
icraggs 31:a51dd239b78e 2 #define MQTTSOCKET_H
icraggs 31:a51dd239b78e 3
icraggs 43:21da1f744243 4 #include "MQTTmbed.h"
JPlenert 47:a38f394916ff 5 #include <TCPSocket.h>
icraggs 31:a51dd239b78e 6
icraggs 31:a51dd239b78e 7 class MQTTSocket
icraggs 31:a51dd239b78e 8 {
JPlenert 47:a38f394916ff 9 public:
JPlenert 47:a38f394916ff 10 MQTTSocket(EthernetInterface &eth)
JPlenert 47:a38f394916ff 11 {
JPlenert 47:a38f394916ff 12 mysock.open(&eth);
JPlenert 47:a38f394916ff 13 }
JPlenert 47:a38f394916ff 14
icraggs 31:a51dd239b78e 15 int connect(char* hostname, int port, int timeout=1000)
icraggs 31:a51dd239b78e 16 {
JPlenert 47:a38f394916ff 17 mysock.set_timeout(timeout);
icraggs 31:a51dd239b78e 18 return mysock.connect(hostname, port);
icraggs 31:a51dd239b78e 19 }
icraggs 31:a51dd239b78e 20
icraggs 36:2f1ada427e56 21 int read(unsigned char* buffer, int len, int timeout)
icraggs 31:a51dd239b78e 22 {
JPlenert 47:a38f394916ff 23 mysock.set_timeout(timeout);
JPlenert 47:a38f394916ff 24 return mysock.recv((void*)buffer, len);
icraggs 31:a51dd239b78e 25 }
icraggs 31:a51dd239b78e 26
icraggs 36:2f1ada427e56 27 int write(unsigned char* buffer, int len, int timeout)
icraggs 31:a51dd239b78e 28 {
JPlenert 47:a38f394916ff 29 mysock.set_timeout(timeout);
icraggs 36:2f1ada427e56 30 return mysock.send((char*)buffer, len);
icraggs 31:a51dd239b78e 31 }
icraggs 31:a51dd239b78e 32
icraggs 31:a51dd239b78e 33 int disconnect()
icraggs 31:a51dd239b78e 34 {
icraggs 31:a51dd239b78e 35 return mysock.close();
icraggs 31:a51dd239b78e 36 }
icraggs 31:a51dd239b78e 37
icraggs 31:a51dd239b78e 38 private:
icraggs 31:a51dd239b78e 39
JPlenert 47:a38f394916ff 40 TCPSocket mysock;
icraggs 31:a51dd239b78e 41
icraggs 31:a51dd239b78e 42 };
icraggs 31:a51dd239b78e 43
icraggs 31:a51dd239b78e 44
icraggs 31:a51dd239b78e 45
icraggs 31:a51dd239b78e 46 #endif