Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of MQTTClient by
MQTTClient.h@11:2a8c86bfdeca, 2016-01-04 (annotated)
- Committer:
- wakwak_koba
- Date:
- Mon Jan 04 07:50:26 2016 +0000
- Revision:
- 11:2a8c86bfdeca
- Parent:
- 10:6fa55ad359f0
fixed comment
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| SomeRandomBloke | 5:29cefbfa0b48 | 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 | |
| wakwak_koba | 10:6fa55ad359f0 | 39 | //#define MAX_PACKET_SIZE 128 |
| wakwak_koba | 10:6fa55ad359f0 | 40 | //#define KEEPALIVE 15000 |
| SomeRandomBloke | 0:260fb10c0755 | 41 | |
| SomeRandomBloke | 5:29cefbfa0b48 | 42 | /** MQTTClient |
| SomeRandomBloke | 6:734e384f72c3 | 43 | * |
| SomeRandomBloke | 6:734e384f72c3 | 44 | * Based on MQTTClient code from http://ceit.uq.edu.au/content/mqttclient-mbed-version-20 |
| SomeRandomBloke | 5:29cefbfa0b48 | 45 | * A simple MQTT client for mbed, version 2.0 |
| SomeRandomBloke | 5:29cefbfa0b48 | 46 | * By Yilun FAN, @CEIT, @JAN 2011 |
| SomeRandomBloke | 5:29cefbfa0b48 | 47 | * |
| SomeRandomBloke | 5:29cefbfa0b48 | 48 | * Bug fixes and additions by Andrew Lindsay (andrew [at] thiseldo [dot] co [dot] uk) |
| SomeRandomBloke | 5:29cefbfa0b48 | 49 | */ |
| SomeRandomBloke | 0:260fb10c0755 | 50 | class MQTTClient |
| SomeRandomBloke | 0:260fb10c0755 | 51 | { |
| SomeRandomBloke | 0:260fb10c0755 | 52 | public: |
| SomeRandomBloke | 2:92b9dd336375 | 53 | |
| SomeRandomBloke | 0:260fb10c0755 | 54 | MQTTClient(); |
| SomeRandomBloke | 0:260fb10c0755 | 55 | ~MQTTClient(); |
| SomeRandomBloke | 2:92b9dd336375 | 56 | MQTTClient(IpAddr server, int port, void (*callback)(char*, char*)); |
| wakwak_koba | 10:6fa55ad359f0 | 57 | MQTTClient(IpAddr server, int port, char *id, char *userName, char *password, void (*callback)(char*, char*)); |
| wakwak_koba | 10:6fa55ad359f0 | 58 | int connect(); |
| wakwak_koba | 10:6fa55ad359f0 | 59 | int connect(char *id); |
| SomeRandomBloke | 0:260fb10c0755 | 60 | void disconnect(); |
| wakwak_koba | 10:6fa55ad359f0 | 61 | int publish(char *, char *, bool retain = false); |
| SomeRandomBloke | 0:260fb10c0755 | 62 | int subscribe(char *); |
| wakwak_koba | 10:6fa55ad359f0 | 63 | int keepalive; |
| SomeRandomBloke | 0:260fb10c0755 | 64 | void live(); |
| wakwak_koba | 10:6fa55ad359f0 | 65 | void pool(); |
| wakwak_koba | 10:6fa55ad359f0 | 66 | bool connected; |
| SomeRandomBloke | 0:260fb10c0755 | 67 | |
| SomeRandomBloke | 0:260fb10c0755 | 68 | private: |
| SomeRandomBloke | 0:260fb10c0755 | 69 | int open_session(char* id); |
| SomeRandomBloke | 0:260fb10c0755 | 70 | void read_open_session(); |
| SomeRandomBloke | 0:260fb10c0755 | 71 | int send_data(const char* msg, int size); |
| SomeRandomBloke | 0:260fb10c0755 | 72 | void read_data(); |
| SomeRandomBloke | 0:260fb10c0755 | 73 | |
| SomeRandomBloke | 0:260fb10c0755 | 74 | char* clientId; |
| SomeRandomBloke | 0:260fb10c0755 | 75 | char* userName; |
| SomeRandomBloke | 0:260fb10c0755 | 76 | char *password; |
| SomeRandomBloke | 0:260fb10c0755 | 77 | Timer timer; |
| SomeRandomBloke | 0:260fb10c0755 | 78 | IpAddr serverIp; |
| SomeRandomBloke | 0:260fb10c0755 | 79 | int port; |
| SomeRandomBloke | 0:260fb10c0755 | 80 | bool sessionOpened; |
| wakwak_koba | 10:6fa55ad359f0 | 81 | bool writtable; |
| SomeRandomBloke | 0:260fb10c0755 | 82 | |
| SomeRandomBloke | 0:260fb10c0755 | 83 | void onTCPSocketEvent(TCPSocketEvent e); |
| SomeRandomBloke | 0:260fb10c0755 | 84 | TCPSocket* pTCPSocket; |
| SomeRandomBloke | 0:260fb10c0755 | 85 | Host host; |
| SomeRandomBloke | 0:260fb10c0755 | 86 | |
| SomeRandomBloke | 0:260fb10c0755 | 87 | int lastActivity; |
| SomeRandomBloke | 0:260fb10c0755 | 88 | void (*callback_server)(char*, char*); |
| SomeRandomBloke | 0:260fb10c0755 | 89 | }; |
| SomeRandomBloke | 0:260fb10c0755 | 90 | |
| SomeRandomBloke | 0:260fb10c0755 | 91 | #endif |
