Merge pull request #9 from Mit4el/ver4dev

Добавил NTC, исправил косяк с Гуглом
This commit is contained in:
2023-06-17 19:43:33 +03:00
committed by GitHub
4 changed files with 154 additions and 9 deletions

View File

@@ -116,6 +116,10 @@
"path": "src/modules/sensors/DS2401",
"active": false
},
{
"path": "src/modules/sensors/Ds2423",
"active": true
},
{
"path": "src/modules/sensors/Emon",
"active": false
@@ -164,6 +168,10 @@
"path": "src/modules/sensors/Mhz19",
"active": false
},
{
"path": "src/modules/sensors/Ntc",
"active": true
},
{
"path": "src/modules/sensors/Pzem004t",
"active": true
@@ -180,6 +188,10 @@
"path": "src/modules/sensors/S8",
"active": true
},
{
"path": "src/modules/sensors/Scd40",
"active": true
},
{
"path": "src/modules/sensors/Sds011",
"active": false

View File

@@ -0,0 +1,75 @@
/******************************************************************
Simple library for NTC thermistors
https://github.com/GyverLibs/GyverNTC
adapted for version 4 @Serghei63
******************************************************************/
#include "Global.h"
#include "classes/IoTItem.h"
class NTCt : public IoTItem {
private:
unsigned int _pin;
float R1 = 10000.0; // voltage divider resistor value
float Beta = 3950.0; // Beta value
float To = 25.; // Temperature Celsius
float Ro = 10000.0; // Resistance of Thermistor at 25 degree Celsius
float adcMax = 1023.0;
float Vs = 3.3;
public:
NTCt(String parameters): IoTItem(parameters) {
_pin = jsonReadInt(parameters, "pin");
R1 = jsonReadInt(parameters, "R1"); // voltage divider resistor value
Beta = jsonReadInt(parameters, "Beta"); // Beta value
To = jsonReadInt(parameters, "T0"); // Temperature degree Celsius
Ro = jsonReadInt(parameters, "R0"); // Resistance of Thermistor at 25 degree Celsius
Vs = jsonReadInt(parameters, "Vs"); // Resistance of Thermistor at 25 degree Celsius
To = To+273.15;
#if defined ESP8266
adcMax = 1023.0;
#elif defined ESP32
adcMax = 4095.0;
#endif
}
void doByInterval() {
float Vout, Rt = 0;
float T = 0;
float adc = 0;
for (int i = 0; i < 10; i++)
{
adc += IoTgpio.analogRead(_pin);
}
adc /= 10;
Vout = adc * Vs/adcMax;
Rt = R1 * Vout / (Vs - Vout);
T = 1/(1/To + log(Rt/Ro)/Beta); // Temperature in Kelvin
value.valD = T - 273.15; // Celsius
SerialPrint("i", F("Ntc"), "adc = " + String(adc)+ " ,Vout = " + String(Vout)+ " ,T = " + String(value.valD));
if (String(value.valD) != "nan") regEvent(value.valD, "Ntc");
else
SerialPrint("E", "Ntc", "Error");
}
~NTCt() {};
};
void* getAPI_Ntc(String subtype, String param) {
if (subtype == F("Ntc")) {
return new NTCt(param);
} else {
return nullptr;
}
}

View File

@@ -0,0 +1,65 @@
{
"menuSection": "Сенсоры",
"configItem": [
{
"global": 0,
"name": "Cенсор температуры NTC",
"type": "Reading",
"subtype": "Ntc",
"id": "Ntctmp",
"widget": "anydataTmp",
"page": "Сенсоры",
"descr": "NTC Температура",
"needSave": 0,
"val": "0",
"int": 15,
"pin": "35",
"R1":"10000",
"R0":"10000",
"Beta":"3950.0",
"T0":"25",
"Vs":"3.3",
"round" : 1
}
],
"about": {
"authorName": "Serghei Crasnicov",
"authorContact": "https://t.me/Serghei63",
"authorGit": "https://github.com/Serghei63",
"specialThanks": "https://t.me/Mit4bmw",
"moduleName": "Ntc",
"moduleVersion": "1.1",
"usedRam": {
"esp32_4mb": 15,
"esp8266_4mb": 15
},
"subTypes": [
"Ntc"
],
"title": "Модуль датчика Ntc",
"moduleDesc": "",
"retInfo": "",
"propInfo": {
"pin": "Аналоговый пин (для esp8266 = 0, для esp32 алаоговый gpio, например 35)",
"R1":"Сопротивление подтягивающего резистора, должен быть равен сопротивлению термистера",
"Vs":"Напряжение питания датчика, Для точности измерить и ввести своё, по умолчанию 3.3В",
"R0":"Сопротивление термистора при температуре То, например 10 КОм при 25С",
"T0":"Базовая температура, температура измерения сопротивление термистора (Rterm), обычно 25С",
"Beta":"Beta термистора"
}
},
"defActive": true,
"usedLibs": {
"esp32_4mb": [],
"esp8266_4mb": [],
"esp8266_1mb": [],
"esp8266_1mb_ota": [],
"esp8285_1mb": [],
"esp8285_1mb_ota": [],
"esp8266_2mb": [],
"esp8266_2mb_ota": []
}
}

View File

@@ -12,7 +12,7 @@
"descr": "",
"int": 5,
"logid": "id",
"scid": "AKfycbzAsuM-4Keb-DxZ6yqwmqSeiXRJJAqndijayZQfmx9pfh6wGAejjT6u7gTAIxrbxPBxyw",
"scid": "Script_ID",
"shname": "Logger"
}
],
@@ -40,13 +40,6 @@
"defActive": false,
"usedLibs": {
"esp32_4mb": [],
"esp32s2_4mb": [],
"esp8266_4mb": [],
"esp8266_1mb": [],
"esp8266_1mb_ota": [],
"esp8285_1mb": [],
"esp8285_1mb_ota": [],
"esp8266_2mb": [],
"esp8266_2mb_ota": []
"esp32s2_4mb": []
}
}