improved bus wait with raii class that updates last access
This commit is contained in:
26
src/main.cpp
26
src/main.cpp
@@ -1,3 +1,5 @@
|
||||
#define DEBUGLOG_DEFAULT_LOG_LEVEL_INFO
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <DebugLog.h>
|
||||
#include <DebugLogEnable.h>
|
||||
@@ -57,7 +59,7 @@ void loop()
|
||||
std::function<void(const ArduinoJson::JsonDocument &)> commandsCallback =
|
||||
[&mqtt, &devices](const ArduinoJson::JsonDocument &doc)
|
||||
{
|
||||
if (!doc["cmd"].is<std::string>() || !doc["params"].is<ArduinoJson::JsonObject>())
|
||||
if (!doc["cmd"].is<std::string>())
|
||||
{
|
||||
LOG_ERROR("Invalid Json Command");
|
||||
return;
|
||||
@@ -123,19 +125,19 @@ void loop()
|
||||
|
||||
while (true)
|
||||
{
|
||||
const uint32_t start(millis());
|
||||
const std::string timeStr(rtc.getTimeStr());
|
||||
LOG_INFO("[", k++, "] Loop - Current Datetime", timeStr.c_str());
|
||||
|
||||
{
|
||||
ArduinoJson::JsonDocument poll;
|
||||
poll["cmd"] = "POLL";
|
||||
auto params = poll["params"].to<ArduinoJson::JsonObject>();
|
||||
auto params = poll["values"].to<ArduinoJson::JsonObject>();
|
||||
params["time"] = timeStr;
|
||||
params["number"] = k;
|
||||
mqtt.publish(conf.m_mqttPublish["answers"], poll);
|
||||
};
|
||||
|
||||
|
||||
{
|
||||
ArduinoJson::JsonDocument ti;
|
||||
auto tempinfo = tmp.getTempAll();
|
||||
@@ -144,17 +146,7 @@ void loop()
|
||||
ti["heating"] = tempinfo.at(0);
|
||||
mqtt.publish(conf.m_mqttPublish["temperatures"], ti);
|
||||
};
|
||||
|
||||
{
|
||||
ArduinoJson::JsonDocument pi;
|
||||
auto powerinfo = seneca.getAll();
|
||||
pi["power"] = powerinfo.pAct;
|
||||
pi["current"] = powerinfo.a;
|
||||
pi["energy"] = powerinfo.whPar;
|
||||
pi["voltage"] = powerinfo.v;
|
||||
mqtt.publish(conf.m_mqttPublish["heatpump"], pi);
|
||||
}
|
||||
|
||||
|
||||
if (io.digitalInRead(0)) // ROSSO - Config Reset
|
||||
{
|
||||
LOG_WARN("Config RESET!");
|
||||
@@ -162,7 +154,7 @@ void loop()
|
||||
delay(500);
|
||||
conf.resetConfig();
|
||||
}
|
||||
|
||||
|
||||
if (io.digitalInRead(1)) // GIALLO - Restart
|
||||
{
|
||||
LOG_WARN("RESTART!");
|
||||
@@ -171,9 +163,9 @@ void loop()
|
||||
esp_restart();
|
||||
}
|
||||
|
||||
delay(conf.m_globalLoopDelay); // to avoid too fast loop
|
||||
delay(conf.m_globalLoopDelay - (start - millis())); // to avoid too fast loop, keep precise timing computing loop time
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////
|
||||
///////// MAIN LOOP INSIDE LOOP ////////
|
||||
////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user