-
Notifications
You must be signed in to change notification settings - Fork 0
/
mymosqclient.h
52 lines (48 loc) · 1.35 KB
/
mymosqclient.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
#ifndef MYMOSQCLIENT_H
#define MYMOSQCLIENT_H
#include <mosquittopp.h>
#include <string.h>
#include <string>
#include <iostream>
#include <syslog.h>
#include <sstream>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <syslog.h>
#include <string.h>
#include <vector>
#include "SerialPort.h"
//#define DEAMON
#define PORT "/dev/ttyUSB0"
#define BAUDRATE 115200
#define HOST "localhost"
#define TOPIC "kitchen/switches/#"
#define qos 1
class MQTTSerialInterface : public mosqpp::mosquittopp
{
public:
MQTTSerialInterface(const char* id, const char* host = "localhost", int port = 1883, int keepalive = 60);
~MQTTSerialInterface();
private:
void on_connect(int rc);
void on_disconnect(int rc);
void on_error();
//void on_exit();
void on_log(int level, const char *msg);
void on_publish(int mid);
void on_message(const struct mosquitto_message *message);
void on_subscribe(int mid, int qos_count, const int *granted_qos);
void on_unsubscribe(int mid);
void log(std::stringstream &info, int prio = LOG_ALERT);
void setcolor(int color, int lightn);
void evaluateMQTT(std::string payload, std::string topic);
char Crc8(const char *data, int len);
SerialPort *serialPort;
char *serialData;
};
#endif // MYMOSQCLIENT_H