Mark Hembrow / Mbed 2 deprecated MQTTTEST

Dependencies:   EthernetNetIf TextLCD mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MQTTClient.h Source File

MQTTClient.h

00001 /**
00002  *A simple MQTT client for mbed, version 2.0
00003  *By Yilun FAN, @CEIT, @JAN 2011
00004  *
00005  */
00006 #ifndef MQTT_CLIENT_H
00007 #define MQTT_CLIENT_H
00008 
00009 #include "mbed.h"
00010 #include "TCPSocket.h"
00011 
00012 #define MQTTCONNECT 1<<4
00013 #define MQTTPUBLISH 3<<4
00014 #define MQTTSUBSCRIBE 8<<4
00015 
00016 #define MAX_PACKET_SIZE 128
00017 #define KEEPALIVE 15000
00018 
00019 class MQTTClient 
00020 {
00021 public:
00022     MQTTClient(IpAddr server, int port, void (*callback)(char*, char*));
00023     ~MQTTClient();
00024     int connect(char *);
00025     void disconnect();
00026     int publish(char *, char *);
00027     int subscribe(char *);
00028     void live();
00029     
00030 private:
00031     int open_session(char* id);
00032     void read_open_session();
00033     int send_data(const char* msg, int size);
00034     void read_data();
00035     
00036     char* clientId;
00037     Timer timer;
00038     IpAddr serverIp;
00039     int port;
00040     bool connected;
00041     bool sessionOpened;
00042     
00043     void onTCPSocketEvent(TCPSocketEvent e);
00044     TCPSocket* pTCPSocket;
00045     Host host;
00046     
00047     int lastActivity;
00048     void (*callback_server)(char*, char*);
00049 };
00050 
00051 #endif