result of success : 1 to 0, max msg size: 127B to 16383B, fixed existing bugs
Fork of MQTTClient by
MQTTClient.h@3:ac326c5b065c, 2012-03-21 (annotated)
- Committer:
- SomeRandomBloke
- Date:
- Wed Mar 21 21:52:42 2012 +0000
- Revision:
- 3:ac326c5b065c
- Parent:
- 2:92b9dd336375
- Child:
- 4:9e25b78e0352
updated comments
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 | 2:92b9dd336375 | 42 | /** MQTTClient class |
SomeRandomBloke | 2:92b9dd336375 | 43 | * |
SomeRandomBloke | 2:92b9dd336375 | 44 | */ |
SomeRandomBloke | 0:260fb10c0755 | 45 | class MQTTClient |
SomeRandomBloke | 0:260fb10c0755 | 46 | { |
SomeRandomBloke | 0:260fb10c0755 | 47 | public: |
SomeRandomBloke | 2:92b9dd336375 | 48 | |
SomeRandomBloke | 0:260fb10c0755 | 49 | MQTTClient(); |
SomeRandomBloke | 0:260fb10c0755 | 50 | ~MQTTClient(); |
SomeRandomBloke | 2:92b9dd336375 | 51 | MQTTClient(IpAddr server, int port, void (*callback)(char*, char*)); |
SomeRandomBloke | 0:260fb10c0755 | 52 | void init(IpAddr *server, int port, void (*callback)(char*, char*)); |
SomeRandomBloke | 0:260fb10c0755 | 53 | void init(IpAddr *server, int port, char *userName, char *password, void (*callback)(char*, char*)); |
SomeRandomBloke | 0:260fb10c0755 | 54 | int connect(char *); |
SomeRandomBloke | 0:260fb10c0755 | 55 | void disconnect(); |
SomeRandomBloke | 0:260fb10c0755 | 56 | int publish(char *, char *); |
SomeRandomBloke | 0:260fb10c0755 | 57 | int subscribe(char *); |
SomeRandomBloke | 0:260fb10c0755 | 58 | void live(); |
SomeRandomBloke | 0:260fb10c0755 | 59 | |
SomeRandomBloke | 0:260fb10c0755 | 60 | private: |
SomeRandomBloke | 0:260fb10c0755 | 61 | int open_session(char* id); |
SomeRandomBloke | 0:260fb10c0755 | 62 | void read_open_session(); |
SomeRandomBloke | 0:260fb10c0755 | 63 | int send_data(const char* msg, int size); |
SomeRandomBloke | 0:260fb10c0755 | 64 | void read_data(); |
SomeRandomBloke | 0:260fb10c0755 | 65 | |
SomeRandomBloke | 0:260fb10c0755 | 66 | char* clientId; |
SomeRandomBloke | 0:260fb10c0755 | 67 | char* userName; |
SomeRandomBloke | 0:260fb10c0755 | 68 | char *password; |
SomeRandomBloke | 0:260fb10c0755 | 69 | Timer timer; |
SomeRandomBloke | 0:260fb10c0755 | 70 | IpAddr serverIp; |
SomeRandomBloke | 0:260fb10c0755 | 71 | int port; |
SomeRandomBloke | 0:260fb10c0755 | 72 | bool connected; |
SomeRandomBloke | 0:260fb10c0755 | 73 | bool sessionOpened; |
SomeRandomBloke | 0:260fb10c0755 | 74 | |
SomeRandomBloke | 0:260fb10c0755 | 75 | void onTCPSocketEvent(TCPSocketEvent e); |
SomeRandomBloke | 0:260fb10c0755 | 76 | TCPSocket* pTCPSocket; |
SomeRandomBloke | 0:260fb10c0755 | 77 | Host host; |
SomeRandomBloke | 0:260fb10c0755 | 78 | |
SomeRandomBloke | 0:260fb10c0755 | 79 | int lastActivity; |
SomeRandomBloke | 0:260fb10c0755 | 80 | void (*callback_server)(char*, char*); |
SomeRandomBloke | 0:260fb10c0755 | 81 | }; |
SomeRandomBloke | 0:260fb10c0755 | 82 | |
SomeRandomBloke | 0:260fb10c0755 | 83 | #endif |