-
Notifications
You must be signed in to change notification settings - Fork 5
/
MQTTClient.h
executable file
·51 lines (42 loc) · 1.01 KB
/
MQTTClient.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
*A simple MQTT client for mbed, version 2.0
*By Yilun FAN, @CEIT, @JAN 2011
*
*/
#ifndef MQTT_CLIENT_H
#define MQTT_CLIENT_H
#include "mbed.h"
#include "TCPSocket.h"
#define MQTTCONNECT 1<<4
#define MQTTPUBLISH 3<<4
#define MQTTSUBSCRIBE 8<<4
#define MAX_PACKET_SIZE 128
#define KEEPALIVE 15000
class MQTTClient
{
public:
MQTTClient(IpAddr server, int port, void (*callback)(char*, char*));
~MQTTClient();
int connect(char *);
void disconnect();
int publish(char *, char *);
int subscribe(char *);
void live();
private:
int open_session(char* id);
void read_open_session();
int send_data(const char* msg, int size);
void read_data();
char* clientId;
Timer timer;
IpAddr serverIp;
int port;
bool connected;
bool sessionOpened;
void onTCPSocketEvent(TCPSocketEvent e);
TCPSocket* pTCPSocket;
Host host;
int lastActivity;
void (*callback_server)(char*, char*);
};
#endif