Merge remote-tracking branch 'origin/pro-develop' into pro-develop
This commit is contained in:
@@ -78,27 +78,28 @@ namespace commands
|
||||
ArduinoJson::JsonDocument response;
|
||||
response["cmd"] = "setCronJob";
|
||||
|
||||
const auto &jobName = params["name"].as<std::string>();
|
||||
const auto &eventName = params["name"].as<std::string>();
|
||||
const auto &timeStr = params["cronExpr"].as<std::string>();
|
||||
const auto &actionStr = params["action"].as<std::string>();
|
||||
response["values"]["name"] = eventName;
|
||||
|
||||
ArduinoJson::JsonDocument action;
|
||||
if (ArduinoJson::deserializeJson(action, actionStr) != ArduinoJson::DeserializationError::Ok)
|
||||
{
|
||||
LOG_ERROR("setCronJob unable to deserialize cron job [", actionStr.c_str(), "]");
|
||||
response["value"]["status"] = "invalid";
|
||||
response["values"]["status"] = "invalid";
|
||||
return response;
|
||||
}
|
||||
|
||||
auto &cron = Cron::getInstance(dev);
|
||||
if (!cron.addEvent(jobName, timeStr, action))
|
||||
if (!cron.addEvent(eventName, timeStr, action))
|
||||
{
|
||||
LOG_ERROR("setCronJob unable to add job [", actionStr.c_str(), "]");
|
||||
response["value"]["status"] = "invalid";
|
||||
response["values"]["status"] = "invalid";
|
||||
return response;
|
||||
}
|
||||
LOG_INFO("setCronJob added job [", actionStr.c_str(), "]");
|
||||
response["value"]["status"] = "valid";
|
||||
response["values"]["status"] = "valid";
|
||||
return response;
|
||||
}
|
||||
const ArduinoJson::JsonDocument Commands::getCronJob(const devices_t &dev, const ArduinoJson::JsonDocument ¶ms)
|
||||
@@ -107,6 +108,7 @@ namespace commands
|
||||
response["cmd"] = "getCronJob";
|
||||
auto &cron = Cron::getInstance(dev);
|
||||
auto eventName = params["name"].as<std::string>();
|
||||
response["values"]["name"] = eventName;
|
||||
|
||||
if (eventName.empty())
|
||||
{
|
||||
@@ -144,7 +146,6 @@ namespace commands
|
||||
ArduinoJson::JsonDocument action;
|
||||
action["cmd"] = cmd;
|
||||
action["params"] = cmdParams;
|
||||
response["values"]["name"] = eventName;
|
||||
response["values"]["cronExpr"] = cron::to_cronstr(cronExpr);
|
||||
response["values"]["action"] = action;
|
||||
|
||||
@@ -157,6 +158,7 @@ namespace commands
|
||||
response["cmd"] = "delCronJob";
|
||||
auto &cron = Cron::getInstance(dev);
|
||||
auto eventName = params["name"].as<std::string>();
|
||||
response["values"]["name"] = eventName;
|
||||
if (eventName.empty() || !cron.delEvent(eventName))
|
||||
{
|
||||
LOG_ERROR("delCronJob failed to delete job [", eventName.c_str(), "]");
|
||||
@@ -189,20 +191,18 @@ namespace commands
|
||||
const ArduinoJson::JsonDocument Commands::setHPlimit(const devices_t &dev, const ArduinoJson::JsonDocument ¶ms)
|
||||
{
|
||||
ArduinoJson::JsonDocument response;
|
||||
{
|
||||
std::string msg;
|
||||
serializeJson(params, msg);
|
||||
LOG_INFO("setHPlimit params ->", msg.c_str());
|
||||
};
|
||||
response["cmd"] = "setHPlimit";
|
||||
if (!params["level"].is<std::string>())
|
||||
{
|
||||
LOG_ERROR("setHPlimit incorrect parameters");
|
||||
return response;
|
||||
}
|
||||
const auto level = params["level"].as<std::string>();
|
||||
response["values"]["level"] = level;
|
||||
if (!c_hpLimitsMap.contains(level))
|
||||
{
|
||||
LOG_ERROR("setHPlimit invalid level", level.c_str());
|
||||
response["values"]["status"] = "invalid";
|
||||
return response;
|
||||
}
|
||||
for (const auto [lvl, ro] : c_hpLimitsMap)
|
||||
@@ -213,17 +213,14 @@ namespace commands
|
||||
dev.io.digitalOutWrite(ro, false);
|
||||
}
|
||||
LOG_INFO("setHPlimit -> level", level.c_str());
|
||||
response["values"]["status"] = "valid";
|
||||
return response;
|
||||
}
|
||||
|
||||
const ArduinoJson::JsonDocument Commands::setHeating(const devices_t &dev, const ArduinoJson::JsonDocument ¶ms)
|
||||
{
|
||||
ArduinoJson::JsonDocument response;
|
||||
{
|
||||
std::string msg;
|
||||
serializeJson(params, msg);
|
||||
LOG_INFO("setHeating params ->", msg.c_str());
|
||||
};
|
||||
response["cmd"] = "setHeating";
|
||||
if (params.isNull())
|
||||
{
|
||||
LOG_ERROR("setHeating incorrect paramaters");
|
||||
@@ -236,15 +233,20 @@ namespace commands
|
||||
if (params[lvl] == "ON")
|
||||
{
|
||||
dev.io.digitalOutWrite(ro, true);
|
||||
response["values"][lvl] = "ON";
|
||||
LOG_INFO("setHeating -> ", lvl.c_str(), "ON");
|
||||
}
|
||||
else if (params[lvl] == "OFF")
|
||||
{
|
||||
dev.io.digitalOutWrite(ro, false);
|
||||
response["values"][lvl] = "OFF";
|
||||
LOG_INFO("setHeating -> ", lvl.c_str(), "OFF");
|
||||
}
|
||||
else
|
||||
{
|
||||
response["values"][lvl] = "invalid";
|
||||
LOG_ERROR("setHeating invalid valve state");
|
||||
}
|
||||
}
|
||||
return response;
|
||||
}
|
||||
@@ -277,11 +279,6 @@ namespace commands
|
||||
{
|
||||
ArduinoJson::JsonDocument response;
|
||||
auto &conf = Config::getInstance();
|
||||
{
|
||||
std::string msg;
|
||||
serializeJson(params, msg);
|
||||
LOG_INFO("setIrrigation params ->", msg.c_str());
|
||||
};
|
||||
response["cmd"] = "setIrrigation";
|
||||
if (params.isNull())
|
||||
{
|
||||
@@ -292,6 +289,8 @@ namespace commands
|
||||
const uint16_t tOn(params["timeOn"].as<uint16_t>());
|
||||
const uint16_t tPause(params["timePause"].as<uint16_t>());
|
||||
|
||||
response["values"]["zone"] = zone;
|
||||
|
||||
if (zone == "stop")
|
||||
{ // stop all zones and reset timers
|
||||
LOG_INFO("setIrrigation stop all zones");
|
||||
@@ -321,6 +320,8 @@ namespace commands
|
||||
return response;
|
||||
}
|
||||
|
||||
response["values"]["timeOn"] = tOn;
|
||||
response["values"]["timePause"] = tPause;
|
||||
if (!c_irrigationValveMap.contains(zone) || tOn <= 0 || tPause <= 0) // verify if zone is a valid map key
|
||||
{
|
||||
LOG_ERROR("setIrrigation incorrect zone[", zone.c_str(), "] or time values tOn[", tOn, "] tPause[", tPause, "]");
|
||||
@@ -366,7 +367,7 @@ namespace commands
|
||||
dev.io.digitalOutWrite(zoneIoNumber, true);
|
||||
xTimerStart(shTimer, 0);
|
||||
timerHandle = shTimer;
|
||||
response["values"]["status"] = "ok";
|
||||
response["values"]["status"] = "valid";
|
||||
LOG_INFO("setIrrigation zone [", timerName, "] tOn[", tOn, "] tPause[", tPause, "]");
|
||||
}
|
||||
return response;
|
||||
@@ -387,15 +388,13 @@ namespace commands
|
||||
|
||||
if (!rtcOk || !ntpOk)
|
||||
{
|
||||
response["values"]["status"] = "unable to get time";
|
||||
response["values"]["status"] = "invalid";
|
||||
return response;
|
||||
}
|
||||
|
||||
response["values"]["status"] = "valid";
|
||||
response["values"]["time"] = rtc.getTimeStr();
|
||||
|
||||
LOG_INFO("setTimeNTP -> RTC is [", response["status"]["time"].as<std::string>().c_str(), "]");
|
||||
|
||||
return response;
|
||||
}
|
||||
// SETTERS //
|
||||
@@ -482,7 +481,7 @@ namespace commands
|
||||
|
||||
if (!rtcOk || !ntpOk)
|
||||
{
|
||||
response["values"]["status"] = "unable to get time";
|
||||
response["values"]["status"] = "invalid";
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -492,7 +491,8 @@ namespace commands
|
||||
auto timeDiff = std::chrono::duration_cast<std::chrono::seconds>(ntpTimePoint - rtcTimePoint);
|
||||
auto direction = timeDiff.count() >= 0 ? "BEYOND" : "AHEAD";
|
||||
|
||||
response["values"]["drift"] = (int32_t)timeDiff.count();
|
||||
response["values"]["status"] = "valid";
|
||||
response["values"]["drift"] = (uint32_t)timeDiff.count();
|
||||
response["values"]["direction"] = "RTC is [" + std::string(direction) + "] NTP time";
|
||||
|
||||
LOG_INFO("getTimeDrift -> RTC is [", (int32_t)timeDiff.count(), "] sec, [", std::string(direction).c_str(), "] NTP time");
|
||||
|
||||
Reference in New Issue
Block a user