MQTTHelpers.h
2.13 KB
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
59
60
61
62
#pragma once
#include <Arduino.h>
#include <MqttClient.h>
#include <ArduinoJson.h>
const size_t fullJsonDocSize = 2 * 1024;
const char * chipID();
const char * shortID();
// ============== Object to supply system functions ============================
class System: public MqttClient::System {
public:
unsigned long millis() const {
return ::millis();
}
void yield(void) {
::yield();
}
};
void discoveryMessageSetIDs(char * discoveryMsgJson);
const char * topicByReference(const char * key,
const char * discoveryMsgJson);
bool validJson(const char * discoveryMsgJson);
bool connectMQTT(MqttClient & client,
const char * clientID,
const char * user,
const char * password);
bool publish(MqttClient & client,
const char * topic,
const char * payload,
bool retained = false);
bool discoveryMsgToJsonDoc(JsonDocument & discoveryMsgDoc,
const char * discoveryMsgJson);
bool addEntity(MqttClient & client,
const char * component,
const char * object,
JsonDocument & discoveryMsgDoc);
bool addEntity(MqttClient & client,
const char * component,
const char * object,
const char * discoveryMsgJson);
bool subscribe(MqttClient & client,
MqttClient::MessageHandlerCbk cbk,
const char * discoveryMessage,
const char * key);