mirror of
https://github.com/lumapu/ahoy.git
synced 2025-05-10 23:46:37 +02:00
Implement MQTT discovery for Home Assistant
This commit is contained in:
parent
b1f09d482f
commit
bbc725f316
6 changed files with 105 additions and 11 deletions
|
@ -29,6 +29,7 @@ class mqtt {
|
|||
DPRINTLN(DBG_VERBOSE, F("mqtt.h:setup"));
|
||||
mAddressSet = true;
|
||||
mClient->setServer(broker, port);
|
||||
mClient->setBufferSize(MQTT_MAX_PACKET_SIZE);
|
||||
|
||||
mPort = port;
|
||||
snprintf(mUser, MQTT_USER_LEN, "%s", user);
|
||||
|
@ -38,14 +39,17 @@ class mqtt {
|
|||
|
||||
void sendMsg(const char *topic, const char *msg) {
|
||||
//DPRINTLN(DBG_VERBOSE, F("mqtt.h:sendMsg"));
|
||||
if(mAddressSet) {
|
||||
char top[64];
|
||||
snprintf(top, 64, "%s/%s", mTopic, topic);
|
||||
char top[64];
|
||||
snprintf(top, 64, "%s/%s", mTopic, topic);
|
||||
sendMsg2(top, msg);
|
||||
}
|
||||
|
||||
void sendMsg2(const char *topic, const char *msg) {
|
||||
if(mAddressSet) {
|
||||
if(!mClient->connected())
|
||||
reconnect();
|
||||
if(mClient->connected())
|
||||
mClient->publish(top, msg);
|
||||
mClient->publish(topic, msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue