An API for using MQTT over multiple transports

Dependencies:   FP MQTTPacket

Dependents:   Cellular_HelloMQTT IoTStarterKit GSwifiInterface_HelloMQTT IBMIoTClientEthernetExample ... more

This library is part of the EclipseTM Paho project; specifically the embedded client.

The goals of this API are:

  1. to be independent of any system library: hence templates parameters for networking, timer and threading classes
  2. not to rely on heap storage, only automatic (I think this is a good thing)
  3. to limit memory use, for instance by defining the size of the buffers and arrays used at object creation time
Committer:
icraggs
Date:
Thu Aug 21 12:40:43 2014 +0000
Revision:
42:f5beda831651
Parent:
36:2f1ada427e56
Child:
43:21da1f744243
latest updates

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 31:a51dd239b78e 4 #include "MQTT_mbed.h"
icraggs 31:a51dd239b78e 5 #include "TCPSocketConnection.h"
icraggs 31:a51dd239b78e 6
icraggs 31:a51dd239b78e 7 class MQTTSocket
icraggs 31:a51dd239b78e 8 {
icraggs 31:a51dd239b78e 9 public:
icraggs 31:a51dd239b78e 10 int connect(char* hostname, int port, int timeout=1000)
icraggs 31:a51dd239b78e 11 {
icraggs 31:a51dd239b78e 12 mysock.set_blocking(false, timeout); // 1 second Timeout
icraggs 31:a51dd239b78e 13 return mysock.connect(hostname, port);
icraggs 31:a51dd239b78e 14 }
icraggs 31:a51dd239b78e 15
icraggs 36:2f1ada427e56 16 int read(unsigned char* buffer, int len, int timeout)
icraggs 31:a51dd239b78e 17 {
icraggs 31:a51dd239b78e 18 mysock.set_blocking(false, timeout);
icraggs 36:2f1ada427e56 19 return mysock.receive((char*)buffer, len);
icraggs 31:a51dd239b78e 20 }
icraggs 31:a51dd239b78e 21
icraggs 36:2f1ada427e56 22 int write(unsigned char* buffer, int len, int timeout)
icraggs 31:a51dd239b78e 23 {
icraggs 31:a51dd239b78e 24 mysock.set_blocking(false, timeout);
icraggs 36:2f1ada427e56 25 return mysock.send((char*)buffer, len);
icraggs 31:a51dd239b78e 26 }
icraggs 31:a51dd239b78e 27
icraggs 31:a51dd239b78e 28 int disconnect()
icraggs 31:a51dd239b78e 29 {
icraggs 31:a51dd239b78e 30 return mysock.close();
icraggs 31:a51dd239b78e 31 }
icraggs 31:a51dd239b78e 32
icraggs 31:a51dd239b78e 33 private:
icraggs 31:a51dd239b78e 34
icraggs 31:a51dd239b78e 35 TCPSocketConnection mysock;
icraggs 31:a51dd239b78e 36
icraggs 31:a51dd239b78e 37 };
icraggs 31:a51dd239b78e 38
icraggs 31:a51dd239b78e 39
icraggs 31:a51dd239b78e 40
icraggs 31:a51dd239b78e 41 #endif