USE YHTANG AWS ACCOUNT TO TEST MQTT
Dependents: NuMaker-mbed-AWS-IoT-example
MQTTSocket.h@43:21da1f744243, 2014-09-29 (annotated)
- Committer:
- icraggs
- Date:
- Mon Sep 29 11:34:26 2014 +0000
- Revision:
- 43:21da1f744243
- Parent:
- 36:2f1ada427e56
- Child:
- 49:08571008b958
QoS 2 processing
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" |
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 |