add support for humidity

This commit is contained in:
Nicu Hodos 2021-12-25 15:58:00 +01:00
parent da4bacd82f
commit 69cf0dae0d
5 changed files with 31 additions and 3 deletions

View File

@ -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);

View File

@ -1,7 +1,6 @@
#pragma once
#include <TinySensor.h>
#include <RCSwitch.h>
class ContactSensor: public TinySensor {
SensorType sensorType = CONTACT;

View File

@ -0,0 +1,20 @@
#pragma once
#include <TinySensor.h>
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));
}
};

View File

@ -1,7 +1,6 @@
#pragma once
#include <TinySensor.h>
#include <RCSwitch.h>
class TempSensor : public TinySensor {
SensorType sensorType = TEMPERATURE;

View File

@ -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
};