gateway: adapt it to publish sensors on MQTT #1

Merged
nicu merged 5 commits from gateway into master 2022-10-13 20:28:48 +02:00
Showing only changes of commit 8e7c9d336d - Show all commits

View File

@ -61,28 +61,28 @@ void readRcSwitch(JsonDocument& jsonDoc) {
} }
if (GET_TYPE(value) == SensorType::GENERIC) { if (GET_TYPE(value) == SensorType::GENERIC) {
JsonObject sensor = jsonDoc.createNestedObject("sensor"); JsonObject sensor = jsonDoc.createNestedObject("sensor");
sensor["id"] = ID(value); jsonDoc["id"] = ID(value);
sensor["value"] = GET_VALUE(value); sensor["value"] = GET_VALUE(value);
sensor["voltage"] = GET_VCC(value); sensor["voltage"] = GET_VCC(value);
return; return;
} }
if (GET_TYPE(value) == SensorType::TEMPERATURE) { if (GET_TYPE(value) == SensorType::TEMPERATURE) {
JsonObject sensor = jsonDoc.createNestedObject("sensor"); JsonObject sensor = jsonDoc.createNestedObject("sensor");
sensor["id"] = ID(value); jsonDoc["id"] = ID(value);
sensor["temperature"] = GET_TEMP(value); sensor["temperature"] = GET_TEMP(value);
sensor["voltage"] = GET_VCC(value); sensor["voltage"] = GET_VCC(value);
return; return;
} }
if (GET_TYPE(value) == SensorType::HUMIDITY) { if (GET_TYPE(value) == SensorType::HUMIDITY) {
JsonObject sensor = jsonDoc.createNestedObject("sensor"); JsonObject sensor = jsonDoc.createNestedObject("sensor");
sensor["id"] = ID(value); jsonDoc["id"] = ID(value);
sensor["humidity"] = GET_HUMIDITY(value); sensor["humidity"] = GET_HUMIDITY(value);
sensor["voltage"] = GET_VCC(value); sensor["voltage"] = GET_VCC(value);
return; return;
} }
if (GET_TYPE(value) == SensorType::CONTACT) { if (GET_TYPE(value) == SensorType::CONTACT) {
JsonObject sensor = jsonDoc.createNestedObject("contact"); JsonObject sensor = jsonDoc.createNestedObject("contact");
sensor["id"] = ID(value); jsonDoc["id"] = ID(value);
sensor["state"] = GET_STATE(value) ? "on" : "off"; sensor["state"] = GET_STATE(value) ? "on" : "off";
sensor["voltage"] = GET_VCC(value); sensor["voltage"] = GET_VCC(value);
return; return;