MQTTClient

Dependents:   IoTGateway_Basic test

Committer:
SomeRandomBloke
Date:
Thu Apr 05 07:50:30 2012 +0000
Revision:
9:a0e39cea763a
Parent:
6:734e384f72c3
quick fix to a length

Who changed what in which revision?

UserRevisionLine numberNew 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
SomeRandomBloke 0:260fb10c0755 39 #define MAX_PACKET_SIZE 128
SomeRandomBloke 0:260fb10c0755 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*));
SomeRandomBloke 0:260fb10c0755 57 void init(IpAddr *server, int port, void (*callback)(char*, char*));
SomeRandomBloke 0:260fb10c0755 58 void init(IpAddr *server, int port, char *userName, char *password, void (*callback)(char*, char*));
SomeRandomBloke 0:260fb10c0755 59 int connect(char *);
SomeRandomBloke 0:260fb10c0755 60 void disconnect();
SomeRandomBloke 0:260fb10c0755 61 int publish(char *, char *);
SomeRandomBloke 0:260fb10c0755 62 int subscribe(char *);
SomeRandomBloke 0:260fb10c0755 63 void live();
SomeRandomBloke 0:260fb10c0755 64
SomeRandomBloke 0:260fb10c0755 65 private:
SomeRandomBloke 0:260fb10c0755 66 int open_session(char* id);
SomeRandomBloke 0:260fb10c0755 67 void read_open_session();
SomeRandomBloke 0:260fb10c0755 68 int send_data(const char* msg, int size);
SomeRandomBloke 0:260fb10c0755 69 void read_data();
SomeRandomBloke 0:260fb10c0755 70
SomeRandomBloke 0:260fb10c0755 71 char* clientId;
SomeRandomBloke 0:260fb10c0755 72 char* userName;
SomeRandomBloke 0:260fb10c0755 73 char *password;
SomeRandomBloke 0:260fb10c0755 74 Timer timer;
SomeRandomBloke 0:260fb10c0755 75 IpAddr serverIp;
SomeRandomBloke 0:260fb10c0755 76 int port;
SomeRandomBloke 0:260fb10c0755 77 bool connected;
SomeRandomBloke 0:260fb10c0755 78 bool sessionOpened;
SomeRandomBloke 0:260fb10c0755 79
SomeRandomBloke 0:260fb10c0755 80 void onTCPSocketEvent(TCPSocketEvent e);
SomeRandomBloke 0:260fb10c0755 81 TCPSocket* pTCPSocket;
SomeRandomBloke 0:260fb10c0755 82 Host host;
SomeRandomBloke 0:260fb10c0755 83
SomeRandomBloke 0:260fb10c0755 84 int lastActivity;
SomeRandomBloke 0:260fb10c0755 85 void (*callback_server)(char*, char*);
SomeRandomBloke 0:260fb10c0755 86 };
SomeRandomBloke 0:260fb10c0755 87
SomeRandomBloke 0:260fb10c0755 88 #endif