-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmqtt.h
58 lines (46 loc) · 1.35 KB
/
mqtt.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
52
53
54
55
56
57
58
/*
* mqtt.h:
*
*/
#include <MQTTClient.h>
#include <time.h>
#include "iftop.h"
#include "hash.h"
//#define ADDRESS "tcp://test.mosquitto.org:1883"
//#define ADDRESS "tcp://localhost:1883"
//#define CLIENTID "ExampleClientPub"
#define QOS 1
#define TIMEOUT 10000L
#define SEND_TOPIC "NWSTAT/AUTO/"
#define RETRIEVE "NWSTAT/RETV/"
#define BROADCST "NWSTAT/BROADCAST"
/* set the reconnect internal to 10 mins
* if the connection is lost, we will try to reconnect to the broker
* in the next 10 mins */
#define RECONNECT_INTERVAL 120
// mqtt client status
typedef enum {
MQTT_STATUS_INIT,
MQTT_STATUS_LOST,
MQTT_STATUS_PENDING,
MQTT_STATUS_COMPLETE
} mqtt_status_enum;
typedef enum {
MQTT_CONNECT_ON,
MQTT_CONNECT_OFF,
} mqtt_connect_enum;
// callback functions
void delivered(void *context, MQTTClient_deliveryToken dt);
int msgarrvd(void *context, char *topicName, int topicLen, MQTTClient_message *message);
void connlost(void *context, char *cause);
// mqtt client
void init_MQTT(void);
void check_MQTT_connection(time_t t);
int connect_and_subscribe();
void get_device_id(void);
void construct_topic(void);
int construct_MQTT_msg(int n, hash_type* history);
void compress_msg(void);
void send_MQTT_msg(void);
void check_status(void);
void destory_MQTT(void);