diff --git a/gateway/src/gateway.cpp b/gateway/src/gateway.cpp index c2a6bae..9fcba96 100644 --- a/gateway/src/gateway.cpp +++ b/gateway/src/gateway.cpp @@ -72,6 +72,13 @@ void readRcSwitch(JsonDocument& jsonDoc) { sensor["voltage"] = GET_VCC(value); return; } + if (GET_TYPE(value) == SensorType::HUMIDITY) { + JsonObject sensor = jsonDoc.createNestedObject("sensor"); + sensor["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"); sensor["id"] = ID(value); diff --git a/libraries/Tiny/ContactSensor.h b/libraries/Tiny/ContactSensor.h index c6fdf5b..367e5a5 100644 --- a/libraries/Tiny/ContactSensor.h +++ b/libraries/Tiny/ContactSensor.h @@ -1,7 +1,6 @@ #pragma once #include -#include class ContactSensor: public TinySensor { SensorType sensorType = CONTACT; diff --git a/libraries/Tiny/HumiditySensor.h b/libraries/Tiny/HumiditySensor.h new file mode 100644 index 0000000..24dd903 --- /dev/null +++ b/libraries/Tiny/HumiditySensor.h @@ -0,0 +1,20 @@ +#pragma once + +#include + +class HumiditySensor : public TinySensor { + SensorType sensorType = HUMIDITY; + +public: + HumiditySensor(short id, short senderPin) : + TinySensor(id, senderPin) { + } + + void sendHumidityAndVoltage(int humidity) { + sendInfo(ID(id) | VCC(readVcc()) | HUMIDITY(humidity) | TYPE(sensorType)); + } + + void sendHumidity(int humidity) { + sendInfo(ID(id) | HUMIDITY(humidity) | TYPE(sensorType)); + } +}; diff --git a/libraries/Tiny/TempSensor.h b/libraries/Tiny/TempSensor.h index 0120ac5..86cc2fd 100644 --- a/libraries/Tiny/TempSensor.h +++ b/libraries/Tiny/TempSensor.h @@ -1,7 +1,6 @@ #pragma once #include -#include class TempSensor : public TinySensor { SensorType sensorType = TEMPERATURE; diff --git a/libraries/Tiny/Tiny.h b/libraries/Tiny/Tiny.h index c644c75..ad7dcca 100644 --- a/libraries/Tiny/Tiny.h +++ b/libraries/Tiny/Tiny.h @@ -4,14 +4,17 @@ #define STATE(value) ((value & 0x1) << 5) #define VCC(value) ((value & 0x1FFF) << 6) #define TEMP(value) (((unsigned long)value & 0x1FF) << 19) +#define HUMIDITY(value) (((unsigned long)value & 0x7F) << 19) #define TYPE(value) (((unsigned long)value & 0xF) << 28) #define GET_TYPE(value) (((unsigned long)value >> 28) & 0xF) #define GET_TEMP(value) (((unsigned long)value >> 19) & 0x1FF) +#define GET_HUMIDITY(value) (((unsigned long)value >> 19) & 0x7F) #define GET_VCC(value) ((value >> 6) & 0x1FFF) #define GET_STATE(value) ((value >> 5) & 0x1) -typedef enum SensorType { +enum SensorType { + HUMIDITY = 5, TEMPERATURE = 6, CONTACT = 7 };