mirror of
https://github.com/Laxilef/OTGateway.git
synced 2026-02-28 04:07:07 +05:00
feat: added support DHT11/DHT22 sensors (#223)
* feat: Added support DHT11/DHT22 sensors * chore: formatting * fix: typo * fix: `HaHelper::publishDynamicSensor()` for DHT sensors fixed * refactor: optimization of wired sensors
This commit is contained in:
@@ -4,7 +4,7 @@ extra_configs = secrets.default.ini
|
|||||||
core_dir = .pio
|
core_dir = .pio
|
||||||
|
|
||||||
[env]
|
[env]
|
||||||
version = 1.6.0-async
|
version = 1.6.0-async-dht
|
||||||
framework = arduino
|
framework = arduino
|
||||||
lib_deps = ESP32Async/AsyncTCP@^3.4.10
|
lib_deps = ESP32Async/AsyncTCP@^3.4.10
|
||||||
ESP32Async/ESPAsyncWebServer@^3.9.4
|
ESP32Async/ESPAsyncWebServer@^3.9.4
|
||||||
@@ -18,6 +18,7 @@ lib_deps = ESP32Async/AsyncTCP@^3.4.10
|
|||||||
gyverlibs/GyverBlinker@^1.1.1
|
gyverlibs/GyverBlinker@^1.1.1
|
||||||
pstolarz/OneWireNg@^0.14.1
|
pstolarz/OneWireNg@^0.14.1
|
||||||
milesburton/DallasTemperature@^4.0.6
|
milesburton/DallasTemperature@^4.0.6
|
||||||
|
https://github.com/Laxilef/esp32DHT#idf5
|
||||||
;laxilef/TinyLogger@^1.1.1
|
;laxilef/TinyLogger@^1.1.1
|
||||||
https://github.com/Laxilef/TinyLogger#custom_handlers
|
https://github.com/Laxilef/TinyLogger#custom_handlers
|
||||||
lib_ignore = OneWire
|
lib_ignore = OneWire
|
||||||
@@ -33,6 +34,7 @@ build_flags = ;-mtext-section-literals
|
|||||||
-D ARDUINOJSON_USE_DOUBLE=0
|
-D ARDUINOJSON_USE_DOUBLE=0
|
||||||
-D ARDUINOJSON_USE_LONG_LONG=0
|
-D ARDUINOJSON_USE_LONG_LONG=0
|
||||||
-D TINYLOGGER_GLOBAL
|
-D TINYLOGGER_GLOBAL
|
||||||
|
-D DHT_TASK_STACK_SIZE=4096
|
||||||
-D DEFAULT_SERIAL_ENABLED=${secrets.serial_enabled}
|
-D DEFAULT_SERIAL_ENABLED=${secrets.serial_enabled}
|
||||||
-D DEFAULT_SERIAL_BAUD=${secrets.serial_baud}
|
-D DEFAULT_SERIAL_BAUD=${secrets.serial_baud}
|
||||||
-D DEFAULT_WEBSERIAL_ENABLED=${secrets.webserial_enabled}
|
-D DEFAULT_WEBSERIAL_ENABLED=${secrets.webserial_enabled}
|
||||||
|
|||||||
@@ -176,9 +176,10 @@ public:
|
|||||||
objId.c_str()
|
objId.c_str()
|
||||||
);
|
);
|
||||||
|
|
||||||
// set device class, name, value template for bluetooth sensors
|
// set device class, name, value template for Bluetooth/DHT sensors
|
||||||
// or name & value template for another sensors
|
// or name & value template for another sensors
|
||||||
if (sSensor.type == Sensors::Type::BLUETOOTH) {
|
if (sSensor.type == Sensors::Type::BLUETOOTH ||
|
||||||
|
sSensor.type == Sensors::Type::DHT11 || sSensor.type == Sensors::Type::DHT22) {
|
||||||
// available state topic
|
// available state topic
|
||||||
doc[FPSTR(HA_AVAILABILITY)][1][FPSTR(HA_TOPIC)] = doc[FPSTR(HA_STATE_TOPIC)];
|
doc[FPSTR(HA_AVAILABILITY)][1][FPSTR(HA_TOPIC)] = doc[FPSTR(HA_STATE_TOPIC)];
|
||||||
doc[FPSTR(HA_AVAILABILITY)][1][FPSTR(HA_VALUE_TEMPLATE)] = JsonString(AVAILABILITY_SENSOR_CONN, true);
|
doc[FPSTR(HA_AVAILABILITY)][1][FPSTR(HA_VALUE_TEMPLATE)] = JsonString(AVAILABILITY_SENSOR_CONN, true);
|
||||||
|
|||||||
@@ -292,6 +292,14 @@ protected:
|
|||||||
this->haHelper->deleteDynamicSensor(prevSettings, Sensors::ValueType::RSSI);
|
this->haHelper->deleteDynamicSensor(prevSettings, Sensors::ValueType::RSSI);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Sensors::Type::DHT11:
|
||||||
|
case Sensors::Type::DHT22:
|
||||||
|
this->haHelper->deleteConnectionDynamicSensor(prevSettings);
|
||||||
|
this->haHelper->deleteSignalQualityDynamicSensor(prevSettings);
|
||||||
|
this->haHelper->deleteDynamicSensor(prevSettings, Sensors::ValueType::TEMPERATURE);
|
||||||
|
this->haHelper->deleteDynamicSensor(prevSettings, Sensors::ValueType::HUMIDITY);
|
||||||
|
break;
|
||||||
|
|
||||||
case Sensors::Type::DALLAS_TEMP:
|
case Sensors::Type::DALLAS_TEMP:
|
||||||
this->haHelper->deleteConnectionDynamicSensor(prevSettings);
|
this->haHelper->deleteConnectionDynamicSensor(prevSettings);
|
||||||
this->haHelper->deleteSignalQualityDynamicSensor(prevSettings);
|
this->haHelper->deleteSignalQualityDynamicSensor(prevSettings);
|
||||||
@@ -319,6 +327,14 @@ protected:
|
|||||||
this->haHelper->publishDynamicSensor(sSettings, Sensors::ValueType::RSSI, settings.system.unitSystem, false);
|
this->haHelper->publishDynamicSensor(sSettings, Sensors::ValueType::RSSI, settings.system.unitSystem, false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Sensors::Type::DHT11:
|
||||||
|
case Sensors::Type::DHT22:
|
||||||
|
this->haHelper->publishConnectionDynamicSensor(sSettings);
|
||||||
|
this->haHelper->publishSignalQualityDynamicSensor(sSettings, false);
|
||||||
|
this->haHelper->publishDynamicSensor(sSettings, Sensors::ValueType::TEMPERATURE, settings.system.unitSystem);
|
||||||
|
this->haHelper->publishDynamicSensor(sSettings, Sensors::ValueType::HUMIDITY, settings.system.unitSystem);
|
||||||
|
break;
|
||||||
|
|
||||||
case Sensors::Type::DALLAS_TEMP:
|
case Sensors::Type::DALLAS_TEMP:
|
||||||
this->haHelper->publishConnectionDynamicSensor(sSettings);
|
this->haHelper->publishConnectionDynamicSensor(sSettings);
|
||||||
this->haHelper->publishSignalQualityDynamicSensor(sSettings, false);
|
this->haHelper->publishSignalQualityDynamicSensor(sSettings, false);
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ public:
|
|||||||
NTC_10K_TEMP = 50,
|
NTC_10K_TEMP = 50,
|
||||||
DALLAS_TEMP = 51,
|
DALLAS_TEMP = 51,
|
||||||
BLUETOOTH = 52,
|
BLUETOOTH = 52,
|
||||||
|
DHT11 = 53,
|
||||||
|
DHT22 = 54,
|
||||||
|
|
||||||
HEATING_SETPOINT_TEMP = 253,
|
HEATING_SETPOINT_TEMP = 253,
|
||||||
MANUAL = 254,
|
MANUAL = 254,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <OneWire.h>
|
#include <OneWire.h>
|
||||||
#include <DallasTemperature.h>
|
#include <DallasTemperature.h>
|
||||||
|
#include <esp32DHT.h>
|
||||||
|
|
||||||
#if USE_BLE
|
#if USE_BLE
|
||||||
#include <NimBLEDevice.h>
|
#include <NimBLEDevice.h>
|
||||||
@@ -50,19 +51,23 @@ protected:
|
|||||||
class SensorsTask : public LeanTask {
|
class SensorsTask : public LeanTask {
|
||||||
public:
|
public:
|
||||||
SensorsTask(bool _enabled = false, unsigned long _interval = 0) : LeanTask(_enabled, _interval) {
|
SensorsTask(bool _enabled = false, unsigned long _interval = 0) : LeanTask(_enabled, _interval) {
|
||||||
|
this->gpioLastPollingTime.reserve(2);
|
||||||
|
|
||||||
|
// OneWire
|
||||||
this->owInstances.reserve(2);
|
this->owInstances.reserve(2);
|
||||||
this->dallasInstances.reserve(2);
|
this->dallasInstances.reserve(2);
|
||||||
this->dallasSearchTime.reserve(2);
|
this->dallasSearchTime.reserve(2);
|
||||||
this->dallasPolling.reserve(2);
|
this->dallasPolling.reserve(2);
|
||||||
this->dallasLastPollingTime.reserve(2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~SensorsTask() {
|
~SensorsTask() {
|
||||||
|
this->gpioLastPollingTime.clear();
|
||||||
|
|
||||||
|
// OneWire
|
||||||
this->dallasInstances.clear();
|
this->dallasInstances.clear();
|
||||||
this->owInstances.clear();
|
this->owInstances.clear();
|
||||||
this->dallasSearchTime.clear();
|
this->dallasSearchTime.clear();
|
||||||
this->dallasPolling.clear();
|
this->dallasPolling.clear();
|
||||||
this->dallasLastPollingTime.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -70,17 +75,26 @@ protected:
|
|||||||
const unsigned int wirelessDisconnectTimeout = 600000u;
|
const unsigned int wirelessDisconnectTimeout = 600000u;
|
||||||
const unsigned short dallasSearchInterval = 60000;
|
const unsigned short dallasSearchInterval = 60000;
|
||||||
const unsigned short dallasPollingInterval = 10000;
|
const unsigned short dallasPollingInterval = 10000;
|
||||||
|
const unsigned short dhtPollingInterval = 15000;
|
||||||
const unsigned short globalPollingInterval = 15000;
|
const unsigned short globalPollingInterval = 15000;
|
||||||
#if USE_BLE
|
#if USE_BLE
|
||||||
const unsigned int bleSetDtInterval = 7200000;
|
const unsigned int bleSetDtInterval = 7200000;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
std::unordered_map<uint8_t, unsigned long> gpioLastPollingTime;
|
||||||
|
|
||||||
|
// OneWire
|
||||||
std::unordered_map<uint8_t, OneWire> owInstances;
|
std::unordered_map<uint8_t, OneWire> owInstances;
|
||||||
std::unordered_map<uint8_t, DallasTemperature> dallasInstances;
|
std::unordered_map<uint8_t, DallasTemperature> dallasInstances;
|
||||||
std::unordered_map<uint8_t, unsigned long> dallasSearchTime;
|
std::unordered_map<uint8_t, unsigned long> dallasSearchTime;
|
||||||
std::unordered_map<uint8_t, bool> dallasPolling;
|
std::unordered_map<uint8_t, bool> dallasPolling;
|
||||||
std::unordered_map<uint8_t, unsigned long> dallasLastPollingTime;
|
|
||||||
|
// DHT
|
||||||
|
DHT dhtInstance;
|
||||||
|
bool dhtIsPolling = false;
|
||||||
|
|
||||||
#if USE_BLE
|
#if USE_BLE
|
||||||
|
// Bluetooth
|
||||||
std::unordered_map<uint8_t, NimBLEClient*> bleClients;
|
std::unordered_map<uint8_t, NimBLEClient*> bleClients;
|
||||||
std::unordered_map<uint8_t, bool> bleSubscribed;
|
std::unordered_map<uint8_t, bool> bleSubscribed;
|
||||||
std::unordered_map<uint8_t, unsigned long> bleLastSetDtTime;
|
std::unordered_map<uint8_t, unsigned long> bleLastSetDtTime;
|
||||||
@@ -116,6 +130,9 @@ protected:
|
|||||||
this->yield();
|
this->yield();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pollingDhtSensors();
|
||||||
|
this->yield();
|
||||||
|
|
||||||
if (millis() - this->globalLastPollingTime > this->globalPollingInterval) {
|
if (millis() - this->globalLastPollingTime > this->globalPollingInterval) {
|
||||||
cleanDallasInstances();
|
cleanDallasInstances();
|
||||||
makeDallasInstances();
|
makeDallasInstances();
|
||||||
@@ -173,7 +190,7 @@ protected:
|
|||||||
|
|
||||||
this->dallasSearchTime[sSensor.gpio] = 0;
|
this->dallasSearchTime[sSensor.gpio] = 0;
|
||||||
this->dallasPolling[sSensor.gpio] = false;
|
this->dallasPolling[sSensor.gpio] = false;
|
||||||
this->dallasLastPollingTime[sSensor.gpio] = 0;
|
this->gpioLastPollingTime[sSensor.gpio] = 0;
|
||||||
|
|
||||||
auto& instance = this->dallasInstances[sSensor.gpio];
|
auto& instance = this->dallasInstances[sSensor.gpio];
|
||||||
instance.setOneWire(&owInstance);
|
instance.setOneWire(&owInstance);
|
||||||
@@ -208,7 +225,7 @@ protected:
|
|||||||
this->owInstances.erase(gpio);
|
this->owInstances.erase(gpio);
|
||||||
this->dallasSearchTime.erase(gpio);
|
this->dallasSearchTime.erase(gpio);
|
||||||
this->dallasPolling.erase(gpio);
|
this->dallasPolling.erase(gpio);
|
||||||
this->dallasLastPollingTime.erase(gpio);
|
this->gpioLastPollingTime.erase(gpio);
|
||||||
|
|
||||||
Log.sinfoln(FPSTR(L_SENSORS_DALLAS), F("Stopped on GPIO %hhu"), gpio);
|
Log.sinfoln(FPSTR(L_SENSORS_DALLAS), F("Stopped on GPIO %hhu"), gpio);
|
||||||
continue;
|
continue;
|
||||||
@@ -329,7 +346,7 @@ protected:
|
|||||||
|
|
||||||
if (this->dallasPolling[gpio]) {
|
if (this->dallasPolling[gpio]) {
|
||||||
unsigned long minPollingTime = instance.millisToWaitForConversion(12) * 2;
|
unsigned long minPollingTime = instance.millisToWaitForConversion(12) * 2;
|
||||||
unsigned long estimatePollingTime = ts - this->dallasLastPollingTime[gpio];
|
unsigned long estimatePollingTime = ts - this->gpioLastPollingTime[gpio];
|
||||||
|
|
||||||
// check conversion time
|
// check conversion time
|
||||||
// isConversionComplete does not work with chinese clones!
|
// isConversionComplete does not work with chinese clones!
|
||||||
@@ -381,7 +398,7 @@ protected:
|
|||||||
this->dallasPolling[gpio] = false;
|
this->dallasPolling[gpio] = false;
|
||||||
|
|
||||||
} else if (newPolling) {
|
} else if (newPolling) {
|
||||||
auto estimateLastPollingTime = ts - this->dallasLastPollingTime[gpio];
|
auto estimateLastPollingTime = ts - this->gpioLastPollingTime[gpio];
|
||||||
|
|
||||||
// check last polling time
|
// check last polling time
|
||||||
if (estimateLastPollingTime < this->dallasPollingInterval) {
|
if (estimateLastPollingTime < this->dallasPollingInterval) {
|
||||||
@@ -392,13 +409,102 @@ protected:
|
|||||||
instance.setResolution(12);
|
instance.setResolution(12);
|
||||||
instance.requestTemperatures();
|
instance.requestTemperatures();
|
||||||
this->dallasPolling[gpio] = true;
|
this->dallasPolling[gpio] = true;
|
||||||
this->dallasLastPollingTime[gpio] = ts;
|
this->gpioLastPollingTime[gpio] = ts;
|
||||||
|
|
||||||
Log.straceln(FPSTR(L_SENSORS_DALLAS), F("GPIO %hhu, polling..."), gpio);
|
Log.straceln(FPSTR(L_SENSORS_DALLAS), F("GPIO %hhu, polling..."), gpio);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void pollingDhtSensors() {
|
||||||
|
if (this->dhtIsPolling) {
|
||||||
|
// busy
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (uint8_t sensorId = 0; sensorId <= Sensors::getMaxSensorId(); sensorId++) {
|
||||||
|
auto& sSensor = Sensors::settings[sensorId];
|
||||||
|
|
||||||
|
if (!sSensor.enabled || sSensor.purpose == Sensors::Purpose::NOT_CONFIGURED) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sSensor.type != Sensors::Type::DHT11 && sSensor.type != Sensors::Type::DHT22) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->gpioLastPollingTime.count(sSensor.gpio) && millis() - this->gpioLastPollingTime[sSensor.gpio] < this->dhtPollingInterval) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto sensorGpio = static_cast<gpio_num_t>(sSensor.gpio);
|
||||||
|
if (this->dhtInstance.getGpio() != sensorGpio) {
|
||||||
|
this->dhtInstance.reset();
|
||||||
|
this->dhtInstance.onData([this, sensorId](float humidity, float temperature) {
|
||||||
|
auto& sSensor = Sensors::settings[sensorId];
|
||||||
|
|
||||||
|
Log.straceln(
|
||||||
|
FPSTR(L_SENSORS_DHT), F("GPIO %hhu, sensor #%hhu '%s', temp: %.2f, humidity: %.2f%%"),
|
||||||
|
sSensor.gpio, sensorId, sSensor.name, temperature, humidity
|
||||||
|
);
|
||||||
|
|
||||||
|
// set temperature
|
||||||
|
Sensors::setValueById(sensorId, temperature, Sensors::ValueType::TEMPERATURE, true, true);
|
||||||
|
|
||||||
|
// set humidity
|
||||||
|
Sensors::setValueById(sensorId, humidity, Sensors::ValueType::HUMIDITY, true, true);
|
||||||
|
|
||||||
|
auto& rSensor = Sensors::results[sensorId];
|
||||||
|
if (rSensor.signalQuality < 100) {
|
||||||
|
rSensor.signalQuality++;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->gpioLastPollingTime[sSensor.gpio] = millis();
|
||||||
|
this->dhtIsPolling = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
this->dhtInstance.onError([this, sensorId](DHT::Status status) {
|
||||||
|
auto& sSensor = Sensors::settings[sensorId];
|
||||||
|
|
||||||
|
Log.swarningln(
|
||||||
|
FPSTR(L_SENSORS_DHT), F("GPIO %hhu, sensor #%hhu '%s': failed receiving data (err: %s)"),
|
||||||
|
sSensor.gpio, sensorId, sSensor.name, DHT::statusToString(this->dhtInstance.getStatus())
|
||||||
|
);
|
||||||
|
|
||||||
|
auto& rSensor = Sensors::results[sensorId];
|
||||||
|
if (rSensor.signalQuality > 0) {
|
||||||
|
rSensor.signalQuality--;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->gpioLastPollingTime[sSensor.gpio] = millis();
|
||||||
|
this->dhtIsPolling = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
DHT::Type sType = DHT::Type::DHT22;
|
||||||
|
if (sSensor.type == Sensors::Type::DHT11) {
|
||||||
|
sType = DHT::Type::DHT11;
|
||||||
|
|
||||||
|
} else if (sSensor.type == Sensors::Type::DHT22) {
|
||||||
|
sType = DHT::Type::DHT22;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->dhtInstance.setup(sensorGpio, sType)) {
|
||||||
|
Log.sinfoln(FPSTR(L_SENSORS_DHT), F("Started on GPIO %hhu"), sSensor.gpio);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
Log.swarningln(
|
||||||
|
FPSTR(L_SENSORS_DHT), F("Failed to start on GPIO %hhu (err: %s)"),
|
||||||
|
sSensor.gpio, DHT::statusToString(this->dhtInstance.getStatus())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this->dhtIsPolling = this->dhtInstance.poll();
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void pollingNtcSensors() {
|
void pollingNtcSensors() {
|
||||||
for (uint8_t sensorId = 0; sensorId <= Sensors::getMaxSensorId(); sensorId++) {
|
for (uint8_t sensorId = 0; sensorId <= Sensors::getMaxSensorId(); sensorId++) {
|
||||||
auto& sSensor = Sensors::settings[sensorId];
|
auto& sSensor = Sensors::settings[sensorId];
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ const char L_OT_CH2[] PROGMEM = "OT.CH2";
|
|||||||
const char L_SENSORS[] PROGMEM = "SENSORS";
|
const char L_SENSORS[] PROGMEM = "SENSORS";
|
||||||
const char L_SENSORS_SETTINGS[] PROGMEM = "SENSORS.SETTINGS";
|
const char L_SENSORS_SETTINGS[] PROGMEM = "SENSORS.SETTINGS";
|
||||||
const char L_SENSORS_DALLAS[] PROGMEM = "SENSORS.DALLAS";
|
const char L_SENSORS_DALLAS[] PROGMEM = "SENSORS.DALLAS";
|
||||||
|
const char L_SENSORS_DHT[] PROGMEM = "SENSORS.DHT";
|
||||||
const char L_SENSORS_NTC[] PROGMEM = "SENSORS.NTC";
|
const char L_SENSORS_NTC[] PROGMEM = "SENSORS.NTC";
|
||||||
const char L_SENSORS_BLE[] PROGMEM = "SENSORS.BLE";
|
const char L_SENSORS_BLE[] PROGMEM = "SENSORS.BLE";
|
||||||
const char L_REGULATOR[] PROGMEM = "REGULATOR";
|
const char L_REGULATOR[] PROGMEM = "REGULATOR";
|
||||||
|
|||||||
@@ -1927,6 +1927,8 @@ bool jsonToSensorSettings(const uint8_t sensorId, const JsonVariantConst src, Se
|
|||||||
case static_cast<uint8_t>(Sensors::Type::NTC_10K_TEMP):
|
case static_cast<uint8_t>(Sensors::Type::NTC_10K_TEMP):
|
||||||
case static_cast<uint8_t>(Sensors::Type::DALLAS_TEMP):
|
case static_cast<uint8_t>(Sensors::Type::DALLAS_TEMP):
|
||||||
case static_cast<uint8_t>(Sensors::Type::BLUETOOTH):
|
case static_cast<uint8_t>(Sensors::Type::BLUETOOTH):
|
||||||
|
case static_cast<uint8_t>(Sensors::Type::DHT11):
|
||||||
|
case static_cast<uint8_t>(Sensors::Type::DHT22):
|
||||||
case static_cast<uint8_t>(Sensors::Type::HEATING_SETPOINT_TEMP):
|
case static_cast<uint8_t>(Sensors::Type::HEATING_SETPOINT_TEMP):
|
||||||
case static_cast<uint8_t>(Sensors::Type::MANUAL):
|
case static_cast<uint8_t>(Sensors::Type::MANUAL):
|
||||||
case static_cast<uint8_t>(Sensors::Type::NOT_CONFIGURED):
|
case static_cast<uint8_t>(Sensors::Type::NOT_CONFIGURED):
|
||||||
@@ -1943,7 +1945,8 @@ bool jsonToSensorSettings(const uint8_t sensorId, const JsonVariantConst src, Se
|
|||||||
|
|
||||||
// gpio
|
// gpio
|
||||||
if (!src[FPSTR(S_GPIO)].isNull()) {
|
if (!src[FPSTR(S_GPIO)].isNull()) {
|
||||||
if (dst.type != Sensors::Type::DALLAS_TEMP && dst.type != Sensors::Type::NTC_10K_TEMP) {
|
if (dst.type != Sensors::Type::DALLAS_TEMP && dst.type != Sensors::Type::NTC_10K_TEMP &&
|
||||||
|
dst.type != Sensors::Type::DHT11 && dst.type != Sensors::Type::DHT22) {
|
||||||
if (dst.gpio != GPIO_IS_NOT_CONFIGURED) {
|
if (dst.gpio != GPIO_IS_NOT_CONFIGURED) {
|
||||||
dst.gpio = GPIO_IS_NOT_CONFIGURED;
|
dst.gpio = GPIO_IS_NOT_CONFIGURED;
|
||||||
changed = true;
|
changed = true;
|
||||||
@@ -2084,6 +2087,10 @@ void sensorResultToJson(const uint8_t sensorId, JsonVariant dst) {
|
|||||||
dst[FPSTR(S_BATTERY)] = roundf(rSensor.values[static_cast<uint8_t>(Sensors::ValueType::BATTERY)], 1);
|
dst[FPSTR(S_BATTERY)] = roundf(rSensor.values[static_cast<uint8_t>(Sensors::ValueType::BATTERY)], 1);
|
||||||
dst[FPSTR(S_RSSI)] = roundf(rSensor.values[static_cast<uint8_t>(Sensors::ValueType::RSSI)], 0);
|
dst[FPSTR(S_RSSI)] = roundf(rSensor.values[static_cast<uint8_t>(Sensors::ValueType::RSSI)], 0);
|
||||||
|
|
||||||
|
} else if (sSensor.type == Sensors::Type::DHT11 || sSensor.type == Sensors::Type::DHT22) {
|
||||||
|
dst[FPSTR(S_TEMPERATURE)] = roundf(rSensor.values[static_cast<uint8_t>(Sensors::ValueType::TEMPERATURE)], 3);
|
||||||
|
dst[FPSTR(S_HUMIDITY)] = roundf(rSensor.values[static_cast<uint8_t>(Sensors::ValueType::HUMIDITY)], 3);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
dst[FPSTR(S_VALUE)] = roundf(rSensor.values[static_cast<uint8_t>(Sensors::ValueType::PRIMARY)], 3);
|
dst[FPSTR(S_VALUE)] = roundf(rSensor.values[static_cast<uint8_t>(Sensors::ValueType::PRIMARY)], 3);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -249,6 +249,8 @@
|
|||||||
"ntcTemp": "NTC 传感器",
|
"ntcTemp": "NTC 传感器",
|
||||||
"dallasTemp": "DALLAS 传感器",
|
"dallasTemp": "DALLAS 传感器",
|
||||||
"bluetooth": "BLE 传感器",
|
"bluetooth": "BLE 传感器",
|
||||||
|
"dht11": "DHT11 传感器",
|
||||||
|
"dht22": "DHT22 传感器",
|
||||||
"heatSetpointTemp": "Heating, setpoint temp",
|
"heatSetpointTemp": "Heating, setpoint temp",
|
||||||
"manual": "通过 MQTT/API 手动配置",
|
"manual": "通过 MQTT/API 手动配置",
|
||||||
"notConfigured": "未配置"
|
"notConfigured": "未配置"
|
||||||
|
|||||||
@@ -249,6 +249,8 @@
|
|||||||
"ntcTemp": "NTC sensor",
|
"ntcTemp": "NTC sensor",
|
||||||
"dallasTemp": "DALLAS sensor",
|
"dallasTemp": "DALLAS sensor",
|
||||||
"bluetooth": "BLE sensor",
|
"bluetooth": "BLE sensor",
|
||||||
|
"dht11": "DHT11 sensor",
|
||||||
|
"dht22": "DHT22 sensor",
|
||||||
"heatSetpointTemp": "Heating, setpoint temp",
|
"heatSetpointTemp": "Heating, setpoint temp",
|
||||||
"manual": "Manual via MQTT/API",
|
"manual": "Manual via MQTT/API",
|
||||||
"notConfigured": "Not configured"
|
"notConfigured": "Not configured"
|
||||||
|
|||||||
@@ -249,6 +249,8 @@
|
|||||||
"ntcTemp": "Sensore NTC",
|
"ntcTemp": "Sensore NTC",
|
||||||
"dallasTemp": "Sensore DALLAS",
|
"dallasTemp": "Sensore DALLAS",
|
||||||
"bluetooth": "Sensore BLE",
|
"bluetooth": "Sensore BLE",
|
||||||
|
"dht11": "Sensore DHT11",
|
||||||
|
"dht22": "Sensore DHT22",
|
||||||
"heatSetpointTemp": "Riscaldamento, temp impostata",
|
"heatSetpointTemp": "Riscaldamento, temp impostata",
|
||||||
"manual": "Manuale via MQTT/API",
|
"manual": "Manuale via MQTT/API",
|
||||||
"notConfigured": "Non configurato"
|
"notConfigured": "Non configurato"
|
||||||
|
|||||||
@@ -228,6 +228,8 @@
|
|||||||
"ntcTemp": "NTC-sensor",
|
"ntcTemp": "NTC-sensor",
|
||||||
"dallasTemp": "DALLAS-sensor",
|
"dallasTemp": "DALLAS-sensor",
|
||||||
"bluetooth": "BLE-sensor",
|
"bluetooth": "BLE-sensor",
|
||||||
|
"dht11": "DHT11-sensor",
|
||||||
|
"dht22": "DHT22-sensor",
|
||||||
"heatSetpointTemp": "Verwarming, insteltemperatuur",
|
"heatSetpointTemp": "Verwarming, insteltemperatuur",
|
||||||
"manual": "Handmatig via MQTT/API",
|
"manual": "Handmatig via MQTT/API",
|
||||||
"notConfigured": "Niet geconfigureerd"
|
"notConfigured": "Niet geconfigureerd"
|
||||||
|
|||||||
@@ -249,6 +249,8 @@
|
|||||||
"ntcTemp": "NTC датчик",
|
"ntcTemp": "NTC датчик",
|
||||||
"dallasTemp": "DALLAS датчик",
|
"dallasTemp": "DALLAS датчик",
|
||||||
"bluetooth": "BLE датчик",
|
"bluetooth": "BLE датчик",
|
||||||
|
"dht11": "DHT11 датчик",
|
||||||
|
"dht22": "DHT22 датчик",
|
||||||
"heatSetpointTemp": "Отопление, температура уставки",
|
"heatSetpointTemp": "Отопление, температура уставки",
|
||||||
"manual": "Вручную через MQTT/API",
|
"manual": "Вручную через MQTT/API",
|
||||||
"notConfigured": "Не сконфигурировано"
|
"notConfigured": "Не сконфигурировано"
|
||||||
|
|||||||
@@ -118,6 +118,8 @@
|
|||||||
<option value="50" data-i18n>sensors.types.ntcTemp</option>
|
<option value="50" data-i18n>sensors.types.ntcTemp</option>
|
||||||
<option value="51" data-i18n>sensors.types.dallasTemp</option>
|
<option value="51" data-i18n>sensors.types.dallasTemp</option>
|
||||||
<option value="52" data-i18n>sensors.types.bluetooth</option>
|
<option value="52" data-i18n>sensors.types.bluetooth</option>
|
||||||
|
<option value="53" data-i18n>sensors.types.dht11</option>
|
||||||
|
<option value="54" data-i18n>sensors.types.dht22</option>
|
||||||
<option value="253" data-i18n>sensors.types.heatSetpointTemp</option>
|
<option value="253" data-i18n>sensors.types.heatSetpointTemp</option>
|
||||||
<option value="254" data-i18n>sensors.types.manual</option>
|
<option value="254" data-i18n>sensors.types.manual</option>
|
||||||
<option value="255" data-i18n>sensors.types.notConfigured</option>
|
<option value="255" data-i18n>sensors.types.notConfigured</option>
|
||||||
@@ -271,27 +273,35 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch(parseInt(event.target.value)) {
|
switch(parseInt(event.target.value)) {
|
||||||
// ntc
|
// NTC10K
|
||||||
case 50:
|
case 50:
|
||||||
parentGpio.classList.remove("hidden");
|
parentGpio.classList.remove("hidden");
|
||||||
parentAddress.classList.add("hidden");
|
parentAddress.classList.add("hidden");
|
||||||
address.removeAttribute("pattern");
|
address.removeAttribute("pattern");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// dallas
|
// OneWire
|
||||||
case 51:
|
case 51:
|
||||||
parentGpio.classList.remove("hidden");
|
parentGpio.classList.remove("hidden");
|
||||||
parentAddress.classList.remove("hidden");
|
parentAddress.classList.remove("hidden");
|
||||||
address.setAttribute("pattern", "([A-Fa-f0-9]{2}:){7}[A-Fa-f0-9]{2}");
|
address.setAttribute("pattern", "([A-Fa-f0-9]{2}:){7}[A-Fa-f0-9]{2}");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// ble
|
// Bluetooth
|
||||||
case 52:
|
case 52:
|
||||||
parentGpio.classList.add("hidden");
|
parentGpio.classList.add("hidden");
|
||||||
parentAddress.classList.remove("hidden");
|
parentAddress.classList.remove("hidden");
|
||||||
address.setAttribute("pattern", "([A-Fa-f0-9]{2}:){5}[A-Fa-f0-9]{2}");
|
address.setAttribute("pattern", "([A-Fa-f0-9]{2}:){5}[A-Fa-f0-9]{2}");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// DHT
|
||||||
|
case 53:
|
||||||
|
case 54:
|
||||||
|
parentGpio.classList.remove("hidden");
|
||||||
|
parentAddress.classList.add("hidden");
|
||||||
|
address.removeAttribute("pattern");
|
||||||
|
break;
|
||||||
|
|
||||||
// other
|
// other
|
||||||
default:
|
default:
|
||||||
parentGpio.classList.add("hidden");
|
parentGpio.classList.add("hidden");
|
||||||
|
|||||||
Reference in New Issue
Block a user