mirror of
https://github.com/xoseperez/espurna.git
synced 2026-03-21 23:57:06 +01:00
- shrink utils source file, move heartbeat and boot management into system - improvise with 'heartbeat' functionality. include scheduler implementation that will manage the per-module heartbeat callbacks with individual 'mode' and 'interval' settings. current ones are mqtt (including relays, lights, thermostat), debug and influxdb. preserve heartbeat NONE, ONCE and REPEAT, REPEAT_STATUS is effectively a hbReport & status bit. - mqtt heartbeat is managed through mqttHeartbeat() callbacks - tweak mqtt callbacks to use lists instead of the vector, slighly reducing the size of the .bin - update WebUI, include report setting and update hbMode values - make sure general.h settings include new heartbeat, move constant definitions outside of the header - correctly include dependencies through the .cpp, avoid leaking internal details. - as a side-effect, base headers are no longer included recursively
70 lines
1.7 KiB
C++
70 lines
1.7 KiB
C++
/*
|
|
|
|
Part of MQTT and API modules
|
|
|
|
Copyright (C) 2020 by Maxim Prokhorov <prokhorov dot max at outlook dot com>
|
|
|
|
*/
|
|
|
|
#include "rpc.h"
|
|
|
|
#include <Schedule.h>
|
|
#include <cstring>
|
|
|
|
#include "system.h"
|
|
#include "utils.h"
|
|
|
|
BrokerBind(StatusBroker);
|
|
|
|
bool rpcHandleAction(const String& action) {
|
|
bool result = false;
|
|
if (action.equals("reboot")) {
|
|
result = true;
|
|
schedule_function([]() {
|
|
deferredReset(100, CustomResetReason::Rpc);
|
|
});
|
|
} else if (action.equals("heartbeat")) {
|
|
result = true;
|
|
systemScheduleHeartbeat();
|
|
}
|
|
return result;
|
|
}
|
|
|
|
PayloadStatus rpcParsePayload(const char* payload, const rpc_payload_check_t ext_check) {
|
|
|
|
// Don't parse empty strings
|
|
const auto len = strlen(payload);
|
|
if (!len) return PayloadStatus::Unknown;
|
|
|
|
// Check most commonly used payloads
|
|
if (len == 1) {
|
|
if (payload[0] == '0') return PayloadStatus::Off;
|
|
if (payload[0] == '1') return PayloadStatus::On;
|
|
if (payload[0] == '2') return PayloadStatus::Toggle;
|
|
return PayloadStatus::Unknown;
|
|
}
|
|
|
|
// If possible, use externally provided payload checker
|
|
if (ext_check) {
|
|
const PayloadStatus result = ext_check(payload);
|
|
if (result != PayloadStatus::Unknown) {
|
|
return result;
|
|
}
|
|
}
|
|
|
|
// Finally, check for "OFF", "ON", "TOGGLE" (both lower and upper cases)
|
|
String temp(payload);
|
|
temp.trim();
|
|
|
|
if (temp.equalsIgnoreCase("off")) {
|
|
return PayloadStatus::Off;
|
|
} else if (temp.equalsIgnoreCase("on")) {
|
|
return PayloadStatus::On;
|
|
} else if (temp.equalsIgnoreCase("toggle")) {
|
|
return PayloadStatus::Toggle;
|
|
}
|
|
|
|
return PayloadStatus::Unknown;
|
|
|
|
}
|