move read temp logic into main
This commit is contained in:
parent
fa11355767
commit
23de23a2e0
@ -19,7 +19,6 @@ namespace Mqtt {
|
||||
void disconnect();
|
||||
Task tReConnect(5 * TASK_MINUTE, TASK_FOREVER, connect, &ts);
|
||||
Task tPublishInit(TASK_IMMEDIATE, TASK_ONCE, publishInit, &ts);
|
||||
Task tPublishBmp(TASK_MINUTE, TASK_FOREVER, publishBmp280, &ts);
|
||||
Task tPublishCommand(TASK_SECOND, TASK_FOREVER, publishCommand, &ts);
|
||||
|
||||
AsyncMqttClient client;
|
||||
@ -120,11 +119,6 @@ namespace Mqtt {
|
||||
}
|
||||
|
||||
void publishBmp280() {
|
||||
static float lastTemp = 0;
|
||||
Bmp::data.readAll();
|
||||
if (abs(lastTemp - Bmp::data.temp) <= 0.2) return;
|
||||
lastTemp = Bmp::data.temp;
|
||||
Display::displayTemp(Bmp::data.temp);
|
||||
StaticJsonDocument<255> jsonDoc;
|
||||
jsonDoc["temperature"] = Bmp::data.temp;
|
||||
jsonDoc["pressure"] = Bmp::data.pressure;
|
||||
@ -163,7 +157,6 @@ namespace Mqtt {
|
||||
Display::onHourFormatChanged(hourFormatMqtt->publishState);
|
||||
client.onConnect([](bool sessionPresent) {
|
||||
tPublishInit.enable();
|
||||
tPublishBmp.enableIfNot();
|
||||
tPublishCommand.enableDelayed();
|
||||
client.subscribe(espClockTopic, 0);
|
||||
tReConnect.disable();
|
||||
@ -172,7 +165,6 @@ namespace Mqtt {
|
||||
client.onDisconnect([](AsyncMqttClientDisconnectReason reason) {
|
||||
tReConnect.enableDelayed();
|
||||
tPublishCommand.disable();
|
||||
tPublishBmp.disable();
|
||||
Serial.println("Disconnected from MQTT");
|
||||
});
|
||||
client.onMessage(onMessage);
|
||||
|
||||
@ -27,6 +27,14 @@ Task tButton(TASK_IMMEDIATE, TASK_ONCE, []() {
|
||||
Task tLed(TASK_IMMEDIATE, TASK_ONCE, []() {
|
||||
Mqtt::ledMqtt->publishState();
|
||||
}, &ts);
|
||||
Task tReadBmp(TASK_MINUTE, TASK_FOREVER, []() {
|
||||
static float lastTemp = 0;
|
||||
Bmp::data.readAll();
|
||||
if (abs(lastTemp - Bmp::data.temp) <= 0.2) return;
|
||||
lastTemp = Bmp::data.temp;
|
||||
Display::displayTemp(Bmp::data.temp);
|
||||
Mqtt::publishBmp280();
|
||||
}, &ts, true);
|
||||
|
||||
void setup() {
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user