2021-12-03 10:03:20 +03:00
|
|
|
#include "Consts.h"
|
|
|
|
|
#ifdef EnableSensorSht20
|
|
|
|
|
#include "items/vSensorSht20.h"
|
|
|
|
|
|
|
|
|
|
#include <Arduino.h>
|
|
|
|
|
|
|
|
|
|
#include "BufferExecute.h"
|
|
|
|
|
#include "Class/LineParsing.h"
|
|
|
|
|
#include "Global.h"
|
|
|
|
|
|
|
|
|
|
#include "Wire.h"
|
|
|
|
|
#include "SHT2x.h"
|
|
|
|
|
SHT2x* sht = nullptr;
|
|
|
|
|
|
|
|
|
|
SensorSht20::SensorSht20(const paramsSht& paramsTmp, const paramsSht& paramsHum) {
|
|
|
|
|
_paramsTmp = paramsSht(paramsTmp);
|
|
|
|
|
_paramsHum = paramsSht(paramsHum);
|
|
|
|
|
|
|
|
|
|
if (!sht) {
|
|
|
|
|
sht = new SHT2x;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sht->begin();
|
|
|
|
|
|
|
|
|
|
uint8_t stat = sht->getStatus();
|
|
|
|
|
Serial.print(stat, HEX);
|
|
|
|
|
Serial.println();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SensorSht20::~SensorSht20() {}
|
|
|
|
|
|
|
|
|
|
void SensorSht20::loop() {
|
|
|
|
|
difference = millis() - prevMillis;
|
|
|
|
|
if (difference >= _paramsHum.interval) {
|
|
|
|
|
prevMillis = millis();
|
|
|
|
|
read();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SensorSht20::read() {
|
|
|
|
|
sht->read();
|
|
|
|
|
|
|
|
|
|
float tmp = sht->getTemperature();
|
|
|
|
|
float hum = sht->getHumidity();
|
|
|
|
|
|
|
|
|
|
tmp = tmp * _paramsTmp.c;
|
|
|
|
|
hum = hum * _paramsHum.c;
|
|
|
|
|
|
|
|
|
|
eventGen2(_paramsTmp.key, String(tmp));
|
|
|
|
|
jsonWriteStr(configLiveJson, _paramsTmp.key, String(tmp));
|
|
|
|
|
publishStatus(_paramsTmp.key, String(tmp));
|
2021-12-13 16:26:43 +03:00
|
|
|
String path = mqttRootDevice + "/" +_paramsTmp.key + "/status";
|
|
|
|
|
String json = "{}";
|
|
|
|
|
jsonWriteStr(json, "status", String(tmp));
|
|
|
|
|
String MyJson = json;
|
|
|
|
|
jsonWriteStr(MyJson, "topic", path);
|
|
|
|
|
ws.textAll(MyJson);
|
|
|
|
|
|
2021-12-03 10:03:20 +03:00
|
|
|
SerialPrint("I", "Sensor", "'" + _paramsTmp.key + "' data: " + String(tmp));
|
|
|
|
|
|
|
|
|
|
eventGen2(_paramsHum.key, String(hum));
|
|
|
|
|
jsonWriteStr(configLiveJson, _paramsHum.key, String(hum));
|
|
|
|
|
publishStatus(_paramsHum.key, String(hum));
|
2021-12-13 16:26:43 +03:00
|
|
|
path = mqttRootDevice + "/" +_paramsHum.key + "/status";
|
|
|
|
|
json = "{}";
|
|
|
|
|
jsonWriteStr(json, "status", String(hum));
|
|
|
|
|
MyJson = json;
|
|
|
|
|
jsonWriteStr(MyJson, "topic", path);
|
|
|
|
|
ws.textAll(MyJson);
|
2021-12-03 10:03:20 +03:00
|
|
|
SerialPrint("I", "Sensor", "'" + _paramsHum.key + "' data: " + String(hum));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MySensorSht20Vector* mySensorSht20 = nullptr;
|
|
|
|
|
|
|
|
|
|
void sht20Sensor() {
|
|
|
|
|
myLineParsing.update();
|
|
|
|
|
String key = myLineParsing.gkey();
|
|
|
|
|
String interval = myLineParsing.gint();
|
|
|
|
|
String c = myLineParsing.gc();
|
|
|
|
|
myLineParsing.clear();
|
|
|
|
|
|
|
|
|
|
static int enterCnt = -1;
|
|
|
|
|
enterCnt++;
|
|
|
|
|
|
|
|
|
|
static paramsSht paramsTmp;
|
|
|
|
|
static paramsSht paramsHum;
|
|
|
|
|
|
|
|
|
|
if (enterCnt == 0) {
|
|
|
|
|
paramsTmp.key = key;
|
|
|
|
|
paramsTmp.c = c.toFloat();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (enterCnt == 1) {
|
|
|
|
|
paramsHum.key = key;
|
|
|
|
|
paramsHum.c = c.toFloat();
|
|
|
|
|
paramsHum.interval = interval.toInt() * 1000;
|
|
|
|
|
|
|
|
|
|
static bool firstTime = true;
|
|
|
|
|
if (firstTime) mySensorSht20 = new MySensorSht20Vector();
|
|
|
|
|
firstTime = false;
|
|
|
|
|
mySensorSht20->push_back(SensorSht20(paramsTmp, paramsHum));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|