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