mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 11:59:12 +03:00
sensor dht support
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
#include "Class/LineParsing.h"
|
#include "Class/LineParsing.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include "items/SensorConvertingClass.h"
|
#include "items/SensorConvertingClass.h"
|
||||||
|
|||||||
45
include/items/SensorDhtClass.h
Normal file
45
include/items/SensorDhtClass.h
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include "Class/LineParsing.h"
|
||||||
|
#include "Global.h"
|
||||||
|
#include "items/SensorConvertingClass.h"
|
||||||
|
|
||||||
|
class SensorDhtClass : public SensorConvertingClass {
|
||||||
|
public:
|
||||||
|
SensorDhtClass() : SensorConvertingClass(){};
|
||||||
|
|
||||||
|
void SensorDhtInit() {
|
||||||
|
//oneWire = new OneWire((uint8_t)_pin.toInt());
|
||||||
|
//sensors.setOneWire(oneWire);
|
||||||
|
//sensors.begin();
|
||||||
|
//sensors.setResolution(48);
|
||||||
|
|
||||||
|
sensorReadingMap += _key + ",";
|
||||||
|
//dhtEnterCounter++;
|
||||||
|
|
||||||
|
//jsonWriteInt(configOptionJson, _key + "_num", dhtEnterCounter);
|
||||||
|
jsonWriteStr(configOptionJson, _key + "_map", _map);
|
||||||
|
jsonWriteStr(configOptionJson, _key + "_с", _c);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SensorDhtRead(String key) {
|
||||||
|
float value;
|
||||||
|
byte num = sensors.getDS18Count();
|
||||||
|
sensors.requestTemperatures();
|
||||||
|
|
||||||
|
int cnt = jsonReadInt(configOptionJson, key + "_num");
|
||||||
|
|
||||||
|
for (byte i = 0; i < num; i++) {
|
||||||
|
if (i == cnt) {
|
||||||
|
value = sensors.getTempCByIndex(i);
|
||||||
|
//value = this->mapping(key, value);
|
||||||
|
float valueFl = this->correction(key, value);
|
||||||
|
eventGen(key, "");
|
||||||
|
jsonWriteStr(configLiveJson, key, String(valueFl));
|
||||||
|
MqttClient::publishStatus(key, String(valueFl));
|
||||||
|
Serial.println("[I] sensor '" + key + "' data: " + String(valueFl));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
extern SensorDhtClass mySensorDht;
|
||||||
@@ -20,7 +20,7 @@ void bmp280T_reading();
|
|||||||
|
|
||||||
void sensorsInit() {
|
void sensorsInit() {
|
||||||
ts.add(
|
ts.add(
|
||||||
SENSORS, 15000, [&](void *) {
|
SENSORS, 10000, [&](void *) {
|
||||||
String buf = sensorReadingMap;
|
String buf = sensorReadingMap;
|
||||||
while (buf.length()) {
|
while (buf.length()) {
|
||||||
String tmp = selectToMarker(buf, ",");
|
String tmp = selectToMarker(buf, ",");
|
||||||
|
|||||||
20
src/items/SensorDhtClass.cpp
Normal file
20
src/items/SensorDhtClass.cpp
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#include "items/ItemsGlobal.h"
|
||||||
|
#include "items/SensorDhtClass.h"
|
||||||
|
//#ifdef SensorDhtEnabled
|
||||||
|
//=========================================Модуль ультрозвукового дальномера==================================================================
|
||||||
|
//dht-temp;id;anydata;Сенсоры;Температура;order;pin;c[1]
|
||||||
|
//=========================================================================================================================================
|
||||||
|
SensorDhtClass mySensorDht;
|
||||||
|
void DhtTemp() {
|
||||||
|
mySensorDht.update();
|
||||||
|
String key = mySensorDht.gkey();
|
||||||
|
sCmd.addCommand(key.c_str(), dhtReading);
|
||||||
|
mySensorDht.SensorDhtInit();
|
||||||
|
mySensorDht.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void dhtReading() {
|
||||||
|
String key = sCmd.order();
|
||||||
|
mySensorDht.SensorDhtRead(key);
|
||||||
|
}
|
||||||
|
//#endif
|
||||||
Reference in New Issue
Block a user