use blue led to indicate status of MQTT connectivity
This commit is contained in:
parent
348e2694db
commit
b02c731e95
@ -28,10 +28,9 @@ namespace Devices {
|
|||||||
.addSecondary(Builder<PressureSensor>::instance(SENSOR_ID).withValueTemplate("{{ value_json.pressure }}").build())
|
.addSecondary(Builder<PressureSensor>::instance(SENSOR_ID).withValueTemplate("{{ value_json.pressure }}").build())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Switch* ledMqtt = Builder<Switch>::instance(new Switch{ "Led", "led",
|
auto ledMqtt = Builder<Switch>::instance(new Switch{ "Led", "led",
|
||||||
[](const char* msg) {
|
[](const char* msg) {
|
||||||
strcmp("ON", msg) == 0 ? digitalWrite(LED_BUILTIN, LOW) : digitalWrite(LED_BUILTIN, HIGH);
|
turnLed(strcmp("ON", msg) == 0);
|
||||||
ledMqtt->updateState(!digitalRead(LED_BUILTIN));
|
|
||||||
}
|
}
|
||||||
}).withStateTopic().restoreFromState().build();
|
}).withStateTopic().restoreFromState().build();
|
||||||
|
|
||||||
|
|||||||
@ -14,6 +14,10 @@ Scheduler ts;
|
|||||||
Task tCheckWifi(5 * TASK_MINUTE, TASK_ONCE, checkWifiCallback, &ts);
|
Task tCheckWifi(5 * TASK_MINUTE, TASK_ONCE, checkWifiCallback, &ts);
|
||||||
Task tWifiConnected(TASK_IMMEDIATE, TASK_ONCE, onWifiConnected, &ts);
|
Task tWifiConnected(TASK_IMMEDIATE, TASK_ONCE, onWifiConnected, &ts);
|
||||||
|
|
||||||
|
void turnLed(bool on = true) {
|
||||||
|
on ? digitalWrite(LED_BUILTIN, LOW) : digitalWrite(LED_BUILTIN, HIGH);
|
||||||
|
}
|
||||||
|
|
||||||
#include "bme.h"
|
#include "bme.h"
|
||||||
#include "ntp_time.h"
|
#include "ntp_time.h"
|
||||||
#include "wifi.h"
|
#include "wifi.h"
|
||||||
@ -56,7 +60,10 @@ void setup() {
|
|||||||
Ota::setup();
|
Ota::setup();
|
||||||
Ntp::setup();
|
Ntp::setup();
|
||||||
Bme::setup();
|
Bme::setup();
|
||||||
Mqtt::setup(&ts);
|
Mqtt::setup(&ts,
|
||||||
|
[] {turnLed(false);},
|
||||||
|
[] {turnLed();}
|
||||||
|
);
|
||||||
Devices::setup();
|
Devices::setup();
|
||||||
|
|
||||||
Wifi::setup();
|
Wifi::setup();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user