An API for using MQTT over multiple transports for mbed OS 5
Fork of MQTT by
MQTTSocket.h@36:2f1ada427e56, 2014-08-01 (annotated)
- Committer:
- icraggs
- Date:
- Fri Aug 01 14:45:25 2014 +0000
- Revision:
- 36:2f1ada427e56
- Parent:
- 31:a51dd239b78e
- Child:
- 43:21da1f744243
Update types to match MQTTPacket changes
Who changed what in which revision?
User | Revision | Line number | New 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 |