High level MQTT-SN C++ library
Dependencies: EthernetInterface FP MQTTSNPacket
MQTTSNUDP.h@1:3f59a8468e46, 2015-02-26 (annotated)
- Committer:
- icraggs
- Date:
- Thu Feb 26 23:51:56 2015 +0000
- Revision:
- 1:3f59a8468e46
- Parent:
- 0:ae83cacd60d2
MQTTSN high level C++ library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
icraggs | 0:ae83cacd60d2 | 1 | #if !defined(MQTTSOCKET_H) |
icraggs | 0:ae83cacd60d2 | 2 | #define MQTTSOCKET_H |
icraggs | 0:ae83cacd60d2 | 3 | |
icraggs | 0:ae83cacd60d2 | 4 | #include "MQTTmbed.h" |
icraggs | 0:ae83cacd60d2 | 5 | #include "UDPSocket.h" |
icraggs | 0:ae83cacd60d2 | 6 | |
icraggs | 0:ae83cacd60d2 | 7 | class MQTTSNUDP |
icraggs | 0:ae83cacd60d2 | 8 | { |
icraggs | 0:ae83cacd60d2 | 9 | public: |
icraggs | 0:ae83cacd60d2 | 10 | int connect(char* hostname, int port, int timeout=1000) |
icraggs | 0:ae83cacd60d2 | 11 | { |
icraggs | 0:ae83cacd60d2 | 12 | mysock.init(); |
icraggs | 0:ae83cacd60d2 | 13 | //mysock.set_blocking(false, timeout); // 1 second Timeout |
icraggs | 0:ae83cacd60d2 | 14 | return remote.set_address((const char *)hostname, port); |
icraggs | 0:ae83cacd60d2 | 15 | } |
icraggs | 0:ae83cacd60d2 | 16 | |
icraggs | 0:ae83cacd60d2 | 17 | int read(unsigned char* buffer, int len, int timeout) |
icraggs | 0:ae83cacd60d2 | 18 | { |
icraggs | 0:ae83cacd60d2 | 19 | mysock.set_blocking(false, timeout); |
icraggs | 0:ae83cacd60d2 | 20 | return mysock.receiveFrom(remote, (char *)buffer, len); |
icraggs | 0:ae83cacd60d2 | 21 | } |
icraggs | 0:ae83cacd60d2 | 22 | |
icraggs | 0:ae83cacd60d2 | 23 | int write(unsigned char* buffer, int len, int timeout) |
icraggs | 0:ae83cacd60d2 | 24 | { |
icraggs | 0:ae83cacd60d2 | 25 | mysock.set_blocking(false, timeout); |
icraggs | 0:ae83cacd60d2 | 26 | return mysock.sendTo(remote, (char*)buffer, len); |
icraggs | 0:ae83cacd60d2 | 27 | } |
icraggs | 0:ae83cacd60d2 | 28 | |
icraggs | 0:ae83cacd60d2 | 29 | int disconnect() |
icraggs | 0:ae83cacd60d2 | 30 | { |
icraggs | 0:ae83cacd60d2 | 31 | return mysock.close(); |
icraggs | 0:ae83cacd60d2 | 32 | } |
icraggs | 0:ae83cacd60d2 | 33 | |
icraggs | 0:ae83cacd60d2 | 34 | private: |
icraggs | 0:ae83cacd60d2 | 35 | |
icraggs | 0:ae83cacd60d2 | 36 | UDPSocket mysock; |
icraggs | 0:ae83cacd60d2 | 37 | Endpoint remote; |
icraggs | 0:ae83cacd60d2 | 38 | |
icraggs | 0:ae83cacd60d2 | 39 | }; |
icraggs | 0:ae83cacd60d2 | 40 | |
icraggs | 0:ae83cacd60d2 | 41 | |
icraggs | 0:ae83cacd60d2 | 42 | |
icraggs | 0:ae83cacd60d2 | 43 | #endif |