MQTTClient
Dependents: IoTGateway_Basic test
MQTTClient.h@4:9e25b78e0352, 2012-03-21 (annotated)
- Committer:
- SomeRandomBloke
- Date:
- Wed Mar 21 21:54:25 2012 +0000
- Revision:
- 4:9e25b78e0352
- Parent:
- 3:ac326c5b065c
- Child:
- 5:29cefbfa0b48
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
SomeRandomBloke | 2:92b9dd336375 | 1 | /** |
SomeRandomBloke | 0:260fb10c0755 | 2 | MQTTClient.cpp |
SomeRandomBloke | 0:260fb10c0755 | 3 | Based on MQTTClient from http://ceit.uq.edu.au/content/mqttclient-mbed-version-20 |
SomeRandomBloke | 0:260fb10c0755 | 4 | A simple MQTT client for mbed, version 2.0 |
SomeRandomBloke | 0:260fb10c0755 | 5 | By Yilun FAN, @CEIT, @JAN 2011 |
SomeRandomBloke | 0:260fb10c0755 | 6 | |
SomeRandomBloke | 0:260fb10c0755 | 7 | Bug fixes and additions by Andrew Lindsay (andrew [at] thiseldo [dot] co [dot] uk) |
SomeRandomBloke | 0:260fb10c0755 | 8 | |
SomeRandomBloke | 0:260fb10c0755 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy |
SomeRandomBloke | 0:260fb10c0755 | 10 | of this software and associated documentation files (the "Software"), to deal |
SomeRandomBloke | 0:260fb10c0755 | 11 | in the Software without restriction, including without limitation the rights |
SomeRandomBloke | 0:260fb10c0755 | 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
SomeRandomBloke | 0:260fb10c0755 | 13 | copies of the Software, and to permit persons to whom the Software is |
SomeRandomBloke | 0:260fb10c0755 | 14 | furnished to do so, subject to the following conditions: |
SomeRandomBloke | 0:260fb10c0755 | 15 | |
SomeRandomBloke | 0:260fb10c0755 | 16 | The above copyright notice and this permission notice shall be included in |
SomeRandomBloke | 0:260fb10c0755 | 17 | all copies or substantial portions of the Software. |
SomeRandomBloke | 0:260fb10c0755 | 18 | |
SomeRandomBloke | 0:260fb10c0755 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
SomeRandomBloke | 0:260fb10c0755 | 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
SomeRandomBloke | 0:260fb10c0755 | 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
SomeRandomBloke | 0:260fb10c0755 | 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
SomeRandomBloke | 0:260fb10c0755 | 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
SomeRandomBloke | 0:260fb10c0755 | 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
SomeRandomBloke | 0:260fb10c0755 | 25 | THE SOFTWARE. |
SomeRandomBloke | 0:260fb10c0755 | 26 | */ |
SomeRandomBloke | 0:260fb10c0755 | 27 | |
SomeRandomBloke | 0:260fb10c0755 | 28 | #ifndef MQTT_CLIENT_H |
SomeRandomBloke | 0:260fb10c0755 | 29 | #define MQTT_CLIENT_H |
SomeRandomBloke | 0:260fb10c0755 | 30 | |
SomeRandomBloke | 0:260fb10c0755 | 31 | #include "mbed.h" |
SomeRandomBloke | 0:260fb10c0755 | 32 | #include "TCPSocket.h" |
SomeRandomBloke | 0:260fb10c0755 | 33 | |
SomeRandomBloke | 0:260fb10c0755 | 34 | #define MQTTCONNECT 1<<4 |
SomeRandomBloke | 0:260fb10c0755 | 35 | #define MQTTCONNACK 2<<4 |
SomeRandomBloke | 0:260fb10c0755 | 36 | #define MQTTPUBLISH 3<<4 |
SomeRandomBloke | 0:260fb10c0755 | 37 | #define MQTTSUBSCRIBE 8<<4 |
SomeRandomBloke | 0:260fb10c0755 | 38 | |
SomeRandomBloke | 0:260fb10c0755 | 39 | #define MAX_PACKET_SIZE 128 |
SomeRandomBloke | 0:260fb10c0755 | 40 | #define KEEPALIVE 15000 |
SomeRandomBloke | 0:260fb10c0755 | 41 | |
SomeRandomBloke | 0:260fb10c0755 | 42 | class MQTTClient |
SomeRandomBloke | 0:260fb10c0755 | 43 | { |
SomeRandomBloke | 0:260fb10c0755 | 44 | public: |
SomeRandomBloke | 2:92b9dd336375 | 45 | |
SomeRandomBloke | 0:260fb10c0755 | 46 | MQTTClient(); |
SomeRandomBloke | 0:260fb10c0755 | 47 | ~MQTTClient(); |
SomeRandomBloke | 2:92b9dd336375 | 48 | MQTTClient(IpAddr server, int port, void (*callback)(char*, char*)); |
SomeRandomBloke | 0:260fb10c0755 | 49 | void init(IpAddr *server, int port, void (*callback)(char*, char*)); |
SomeRandomBloke | 0:260fb10c0755 | 50 | void init(IpAddr *server, int port, char *userName, char *password, void (*callback)(char*, char*)); |
SomeRandomBloke | 0:260fb10c0755 | 51 | int connect(char *); |
SomeRandomBloke | 0:260fb10c0755 | 52 | void disconnect(); |
SomeRandomBloke | 0:260fb10c0755 | 53 | int publish(char *, char *); |
SomeRandomBloke | 0:260fb10c0755 | 54 | int subscribe(char *); |
SomeRandomBloke | 0:260fb10c0755 | 55 | void live(); |
SomeRandomBloke | 0:260fb10c0755 | 56 | |
SomeRandomBloke | 0:260fb10c0755 | 57 | private: |
SomeRandomBloke | 0:260fb10c0755 | 58 | int open_session(char* id); |
SomeRandomBloke | 0:260fb10c0755 | 59 | void read_open_session(); |
SomeRandomBloke | 0:260fb10c0755 | 60 | int send_data(const char* msg, int size); |
SomeRandomBloke | 0:260fb10c0755 | 61 | void read_data(); |
SomeRandomBloke | 0:260fb10c0755 | 62 | |
SomeRandomBloke | 0:260fb10c0755 | 63 | char* clientId; |
SomeRandomBloke | 0:260fb10c0755 | 64 | char* userName; |
SomeRandomBloke | 0:260fb10c0755 | 65 | char *password; |
SomeRandomBloke | 0:260fb10c0755 | 66 | Timer timer; |
SomeRandomBloke | 0:260fb10c0755 | 67 | IpAddr serverIp; |
SomeRandomBloke | 0:260fb10c0755 | 68 | int port; |
SomeRandomBloke | 0:260fb10c0755 | 69 | bool connected; |
SomeRandomBloke | 0:260fb10c0755 | 70 | bool sessionOpened; |
SomeRandomBloke | 0:260fb10c0755 | 71 | |
SomeRandomBloke | 0:260fb10c0755 | 72 | void onTCPSocketEvent(TCPSocketEvent e); |
SomeRandomBloke | 0:260fb10c0755 | 73 | TCPSocket* pTCPSocket; |
SomeRandomBloke | 0:260fb10c0755 | 74 | Host host; |
SomeRandomBloke | 0:260fb10c0755 | 75 | |
SomeRandomBloke | 0:260fb10c0755 | 76 | int lastActivity; |
SomeRandomBloke | 0:260fb10c0755 | 77 | void (*callback_server)(char*, char*); |
SomeRandomBloke | 0:260fb10c0755 | 78 | }; |
SomeRandomBloke | 0:260fb10c0755 | 79 | |
SomeRandomBloke | 0:260fb10c0755 | 80 | #endif |