don't send 0 voltage
This commit is contained in:
parent
0cd557f4d5
commit
4b5c6b930f
@ -43,6 +43,36 @@ void loop() {
|
||||
}
|
||||
}
|
||||
|
||||
bool buildSensorJson(JsonDocument& jsonDoc, unsigned long value) {
|
||||
jsonDoc["id"] = ID(value);
|
||||
|
||||
JsonObject sensor = jsonDoc.createNestedObject("sensor");
|
||||
|
||||
float voltage = GET_VCC(value);
|
||||
if (voltage != 0) {
|
||||
sensor["voltage"] = voltage;
|
||||
}
|
||||
|
||||
switch (GET_TYPE(value)) {
|
||||
case SensorType::GENERIC:
|
||||
sensor["value"] = GET_VALUE(value);
|
||||
break;
|
||||
case SensorType::TEMPERATURE:
|
||||
sensor["temperature"] = GET_TEMP(value);
|
||||
break;
|
||||
case SensorType::HUMIDITY:
|
||||
sensor["humidity"] = GET_HUMIDITY(value);
|
||||
break;
|
||||
case SensorType::CONTACT:
|
||||
sensor["state"] = GET_STATE(value) ? "on" : "off";
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void readRcSwitch(JsonDocument& jsonDoc) {
|
||||
if (mySwitch.available()) {
|
||||
unsigned long value = mySwitch.getReceivedValue();
|
||||
@ -59,32 +89,7 @@ void readRcSwitch(JsonDocument& jsonDoc) {
|
||||
motion["basement"] = value == 1879048230L ? "on" : "off";
|
||||
return;
|
||||
}
|
||||
if (GET_TYPE(value) == SensorType::GENERIC) {
|
||||
JsonObject sensor = jsonDoc.createNestedObject("sensor");
|
||||
jsonDoc["id"] = ID(value);
|
||||
sensor["value"] = GET_VALUE(value);
|
||||
sensor["voltage"] = GET_VCC(value);
|
||||
return;
|
||||
}
|
||||
if (GET_TYPE(value) == SensorType::TEMPERATURE) {
|
||||
JsonObject sensor = jsonDoc.createNestedObject("sensor");
|
||||
jsonDoc["id"] = ID(value);
|
||||
sensor["temperature"] = GET_TEMP(value);
|
||||
sensor["voltage"] = GET_VCC(value);
|
||||
return;
|
||||
}
|
||||
if (GET_TYPE(value) == SensorType::HUMIDITY) {
|
||||
JsonObject sensor = jsonDoc.createNestedObject("sensor");
|
||||
jsonDoc["id"] = ID(value);
|
||||
sensor["humidity"] = GET_HUMIDITY(value);
|
||||
sensor["voltage"] = GET_VCC(value);
|
||||
return;
|
||||
}
|
||||
if (GET_TYPE(value) == SensorType::CONTACT) {
|
||||
JsonObject sensor = jsonDoc.createNestedObject("contact");
|
||||
jsonDoc["id"] = ID(value);
|
||||
sensor["state"] = GET_STATE(value) ? "on" : "off";
|
||||
sensor["voltage"] = GET_VCC(value);
|
||||
if (buildSensorJson(jsonDoc, value)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user