forked from dirkx/makerspaceleiden-payment-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMqttlogStream.h
46 lines (37 loc) · 1000 Bytes
/
MqttlogStream.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
#ifndef _H_MqttStream
#define _H_MqttStream
#include <Print.h>
#include <PubSubClient.h>
#include "log.h"
class MqttStream : public TLog {
public:
const char * name() {
return "MqttStream";
}
MqttStream(Client * client, const char * mqttServer = NULL, const char * mqttTopic = NULL, const uint16_t mqttPort = 1883) :
_client(client), _mqttServer(mqttServer), _mqttTopic(mqttTopic), _mqttPort(mqttPort) {
};
void setPort(uint16_t port) {
_mqttPort = port;
}
void setTopic(const char * topic) {
if (topic)
_mqttTopic = strdup(topic);
}
void setServer(const char * server) {
if (server)
_mqttServer = strdup(server);
}
virtual size_t write(uint8_t c);
virtual void begin();
virtual void loop();
private:
Client * _client;
PubSubClient * _mqtt = NULL;
const char * _mqttServer, * _mqttTopic;
uint16_t _mqttPort;
char logbuff[512];
size_t at = 0;
protected:
};
#endif