Modified MQTT for Mbed OS.
Dependents: mbed-os-mqtt door_lock co657_IoT nucleo-f429zi-mbed-os-mqtt
Fork of MQTT by
MQTTSocket.h@51:ac90fd2dd859, 2016-11-18 (annotated)
- Committer:
- azazeal88
- Date:
- Fri Nov 18 13:29:50 2016 +0000
- Revision:
- 51:ac90fd2dd859
- Parent:
- 48:83e45fa35cc8
Buffer at 4096 was causing issues. Have reverted, but will need to look closer at allocation
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 | 43:21da1f744243 | 4 | #include "MQTTmbed.h" |
azazeal88 | 47:a84464ad0b6f | 5 | #include "TCPSocket.h" |
icraggs | 31:a51dd239b78e | 6 | |
icraggs | 31:a51dd239b78e | 7 | class MQTTSocket |
icraggs | 31:a51dd239b78e | 8 | { |
icraggs | 31:a51dd239b78e | 9 | public: |
azazeal88 | 47:a84464ad0b6f | 10 | |
azazeal88 | 47:a84464ad0b6f | 11 | int open(EthernetInterface& eth){ |
azazeal88 | 47:a84464ad0b6f | 12 | return mysock.open(ð); |
azazeal88 | 47:a84464ad0b6f | 13 | } |
azazeal88 | 47:a84464ad0b6f | 14 | |
icraggs | 31:a51dd239b78e | 15 | int connect(char* hostname, int port, int timeout=1000) |
icraggs | 31:a51dd239b78e | 16 | { |
azazeal88 | 48:83e45fa35cc8 | 17 | mysock.set_blocking(false); |
azazeal88 | 48:83e45fa35cc8 | 18 | mysock.set_timeout(timeout); |
icraggs | 31:a51dd239b78e | 19 | return mysock.connect(hostname, port); |
icraggs | 31:a51dd239b78e | 20 | } |
icraggs | 31:a51dd239b78e | 21 | |
icraggs | 36:2f1ada427e56 | 22 | int read(unsigned char* buffer, int len, int timeout) |
icraggs | 31:a51dd239b78e | 23 | { |
azazeal88 | 48:83e45fa35cc8 | 24 | mysock.set_blocking(false); |
azazeal88 | 48:83e45fa35cc8 | 25 | mysock.set_timeout(timeout); |
azazeal88 | 47:a84464ad0b6f | 26 | return mysock.recv((char*)buffer, len); |
icraggs | 31:a51dd239b78e | 27 | } |
icraggs | 31:a51dd239b78e | 28 | |
icraggs | 36:2f1ada427e56 | 29 | int write(unsigned char* buffer, int len, int timeout) |
icraggs | 31:a51dd239b78e | 30 | { |
azazeal88 | 48:83e45fa35cc8 | 31 | mysock.set_blocking(false); |
azazeal88 | 48:83e45fa35cc8 | 32 | mysock.set_timeout(timeout); |
icraggs | 36:2f1ada427e56 | 33 | return mysock.send((char*)buffer, len); |
icraggs | 31:a51dd239b78e | 34 | } |
icraggs | 31:a51dd239b78e | 35 | |
icraggs | 31:a51dd239b78e | 36 | int disconnect() |
icraggs | 31:a51dd239b78e | 37 | { |
icraggs | 31:a51dd239b78e | 38 | return mysock.close(); |
icraggs | 31:a51dd239b78e | 39 | } |
icraggs | 31:a51dd239b78e | 40 | |
icraggs | 31:a51dd239b78e | 41 | private: |
icraggs | 31:a51dd239b78e | 42 | |
azazeal88 | 47:a84464ad0b6f | 43 | TCPSocket mysock; |
icraggs | 31:a51dd239b78e | 44 | |
icraggs | 31:a51dd239b78e | 45 | }; |
icraggs | 31:a51dd239b78e | 46 | |
icraggs | 31:a51dd239b78e | 47 | |
icraggs | 31:a51dd239b78e | 48 | |
icraggs | 31:a51dd239b78e | 49 | #endif |