mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-29 06:06:40 +00:00
Allow json payload for antiburn #134
This commit is contained in:
parent
e65d9bc77a
commit
f32a222936
@ -960,32 +960,29 @@ void dispatch_antiburn(const char*, const char* payload, uint8_t source)
|
|||||||
|
|
||||||
size_t maxsize = (128u * ((strlen(payload) / 128) + 1)) + 128;
|
size_t maxsize = (128u * ((strlen(payload) / 128) + 1)) + 128;
|
||||||
DynamicJsonDocument json(maxsize);
|
DynamicJsonDocument json(maxsize);
|
||||||
bool state = false;
|
|
||||||
|
|
||||||
// Note: Deserialization needs to be (const char *) so the objects WILL be copied
|
// Note: Deserialization needs to be (const char *) so the objects WILL be copied
|
||||||
// this uses more memory but otherwise the mqtt receive buffer can get overwritten by the send buffer !!
|
// this uses more memory but otherwise the mqtt receive buffer can get overwritten by the send buffer !!
|
||||||
DeserializationError jsonError = deserializeJson(json, payload);
|
DeserializationError jsonError = deserializeJson(json, payload);
|
||||||
json.shrinkToFit();
|
json.shrinkToFit();
|
||||||
|
bool state = false;
|
||||||
|
|
||||||
if(jsonError) { // Couldn't parse incoming payload as json
|
if(jsonError) { // Couldn't parse incoming payload as json
|
||||||
state = Parser::is_true(payload);
|
state = Parser::is_true(payload);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
if(json.is<uint8_t>()) { // plain numbers are parsed as valid json object
|
||||||
// plain numbers are parsed as valid json object
|
|
||||||
if(json.is<uint8_t>()) {
|
|
||||||
state = json.as<uint8_t>();
|
state = json.as<uint8_t>();
|
||||||
|
|
||||||
// true and false are parsed as valid json object
|
} else if(json.is<bool>()) { // true and false are parsed as valid json object
|
||||||
} else if(json.is<bool>()) {
|
|
||||||
state = json.as<bool>();
|
state = json.as<bool>();
|
||||||
|
|
||||||
} else {
|
} else { // other text
|
||||||
if(!json[F("state")].isNull()) state = Parser::is_true(json[F("state")].as<std::string>().c_str());
|
JsonVariant key = json[F("state")];
|
||||||
|
if(!key.isNull()) state = Parser::is_true(key.as<std::string>().c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hasp_set_antiburn(state ? 30 : 0, 1000); // ON = 25 cycles of 1000 milli seconds (i.e. 25 sec)
|
hasp_set_antiburn(state ? 30 : 0, 1000); // ON = 30 cycles of 1000 milli seconds (i.e. 30 sec)
|
||||||
}
|
}
|
||||||
|
|
||||||
// restart the device
|
// restart the device
|
||||||
|
Loading…
x
Reference in New Issue
Block a user