mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 22:52:19 +03:00
delete
This commit is contained in:
@@ -1,25 +0,0 @@
|
||||
#include "BufferExecute.h"
|
||||
#include "items/ButtonInClass.h"
|
||||
//==========================================Модуль физических кнопок========================================
|
||||
//button-in switch1 toggle Кнопки Свет 1 pin[2] db[20]
|
||||
//==========================================================================================================
|
||||
|
||||
boolean but[NUM_BUTTONS];
|
||||
Bounce *buttons = new Bounce[NUM_BUTTONS];
|
||||
|
||||
ButtonInClass myButtonIn;
|
||||
void buttonIn() {
|
||||
myButtonIn.update();
|
||||
String key = myButtonIn.gkey();
|
||||
String pin = myButtonIn.gpin();
|
||||
sCmd.addCommand(key.c_str(), buttonInSet);
|
||||
myButtonIn.init();
|
||||
myButtonIn.switchStateSetDefault();
|
||||
myButtonIn.clear();
|
||||
}
|
||||
|
||||
void buttonInSet() {
|
||||
String key = sCmd.order();
|
||||
String state = sCmd.next();
|
||||
myButtonIn.switchChangeVirtual(key, state);
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
#include "items/SensorPower.h"
|
||||
|
||||
SensorPZEM* myPowerSensor;
|
||||
|
||||
void SensorPZEM::loop() {
|
||||
uint32_t now = millis();
|
||||
if ((_lastUpdate + _interval) < now) {
|
||||
post("voltage", String(_pzem->values()->voltage, 2));
|
||||
post("current", String(_pzem->values()->current, 2));
|
||||
post("power", String(_pzem->values()->power, 2));
|
||||
post("energy", String(_pzem->values()->energy, 2));
|
||||
post("freq", String(_pzem->values()->freq, 0));
|
||||
post("pf", String(_pzem->values()->pf, 2));
|
||||
_lastUpdate = now;
|
||||
}
|
||||
}
|
||||
|
||||
String SensorPZEM::getDataKey(const char* param_key) {
|
||||
String res = _key;
|
||||
res += "_";
|
||||
res += param_key;
|
||||
return res;
|
||||
}
|
||||
|
||||
void SensorPZEM::post(const char* key, const String& value) {
|
||||
String dataKey = getDataKey(key);
|
||||
eventGen2(dataKey, value);
|
||||
jsonWriteStr(configLiveJson, dataKey, value);
|
||||
publishStatus(dataKey, value);
|
||||
SerialPrint("I", "Sensor", "'" + dataKey + "' data: " + value);
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
#include "items/vButtonOut.h"
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
#include "BufferExecute.h"
|
||||
#include "SoftUART.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
//this class save data to flash
|
||||
ButtonOut::ButtonOut(String pin, boolean inv, String key, String type) {
|
||||
_pin = pin;
|
||||
_inv = inv;
|
||||
_key = key;
|
||||
_type = type;
|
||||
if (_pin != "") {
|
||||
pinMode(_pin.toInt(), OUTPUT);
|
||||
}
|
||||
int state = jsonReadInt(configStoreJson, key);
|
||||
this->execute(String(state));
|
||||
}
|
||||
ButtonOut::~ButtonOut() {}
|
||||
|
||||
void ButtonOut::execute(String state) {
|
||||
if (state != "" && _pin != "") {
|
||||
if (state == "change") {
|
||||
state = String(!digitalRead(_pin.toInt()));
|
||||
digitalWrite(_pin.toInt(), state.toInt());
|
||||
}
|
||||
else {
|
||||
if (_inv) {
|
||||
digitalWrite(_pin.toInt(), !state.toInt());
|
||||
}
|
||||
else {
|
||||
digitalWrite(_pin.toInt(), state.toInt());
|
||||
}
|
||||
}
|
||||
}
|
||||
eventGen2(_key, state);
|
||||
jsonWriteInt(configStoreJson, _key, state.toInt());
|
||||
saveStore();
|
||||
publishStatus(_key, state);
|
||||
}
|
||||
|
||||
MyButtonOutVector* myButtonOut = nullptr;
|
||||
|
||||
void buttonOut() {
|
||||
myLineParsing.update();
|
||||
String key = myLineParsing.gkey();
|
||||
String pin = myLineParsing.gpin();
|
||||
String inv = myLineParsing.ginv();
|
||||
String type = myLineParsing.gtype();
|
||||
|
||||
bool invb = false;
|
||||
if (inv.toInt() == 1) invb = true;
|
||||
|
||||
myLineParsing.clear();
|
||||
|
||||
buttonOut_EnterCounter++;
|
||||
addKey(key, buttonOut_KeyList, buttonOut_EnterCounter);
|
||||
|
||||
static bool firstTime = true;
|
||||
if (firstTime) myButtonOut = new MyButtonOutVector();
|
||||
firstTime = false;
|
||||
myButtonOut->push_back(ButtonOut(pin, invb, key, type));
|
||||
|
||||
sCmd.addCommand(key.c_str(), buttonOutExecute);
|
||||
}
|
||||
|
||||
void buttonOutExecute() {
|
||||
String key = sCmd.order();
|
||||
String state = sCmd.next();
|
||||
|
||||
int number = getKeyNum(key, buttonOut_KeyList);
|
||||
|
||||
if (myButtonOut != nullptr) {
|
||||
if (number != -1) {
|
||||
myButtonOut->at(number).execute(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
#include "items/vCountDown.h"
|
||||
#include "BufferExecute.h"
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
#include "BufferExecute.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
CountDownClass::CountDownClass(String key) {
|
||||
_key = key;
|
||||
}
|
||||
|
||||
CountDownClass::~CountDownClass() {}
|
||||
|
||||
void CountDownClass::execute(unsigned int countDownPeriod) {
|
||||
_countDownPeriod = countDownPeriod * 1000;
|
||||
_start = true;
|
||||
}
|
||||
|
||||
void CountDownClass::loop() {
|
||||
if (_countDownPeriod > 0 && _start) {
|
||||
prevMillis1 = millis();
|
||||
_start = false;
|
||||
sec = (_countDownPeriod / 1000);
|
||||
}
|
||||
currentMillis = millis();
|
||||
difference1 = currentMillis - prevMillis1;
|
||||
difference2 = currentMillis - prevMillis2;
|
||||
if (difference1 > _countDownPeriod && _countDownPeriod > 0) {
|
||||
_countDownPeriod = 0;
|
||||
eventGen2(_key, "0");
|
||||
Serial.println(_key + " completed");
|
||||
}
|
||||
if (difference2 > 1000 && _countDownPeriod > 0) {
|
||||
prevMillis2 = millis();
|
||||
sec--;
|
||||
Serial.println(_key + " " + String(sec));
|
||||
publishStatus(_key, String(sec));
|
||||
}
|
||||
}
|
||||
|
||||
MyCountDownVector* myCountDown = nullptr;
|
||||
|
||||
void countDown() {
|
||||
myLineParsing.update();
|
||||
String key = myLineParsing.gkey();
|
||||
myLineParsing.clear();
|
||||
|
||||
countDown_EnterCounter++;
|
||||
addKey(key, countDown_KeyList, countDown_EnterCounter);
|
||||
|
||||
Serial.println(countDown_EnterCounter);
|
||||
Serial.println(countDown_KeyList);
|
||||
|
||||
static bool firstTime = true;
|
||||
if (firstTime) myCountDown = new MyCountDownVector();
|
||||
firstTime = false;
|
||||
myCountDown->push_back(CountDownClass(key));
|
||||
|
||||
sCmd.addCommand(key.c_str(), countDownExecute);
|
||||
}
|
||||
|
||||
void countDownExecute() {
|
||||
String key = sCmd.order();
|
||||
String value = sCmd.next();
|
||||
|
||||
if (!isDigitStr(value)) { //если значение - текст
|
||||
value = getValue(value);
|
||||
}
|
||||
|
||||
int number = getKeyNum(key, countDown_KeyList);
|
||||
|
||||
if (myCountDown != nullptr) {
|
||||
if (number != -1) {
|
||||
myCountDown->at(number).execute(value.toInt());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
#include "items/vImpulsOut.h"
|
||||
#include "BufferExecute.h"
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
#include "BufferExecute.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
ImpulsOutClass::ImpulsOutClass(unsigned int impulsPin) {
|
||||
_impulsPin = impulsPin;
|
||||
pinMode(impulsPin, OUTPUT);
|
||||
}
|
||||
|
||||
ImpulsOutClass::~ImpulsOutClass() {}
|
||||
|
||||
void ImpulsOutClass::execute(unsigned long impulsPeriod, unsigned int impulsCount) {
|
||||
_impulsPeriod = impulsPeriod;
|
||||
_impulsCount = impulsCount * 2;
|
||||
_impulsCountBuf = _impulsCount;
|
||||
}
|
||||
|
||||
void ImpulsOutClass::loop() {
|
||||
currentMillis = millis();
|
||||
difference = currentMillis - prevMillis;
|
||||
if (_impulsCountBuf > 0) {
|
||||
if (difference > _impulsPeriod) {
|
||||
_impulsCountBuf--;
|
||||
prevMillis = millis();
|
||||
yield();
|
||||
digitalWrite(_impulsPin, !digitalRead(_impulsPin));
|
||||
yield();
|
||||
}
|
||||
}
|
||||
if (_impulsCountBuf <= 0) {
|
||||
digitalWrite(_impulsPin, LOW);
|
||||
}
|
||||
}
|
||||
|
||||
MyImpulsOutVector* myImpulsOut = nullptr;
|
||||
|
||||
void impuls() {
|
||||
myLineParsing.update();
|
||||
String key = myLineParsing.gkey();
|
||||
String pin = myLineParsing.gpin();
|
||||
myLineParsing.clear();
|
||||
|
||||
impuls_EnterCounter++;
|
||||
addKey(key, impuls_KeyList, impuls_EnterCounter);
|
||||
|
||||
static bool firstTime = true;
|
||||
if (firstTime) myImpulsOut = new MyImpulsOutVector();
|
||||
firstTime = false;
|
||||
myImpulsOut->push_back(ImpulsOutClass(pin.toInt()));
|
||||
|
||||
sCmd.addCommand(key.c_str(), impulsExecute);
|
||||
}
|
||||
|
||||
void impulsExecute() {
|
||||
String key = sCmd.order();
|
||||
String impulsPeriod = sCmd.next();
|
||||
String impulsCount = sCmd.next();
|
||||
|
||||
int number = getKeyNum(key, impuls_KeyList);
|
||||
|
||||
if (myImpulsOut != nullptr) {
|
||||
if (number != -1) {
|
||||
myImpulsOut->at(number).execute(impulsPeriod.toInt(), impulsCount.toInt());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
#include "items/vInOutput.h"
|
||||
#include <Arduino.h>
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
#include "BufferExecute.h"
|
||||
#include "Clock.h"
|
||||
|
||||
//this class save date to flash
|
||||
InOutput::InOutput(String key, String widget) {
|
||||
_key = key;
|
||||
String value = jsonReadStr(configStoreJson, key);
|
||||
|
||||
if (value == "") {
|
||||
if (widget.indexOf("Digit") != -1) {
|
||||
value = "25";
|
||||
}
|
||||
if (widget.indexOf("Time") != -1) {
|
||||
value = "12:00";
|
||||
}
|
||||
}
|
||||
|
||||
this->execute(value);
|
||||
}
|
||||
InOutput::~InOutput() {}
|
||||
|
||||
void InOutput::execute(String value) {
|
||||
eventGen2(_key, value);
|
||||
jsonWriteStr(configStoreJson, _key, value);
|
||||
saveStore();
|
||||
publishStatus(_key, value);
|
||||
}
|
||||
|
||||
MyInOutputVector* myInOutput = nullptr;
|
||||
|
||||
void inOutput() {
|
||||
myLineParsing.update();
|
||||
String widget = myLineParsing.gfile();
|
||||
String key = myLineParsing.gkey();
|
||||
myLineParsing.clear();
|
||||
|
||||
inOutput_EnterCounter++;
|
||||
addKey(key, inOutput_KeyList, inOutput_EnterCounter);
|
||||
|
||||
static bool firstTime = true;
|
||||
if (firstTime) myInOutput = new MyInOutputVector();
|
||||
firstTime = false;
|
||||
myInOutput->push_back(InOutput(key, widget));
|
||||
|
||||
sCmd.addCommand(key.c_str(), inOutputExecute);
|
||||
}
|
||||
|
||||
void inOutputExecute() {
|
||||
String key = sCmd.order();
|
||||
String value = sCmd.next();
|
||||
//String type = sCmd.next();
|
||||
|
||||
|
||||
if (!isDigitStr(value)) { //если значение - текст
|
||||
if (value.indexOf(":") == -1) { //если этот текст не время
|
||||
String valueJson = getValue(value);
|
||||
if (valueJson != "no value") { //если это ключ переменной
|
||||
value = valueJson;
|
||||
}
|
||||
else { //если это просто текст
|
||||
value.replace("#", " ");
|
||||
value.replace("%date%", timeNow->getDateTimeDotFormated());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int number = getKeyNum(key, inOutput_KeyList);
|
||||
|
||||
if (myInOutput != nullptr) {
|
||||
if (number != -1) {
|
||||
myInOutput->at(number).execute(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,190 +0,0 @@
|
||||
#include "items/vLogging.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "BufferExecute.h"
|
||||
#include "Class/LineParsing.h"
|
||||
#include "FileSystem.h"
|
||||
#include "Global.h"
|
||||
|
||||
LoggingClass::LoggingClass(unsigned long period, unsigned int maxPoints, String loggingValueKey, String key) {
|
||||
_period = period * 1000;
|
||||
_maxPoints = maxPoints;
|
||||
_loggingValueKey = loggingValueKey;
|
||||
_key = key;
|
||||
}
|
||||
|
||||
LoggingClass::~LoggingClass() {}
|
||||
|
||||
void LoggingClass::loop() {
|
||||
if (_period > 0) {
|
||||
currentMillis = millis();
|
||||
difference = currentMillis - prevMillis;
|
||||
if (difference >= _period) {
|
||||
prevMillis = millis();
|
||||
execute("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LoggingClass::execute(String keyOrValue) {
|
||||
String loggingValue = "";
|
||||
|
||||
if (keyOrValue == "") { //прилетело из лупа
|
||||
if (getValue(_loggingValueKey) != "no value") {
|
||||
loggingValue = getValue(_loggingValueKey);
|
||||
} else {
|
||||
SerialPrint("E", "Logging", "This value not found on this device");
|
||||
}
|
||||
} else { //прилетело из события
|
||||
if (isDigitDotCommaStr(keyOrValue)) { //если это число или дробное число
|
||||
loggingValue = keyOrValue;
|
||||
} else { //если это ключ
|
||||
if (getValue(_loggingValueKey) != "no value") {
|
||||
loggingValue = getValue(keyOrValue);
|
||||
} else {
|
||||
SerialPrint("E", "Logging", "This value not found on this device");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String filename = "/logs/" + _key + ".txt";
|
||||
|
||||
size_t cnt = countLines(filename);
|
||||
size_t sz = getFileSize(filename);
|
||||
|
||||
SerialPrint("I", "Logging", "http://" + WiFi.localIP().toString() + "/" + filename + " lines " + String(cnt, DEC) + ", size " + String(sz));
|
||||
|
||||
if ((cnt > _maxPoints + 1)) {
|
||||
removeFile(filename);
|
||||
SerialPrint("E", "Logging", "file been remooved: " + filename + " " + String(cnt) + ">" + String(_maxPoints));
|
||||
cnt = 0;
|
||||
}
|
||||
|
||||
if (loggingValue != "") {
|
||||
if (cnt >= _maxPoints) { //удаляем старую строку и добавляем новую
|
||||
String logData = readFile(filename, 20480); //10240
|
||||
SerialPrint("I", "Logging", "Free heap " + String(ESP.getFreeHeap()));
|
||||
if (logData == "large") {
|
||||
SerialPrint("E", "Logging", "File is very large");
|
||||
}
|
||||
|
||||
logData = deleteBeforeDelimiter(logData, "\r\n");
|
||||
|
||||
if (timeNow->hasTimeSynced()) {
|
||||
logData += timeNow->getTimeUnix() + " " + loggingValue + "\r\n";
|
||||
|
||||
writeFile(filename, logData);
|
||||
}
|
||||
} else { //просто добавляем новую строку
|
||||
if (timeNow->hasTimeSynced()) {
|
||||
addFileLn(filename, timeNow->getTimeUnix() + " " + loggingValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String buf = "{}";
|
||||
jsonWriteInt(buf, "x", timeNow->getTimeUnix().toInt());
|
||||
jsonWriteFloat(buf, "y1", loggingValue.toFloat());
|
||||
buf = "{\"status\":[" + buf + "]}";
|
||||
publishChart(_key, buf);
|
||||
}
|
||||
|
||||
MyLoggingVector* myLogging = nullptr;
|
||||
|
||||
void logging() {
|
||||
myLineParsing.update();
|
||||
String loggingValueKey = myLineParsing.gval();
|
||||
String key = myLineParsing.gkey();
|
||||
String interv = myLineParsing.gint();
|
||||
String maxcnt = myLineParsing.gcnt();
|
||||
myLineParsing.clear();
|
||||
|
||||
logging_KeyList += key + ",";
|
||||
|
||||
logging_EnterCounter++;
|
||||
addKey(key, logging_KeyList, logging_EnterCounter);
|
||||
|
||||
static bool firstTime = true;
|
||||
if (firstTime) myLogging = new MyLoggingVector();
|
||||
firstTime = false;
|
||||
myLogging->push_back(LoggingClass(interv.toInt(), maxcnt.toInt(), loggingValueKey, key));
|
||||
|
||||
sCmd.addCommand(key.c_str(), loggingExecute);
|
||||
}
|
||||
|
||||
void loggingExecute() {
|
||||
String key = sCmd.order();
|
||||
String value = sCmd.next();
|
||||
int number = getKeyNum(key, logging_KeyList);
|
||||
if (myLogging != nullptr) {
|
||||
if (number != -1) {
|
||||
myLogging->at(number).execute(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void choose_log_date_and_send() {
|
||||
String all_line = logging_KeyList;
|
||||
while (all_line.length() != 0) {
|
||||
String tmp = selectToMarker(all_line, ",");
|
||||
sendLogData("/logs/" + tmp + ".txt", tmp);
|
||||
all_line = deleteBeforeDelimiter(all_line, ",");
|
||||
}
|
||||
}
|
||||
|
||||
void sendLogData(String file, String topic) {
|
||||
File configFile = FileFS.open(file, "r");
|
||||
if (!configFile) {
|
||||
return;
|
||||
}
|
||||
configFile.seek(0, SeekSet);
|
||||
int i = 0;
|
||||
String buf = "{}";
|
||||
String json_array;
|
||||
String unix_time;
|
||||
String value;
|
||||
unsigned int psn;
|
||||
unsigned int sz = configFile.size();
|
||||
do {
|
||||
i++;
|
||||
psn = configFile.position();
|
||||
String line = configFile.readStringUntil('\n');
|
||||
unix_time = selectToMarker(line, " ");
|
||||
jsonWriteInt(buf, "x", unix_time.toInt());
|
||||
value = deleteBeforeDelimiter(line, " ");
|
||||
jsonWriteFloat(buf, "y1", value.toFloat());
|
||||
if (unix_time != "" || value != "") {
|
||||
json_array += buf + ",";
|
||||
}
|
||||
int grafmax = jsonReadInt(configSetupJson, "grafmax");
|
||||
if (grafmax != 0) {
|
||||
if (i >= grafmax) {
|
||||
json_array = "{\"status\":[" + json_array + "]}";
|
||||
json_array.replace("},]}", "}]}");
|
||||
publishChart(topic, json_array);
|
||||
json_array = "";
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
} while (psn < sz);
|
||||
|
||||
configFile.close();
|
||||
|
||||
json_array = "{\"status\":[" + json_array + "]}";
|
||||
json_array.replace("},]}", "}]}");
|
||||
publishChart(topic, json_array);
|
||||
}
|
||||
|
||||
void cleanLogAndData() {
|
||||
#ifdef ESP8266
|
||||
auto dir = FileFS.openDir("logs");
|
||||
while (dir.next()) {
|
||||
String fname = dir.fileName();
|
||||
SerialPrint("I", "System", fname);
|
||||
removeFile("logs/" + fname);
|
||||
}
|
||||
#endif
|
||||
removeFile("store.json");
|
||||
configStoreJson = "";
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
|
||||
#include "Consts.h"
|
||||
#ifdef PwmOutEnable
|
||||
#include "items/vPwmOut.h"
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
#include "BufferExecute.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
|
||||
//this class save data to flash
|
||||
PwmOut::PwmOut(unsigned int pin, String key) {
|
||||
_pin = pin;
|
||||
_key = key;
|
||||
pinMode(_pin, OUTPUT);
|
||||
int state = jsonReadInt(configStoreJson, key);
|
||||
this->execute(String(state));
|
||||
}
|
||||
PwmOut::~PwmOut() {}
|
||||
|
||||
void PwmOut::execute(String state) {
|
||||
analogWrite(_pin, state.toInt());
|
||||
eventGen2(_key, state);
|
||||
jsonWriteInt(configStoreJson, _key, state.toInt());
|
||||
saveStore();
|
||||
publishStatus(_key, state);
|
||||
}
|
||||
|
||||
MyPwmOutVector* myPwmOut = nullptr;
|
||||
|
||||
void pwmOut() {
|
||||
myLineParsing.update();
|
||||
String key = myLineParsing.gkey();
|
||||
String pin = myLineParsing.gpin();
|
||||
myLineParsing.clear();
|
||||
|
||||
pwmOut_EnterCounter++;
|
||||
addKey(key, pwmOut_KeyList, pwmOut_EnterCounter);
|
||||
|
||||
static bool firstTime = true;
|
||||
if (firstTime) myPwmOut = new MyPwmOutVector();
|
||||
firstTime = false;
|
||||
myPwmOut->push_back(PwmOut(pin.toInt(), key));
|
||||
|
||||
sCmd.addCommand(key.c_str(), pwmOutExecute);
|
||||
}
|
||||
|
||||
void pwmOutExecute() {
|
||||
String key = sCmd.order();
|
||||
String state = sCmd.next();
|
||||
|
||||
int number = getKeyNum(key, pwmOut_KeyList);
|
||||
|
||||
if (myPwmOut != nullptr) {
|
||||
if (number != -1) {
|
||||
myPwmOut->at(number).execute(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,70 +0,0 @@
|
||||
#include "items/vSensorAnalog.h"
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
#include "BufferExecute.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
SensorAnalog::SensorAnalog(String key, unsigned long interval, unsigned int adcPin, int map1, int map2, int map3, int map4, float c) {
|
||||
_interval = interval * 1000;
|
||||
_key = key;
|
||||
_adcPin = adcPin;
|
||||
|
||||
_map1 = map1;
|
||||
_map2 = map2;
|
||||
_map3 = map3;
|
||||
_map4 = map4;
|
||||
|
||||
_c = c;
|
||||
}
|
||||
|
||||
SensorAnalog::~SensorAnalog() {}
|
||||
|
||||
void SensorAnalog::loop() {
|
||||
currentMillis = millis();
|
||||
difference = currentMillis - prevMillis;
|
||||
if (difference >= _interval) {
|
||||
prevMillis = millis();
|
||||
readAnalog();
|
||||
}
|
||||
}
|
||||
|
||||
void SensorAnalog::readAnalog() {
|
||||
int value;
|
||||
#ifdef ESP32
|
||||
value = analogRead(_adcPin);
|
||||
#endif
|
||||
#ifdef ESP8266
|
||||
value = analogRead(A0);
|
||||
#endif
|
||||
|
||||
value = map(value, _map1, _map2, _map3, _map4);
|
||||
float valueFloat = value * _c;
|
||||
|
||||
eventGen2(_key, String(valueFloat));
|
||||
jsonWriteStr(configLiveJson, _key, String(valueFloat));
|
||||
publishStatus(_key, String(valueFloat));
|
||||
SerialPrint("I", "Sensor", "'" + _key + "' data: " + String(valueFloat));
|
||||
}
|
||||
|
||||
MySensorAnalogVector* mySensorAnalog = nullptr;
|
||||
|
||||
void analogAdc() {
|
||||
myLineParsing.update();
|
||||
String interval = myLineParsing.gint();
|
||||
String pin = myLineParsing.gpin();
|
||||
String key = myLineParsing.gkey();
|
||||
String map = myLineParsing.gmap();
|
||||
String c = myLineParsing.gc();
|
||||
myLineParsing.clear();
|
||||
|
||||
int map1 = selectFromMarkerToMarker(map, ",", 0).toInt();
|
||||
int map2 = selectFromMarkerToMarker(map, ",", 1).toInt();
|
||||
int map3 = selectFromMarkerToMarker(map, ",", 2).toInt();
|
||||
int map4 = selectFromMarkerToMarker(map, ",", 3).toInt();
|
||||
|
||||
static bool firstTime = true;
|
||||
if (firstTime) mySensorAnalog = new MySensorAnalogVector();
|
||||
firstTime = false;
|
||||
mySensorAnalog->push_back(SensorAnalog(key, interval.toInt(), pin.toInt(), map1, map2, map3, map4, c.toFloat()));
|
||||
}
|
||||
|
||||
@@ -1,100 +0,0 @@
|
||||
#include "items/vSensorBme280.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "BufferExecute.h"
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
|
||||
Adafruit_BME280* bme = nullptr;
|
||||
|
||||
SensorBme280::SensorBme280(const paramsBme& paramsTmp, const paramsBme& paramsHum, const paramsBme& paramsPrs) {
|
||||
_paramsTmp = paramsBme(paramsTmp);
|
||||
_paramsHum = paramsBme(paramsHum);
|
||||
_paramsPrs = paramsBme(paramsPrs);
|
||||
|
||||
if (!bme) {
|
||||
bme = new Adafruit_BME280;
|
||||
}
|
||||
|
||||
bme->getTemperatureSensor();
|
||||
bme->getPressureSensor();
|
||||
bme->getHumiditySensor();
|
||||
bme->begin(hexStringToUint8(_paramsPrs.addr));
|
||||
}
|
||||
|
||||
SensorBme280::~SensorBme280() {}
|
||||
|
||||
void SensorBme280::loop() {
|
||||
difference = millis() - prevMillis;
|
||||
if (difference >= _paramsPrs.interval) {
|
||||
prevMillis = millis();
|
||||
read();
|
||||
}
|
||||
}
|
||||
|
||||
void SensorBme280::read() {
|
||||
float tmp = bme->readTemperature();
|
||||
float hum = bme->readHumidity();
|
||||
float prs = bme->readPressure();
|
||||
prs = prs / 1.333224 / 100;
|
||||
|
||||
tmp = tmp * _paramsTmp.c;
|
||||
hum = hum * _paramsHum.c;
|
||||
prs = prs * _paramsPrs.c;
|
||||
|
||||
eventGen2(_paramsTmp.key, String(tmp));
|
||||
jsonWriteStr(configLiveJson, _paramsTmp.key, String(tmp));
|
||||
publishStatus(_paramsTmp.key, String(tmp));
|
||||
SerialPrint("I", "Sensor", "'" + _paramsTmp.key + "' data: " + String(tmp));
|
||||
|
||||
eventGen2(_paramsHum.key, String(hum));
|
||||
jsonWriteStr(configLiveJson, _paramsHum.key, String(hum));
|
||||
publishStatus(_paramsHum.key, String(hum));
|
||||
SerialPrint("I", "Sensor", "'" + _paramsHum.key + "' data: " + String(hum));
|
||||
|
||||
eventGen2(_paramsPrs.key, String(prs));
|
||||
jsonWriteStr(configLiveJson, _paramsPrs.key, String(prs));
|
||||
publishStatus(_paramsPrs.key, String(prs));
|
||||
SerialPrint("I", "Sensor", "'" + _paramsPrs.key + "' data: " + String(prs));
|
||||
}
|
||||
|
||||
MySensorBme280Vector* mySensorBme280 = nullptr;
|
||||
|
||||
void bme280Sensor() {
|
||||
myLineParsing.update();
|
||||
String key = myLineParsing.gkey();
|
||||
String addr = myLineParsing.gaddr();
|
||||
String interval = myLineParsing.gint();
|
||||
String c = myLineParsing.gc();
|
||||
myLineParsing.clear();
|
||||
|
||||
static int enterCnt = -1;
|
||||
enterCnt++;
|
||||
|
||||
static paramsBme paramsTmp;
|
||||
static paramsBme paramsHum;
|
||||
static paramsBme paramsPrs;
|
||||
|
||||
if (enterCnt == 0) {
|
||||
paramsTmp.key = key;
|
||||
paramsTmp.c = c.toFloat();
|
||||
}
|
||||
|
||||
if (enterCnt == 1) {
|
||||
paramsHum.key = key;
|
||||
paramsHum.c = c.toFloat();
|
||||
}
|
||||
|
||||
if (enterCnt == 2) {
|
||||
paramsPrs.key = key;
|
||||
paramsPrs.addr = addr;
|
||||
paramsPrs.interval = interval.toInt() * 1000;
|
||||
paramsPrs.c = c.toFloat();
|
||||
|
||||
static bool firstTime = true;
|
||||
if (firstTime) mySensorBme280 = new MySensorBme280Vector();
|
||||
firstTime = false;
|
||||
mySensorBme280->push_back(SensorBme280(paramsTmp, paramsHum, paramsPrs));
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
#include "items/vSensorBmp280.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "BufferExecute.h"
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
|
||||
Adafruit_BMP280* bmp = nullptr;
|
||||
|
||||
SensorBmp280::SensorBmp280(const paramsBmp& paramsTmp, const paramsBmp& paramsPrs) {
|
||||
_paramsTmp = paramsBmp(paramsTmp);
|
||||
_paramsPrs = paramsBmp(paramsPrs);
|
||||
|
||||
if (!bmp) {
|
||||
bmp = new Adafruit_BMP280;
|
||||
}
|
||||
|
||||
bmp->getTemperatureSensor();
|
||||
bmp->getPressureSensor();
|
||||
bmp->begin(hexStringToUint8(_paramsPrs.addr));
|
||||
}
|
||||
|
||||
SensorBmp280::~SensorBmp280() {}
|
||||
|
||||
void SensorBmp280::loop() {
|
||||
difference = millis() - prevMillis;
|
||||
if (difference >= _paramsPrs.interval) {
|
||||
prevMillis = millis();
|
||||
read();
|
||||
}
|
||||
}
|
||||
|
||||
void SensorBmp280::read() {
|
||||
float tmp = bmp->readTemperature();
|
||||
float prs = bmp->readPressure();
|
||||
prs = prs / 1.333224 / 100;
|
||||
|
||||
tmp = tmp * _paramsTmp.c;
|
||||
prs = prs * _paramsPrs.c;
|
||||
|
||||
eventGen2(_paramsTmp.key, String(tmp));
|
||||
jsonWriteStr(configLiveJson, _paramsTmp.key, String(tmp));
|
||||
publishStatus(_paramsTmp.key, String(tmp));
|
||||
SerialPrint("I", "Sensor", "'" + _paramsTmp.key + "' data: " + String(tmp));
|
||||
|
||||
eventGen2(_paramsPrs.key, String(prs));
|
||||
jsonWriteStr(configLiveJson, _paramsPrs.key, String(prs));
|
||||
publishStatus(_paramsPrs.key, String(prs));
|
||||
SerialPrint("I", "Sensor", "'" + _paramsPrs.key + "' data: " + String(prs));
|
||||
}
|
||||
|
||||
MySensorBmp280Vector* mySensorBmp280 = nullptr;
|
||||
|
||||
void bmp280Sensor() {
|
||||
myLineParsing.update();
|
||||
String key = myLineParsing.gkey();
|
||||
String addr = myLineParsing.gaddr();
|
||||
String interval = myLineParsing.gint();
|
||||
String c = myLineParsing.gc();
|
||||
myLineParsing.clear();
|
||||
|
||||
static int enterCnt = -1;
|
||||
enterCnt++;
|
||||
|
||||
static paramsBmp paramsTmp;
|
||||
static paramsBmp paramsHum;
|
||||
static paramsBmp paramsPrs;
|
||||
|
||||
if (enterCnt == 0) {
|
||||
paramsTmp.key = key;
|
||||
paramsTmp.c = c.toFloat();
|
||||
}
|
||||
|
||||
if (enterCnt == 1) {
|
||||
paramsPrs.key = key;
|
||||
paramsPrs.addr = addr;
|
||||
paramsPrs.interval = interval.toInt() * 1000;
|
||||
paramsPrs.c = c.toFloat();
|
||||
|
||||
static bool firstTime = true;
|
||||
if (firstTime) mySensorBmp280 = new MySensorBmp280Vector();
|
||||
firstTime = false;
|
||||
mySensorBmp280->push_back(SensorBmp280(paramsTmp, paramsPrs));
|
||||
}
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
#include "items/vSensorCcs811.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "BufferExecute.h"
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
|
||||
SensorCcs811::SensorCcs811(const paramsCcs811& paramsPpm, const paramsCcs811& paramsPpb) {
|
||||
_paramsPpm = paramsCcs811(paramsPpm);
|
||||
_paramsPpb = paramsCcs811(paramsPpb);
|
||||
|
||||
ccs811 = new Adafruit_CCS811();
|
||||
|
||||
if (!ccs811->begin(hexStringToUint8(_paramsPpb.addr))) SerialPrint("E", "Sensor CCS", "Wire not connected");
|
||||
}
|
||||
|
||||
SensorCcs811::~SensorCcs811() {}
|
||||
|
||||
void SensorCcs811::loop() {
|
||||
difference = millis() - prevMillis;
|
||||
if (difference >= _paramsPpb.interval) {
|
||||
prevMillis = millis();
|
||||
read();
|
||||
}
|
||||
}
|
||||
|
||||
void SensorCcs811::read() {
|
||||
float co2;
|
||||
float ppm;
|
||||
if (ccs811->available()) {
|
||||
if (!ccs811->readData()) {
|
||||
co2 = ccs811->geteCO2();
|
||||
ppm = ccs811->getTVOC();
|
||||
|
||||
co2 = co2 * _paramsPpm.c;
|
||||
ppm = ppm * _paramsPpb.c;
|
||||
|
||||
eventGen2(_paramsPpm.key, String(co2));
|
||||
jsonWriteStr(configLiveJson, _paramsPpm.key, String(co2));
|
||||
publishStatus(_paramsPpm.key, String(co2));
|
||||
SerialPrint("I", "Sensor", "'" + _paramsPpm.key + "' data: " + String(co2));
|
||||
|
||||
eventGen2(_paramsPpb.key, String(ppm));
|
||||
jsonWriteStr(configLiveJson, _paramsPpb.key, String(ppm));
|
||||
publishStatus(_paramsPpb.key, String(ppm));
|
||||
SerialPrint("I", "Sensor", "'" + _paramsPpb.key + "' data: " + String(ppm));
|
||||
} else {
|
||||
SerialPrint("E", "Sensor CCS", "Error");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MySensorCcs811Vector* mySensorCcs811 = nullptr;
|
||||
|
||||
void ccs811Sensor() {
|
||||
myLineParsing.update();
|
||||
String key = myLineParsing.gkey();
|
||||
String addr = myLineParsing.gaddr();
|
||||
String interval = myLineParsing.gint();
|
||||
String c = myLineParsing.gc();
|
||||
myLineParsing.clear();
|
||||
|
||||
static int enterCnt = -1;
|
||||
enterCnt++;
|
||||
|
||||
static paramsCcs811 paramsPpm;
|
||||
static paramsCcs811 paramsPpb;
|
||||
|
||||
if (enterCnt == 0) {
|
||||
paramsPpm.key = key;
|
||||
paramsPpm.interval = interval.toInt() * 1000;
|
||||
paramsPpm.c = c.toFloat();
|
||||
}
|
||||
|
||||
if (enterCnt == 1) {
|
||||
paramsPpb.key = key;
|
||||
paramsPpb.addr = addr;
|
||||
paramsPpb.interval = interval.toInt() * 1000;
|
||||
paramsPpb.c = c.toFloat();
|
||||
|
||||
static bool firstTime = true;
|
||||
if (firstTime) mySensorCcs811 = new MySensorCcs811Vector();
|
||||
firstTime = false;
|
||||
mySensorCcs811->push_back(SensorCcs811(paramsPpm, paramsPpb));
|
||||
|
||||
enterCnt = -1;
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
#include "items/vSensorDallas.h"
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
#include "BufferExecute.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
SensorDallas::SensorDallas(unsigned long interval, unsigned int pin, unsigned int index, String key) {
|
||||
_interval = interval * 1000;
|
||||
_key = key;
|
||||
_pin = pin;
|
||||
_index = index;
|
||||
|
||||
oneWire = new OneWire((uint8_t)_pin);
|
||||
sensors.setOneWire(oneWire);
|
||||
sensors.begin();
|
||||
sensors.setResolution(12);
|
||||
}
|
||||
|
||||
SensorDallas::~SensorDallas() {}
|
||||
|
||||
void SensorDallas::loop() {
|
||||
currentMillis = millis();
|
||||
difference = currentMillis - prevMillis;
|
||||
if (difference >= _interval) {
|
||||
prevMillis = millis();
|
||||
readDallas();
|
||||
}
|
||||
}
|
||||
|
||||
void SensorDallas::readDallas() {
|
||||
sensors.requestTemperaturesByIndex(_index);
|
||||
float value = sensors.getTempCByIndex(_index);
|
||||
eventGen2(_key, String(value));
|
||||
jsonWriteStr(configLiveJson, _key, String(value));
|
||||
publishStatus(_key, String(value));
|
||||
SerialPrint("I", "Sensor", "'" + _key + "' data: " + String(value));
|
||||
}
|
||||
|
||||
MySensorDallasVector* mySensorDallas2 = nullptr;
|
||||
|
||||
void dallas() {
|
||||
myLineParsing.update();
|
||||
String interval = myLineParsing.gint();
|
||||
String pin = myLineParsing.gpin();
|
||||
String index = myLineParsing.gindex();
|
||||
String key = myLineParsing.gkey();
|
||||
myLineParsing.clear();
|
||||
|
||||
static bool firstTime = true;
|
||||
if (firstTime) mySensorDallas2 = new MySensorDallasVector();
|
||||
firstTime = false;
|
||||
mySensorDallas2->push_back(SensorDallas(interval.toInt(), pin.toInt(), index.toInt(), key));
|
||||
}
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
#include "items/vSensorDht.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "BufferExecute.h"
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
|
||||
SensorDht::SensorDht(const paramsDht& paramsTmp, const paramsDht& paramsHum) {
|
||||
_paramsTmp = paramsDht(paramsTmp);
|
||||
_paramsHum = paramsDht(paramsHum);
|
||||
|
||||
dht = new DHTesp();
|
||||
|
||||
if (_paramsHum.type == "dht11") {
|
||||
dht->setup(_paramsHum.pin, DHTesp::DHT11);
|
||||
} else if (_paramsHum.type == "dht22") {
|
||||
dht->setup(_paramsHum.pin, DHTesp::DHT22);
|
||||
}
|
||||
|
||||
_paramsHum.interval = _paramsHum.interval + dht->getMinimumSamplingPeriod();
|
||||
}
|
||||
|
||||
SensorDht::~SensorDht() {}
|
||||
|
||||
void SensorDht::loop() {
|
||||
difference = millis() - prevMillis;
|
||||
if (difference >= _paramsHum.interval) {
|
||||
prevMillis = millis();
|
||||
readTmpHum();
|
||||
}
|
||||
}
|
||||
|
||||
void SensorDht::readTmpHum() {
|
||||
float tmp = dht->getTemperature();
|
||||
float hum = dht->getHumidity();
|
||||
|
||||
if (String(tmp) != "nan" && String(hum) != "nan") {
|
||||
tmp = tmp * _paramsTmp.c;
|
||||
hum = hum * _paramsHum.c;
|
||||
|
||||
eventGen2(_paramsTmp.key, String(tmp));
|
||||
jsonWriteStr(configLiveJson, _paramsTmp.key, String(tmp));
|
||||
publishStatus(_paramsTmp.key, String(tmp));
|
||||
SerialPrint("I", "Sensor", "'" + _paramsTmp.key + "' data: " + String(tmp));
|
||||
|
||||
eventGen2(_paramsHum.key, String(hum));
|
||||
jsonWriteStr(configLiveJson, _paramsHum.key, String(hum));
|
||||
publishStatus(_paramsHum.key, String(hum));
|
||||
SerialPrint("I", "Sensor", "'" + _paramsHum.key + "' data: " + String(hum));
|
||||
|
||||
} else {
|
||||
SerialPrint("E", "Sensor DHT", "Error");
|
||||
}
|
||||
}
|
||||
|
||||
MySensorDhtVector* mySensorDht = nullptr;
|
||||
|
||||
void dhtSensor() {
|
||||
myLineParsing.update();
|
||||
String type = myLineParsing.gtype();
|
||||
String interval = myLineParsing.gint();
|
||||
String pin = myLineParsing.gpin();
|
||||
String key = myLineParsing.gkey();
|
||||
String c = myLineParsing.gc();
|
||||
myLineParsing.clear();
|
||||
|
||||
static int enterCnt = -1;
|
||||
enterCnt++;
|
||||
|
||||
static paramsDht paramsTmp;
|
||||
static paramsDht paramsHum;
|
||||
|
||||
if (enterCnt == 0) {
|
||||
paramsTmp.key = key;
|
||||
paramsTmp.interval = interval.toInt() * 1000;
|
||||
paramsTmp.c = c.toFloat();
|
||||
}
|
||||
|
||||
if (enterCnt == 1) {
|
||||
paramsHum.type = type;
|
||||
paramsHum.key = key;
|
||||
paramsHum.interval = interval.toInt() * 1000;
|
||||
paramsHum.pin = pin.toInt();
|
||||
paramsHum.c = c.toFloat();
|
||||
|
||||
static bool firstTime = true;
|
||||
if (firstTime) mySensorDht = new MySensorDhtVector();
|
||||
firstTime = false;
|
||||
mySensorDht->push_back(SensorDht(paramsTmp, paramsHum));
|
||||
|
||||
enterCnt = -1;
|
||||
}
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
#include "items/vSensorUltrasonic.h"
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
#include "BufferExecute.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
GMedian<5, int> testFilter;
|
||||
|
||||
SensorUltrasonic::SensorUltrasonic(String key, unsigned long interval, unsigned int trig, unsigned int echo, int map1, int map2, int map3, int map4, float c) {
|
||||
_interval = interval * 1000;
|
||||
_key = key;
|
||||
_trig = trig;
|
||||
_echo = echo;
|
||||
|
||||
_map1 = map1;
|
||||
_map2 = map2;
|
||||
_map3 = map3;
|
||||
_map4 = map4;
|
||||
|
||||
_c = c;
|
||||
|
||||
pinMode(_trig, OUTPUT);
|
||||
pinMode(_echo, INPUT);
|
||||
}
|
||||
|
||||
SensorUltrasonic::~SensorUltrasonic() {}
|
||||
|
||||
void SensorUltrasonic::loop() {
|
||||
currentMillis = millis();
|
||||
difference = currentMillis - prevMillis;
|
||||
if (difference >= _interval) {
|
||||
prevMillis = millis();
|
||||
readUltrasonic();
|
||||
}
|
||||
}
|
||||
|
||||
void SensorUltrasonic::readUltrasonic() {
|
||||
|
||||
static unsigned int counter;
|
||||
counter++;
|
||||
|
||||
int value;
|
||||
|
||||
digitalWrite(_trig, LOW);
|
||||
delayMicroseconds(2);
|
||||
digitalWrite(_trig, HIGH);
|
||||
delayMicroseconds(10);
|
||||
digitalWrite(_trig, LOW);
|
||||
long duration_ = pulseIn(_echo, HIGH, 30000); // 3000 µs = 50cm // 30000 µs = 5 m
|
||||
value = duration_ / 29 / 2;
|
||||
|
||||
value = testFilter.filtered(value);
|
||||
|
||||
value = map(value, _map1, _map2, _map3, _map4);
|
||||
float valueFloat = value * _c;
|
||||
|
||||
if (counter > 10) {
|
||||
eventGen2(_key, String(valueFloat));
|
||||
jsonWriteStr(configLiveJson, _key, String(valueFloat));
|
||||
publishStatus(_key, String(valueFloat));
|
||||
SerialPrint("I", "Sensor", "'" + _key + "' data: " + String(valueFloat));
|
||||
}
|
||||
}
|
||||
|
||||
MySensorUltrasonicVector* mySensorUltrasonic = nullptr;
|
||||
|
||||
void ultrasonic() {
|
||||
myLineParsing.update();
|
||||
String interval = myLineParsing.gint();
|
||||
String pin = myLineParsing.gpin();
|
||||
String key = myLineParsing.gkey();
|
||||
String map = myLineParsing.gmap();
|
||||
String c = myLineParsing.gc();
|
||||
myLineParsing.clear();
|
||||
|
||||
unsigned int trig = selectFromMarkerToMarker(pin, ",", 0).toInt();
|
||||
unsigned int echo = selectFromMarkerToMarker(pin, ",", 1).toInt();
|
||||
|
||||
int map1 = selectFromMarkerToMarker(map, ",", 0).toInt();
|
||||
int map2 = selectFromMarkerToMarker(map, ",", 1).toInt();
|
||||
int map3 = selectFromMarkerToMarker(map, ",", 2).toInt();
|
||||
int map4 = selectFromMarkerToMarker(map, ",", 3).toInt();
|
||||
|
||||
static bool firstTime = true;
|
||||
if (firstTime) mySensorUltrasonic = new MySensorUltrasonicVector();
|
||||
firstTime = false;
|
||||
mySensorUltrasonic->push_back(SensorUltrasonic(key, interval.toInt(), trig, echo, map1, map2, map3, map4, c.toFloat()));
|
||||
}
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
#include "items/vSensorUptime.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "BufferExecute.h"
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
|
||||
SensorUptime::SensorUptime(const paramsUptime& paramsUpt) {
|
||||
_paramsUpt = paramsUptime(paramsUpt);
|
||||
}
|
||||
|
||||
SensorUptime::~SensorUptime() {}
|
||||
|
||||
void SensorUptime::loop() {
|
||||
difference = millis() - prevMillis;
|
||||
if (difference >= _paramsUpt.interval) {
|
||||
prevMillis = millis();
|
||||
read();
|
||||
}
|
||||
}
|
||||
|
||||
void SensorUptime::read() {
|
||||
String upt = timeNow->getUptime();
|
||||
|
||||
eventGen2(_paramsUpt.key, upt);
|
||||
jsonWriteStr(configLiveJson, _paramsUpt.key, upt);
|
||||
publishStatus(_paramsUpt.key, upt);
|
||||
SerialPrint("I", "Sensor", "'" + _paramsUpt.key + "' data: " + upt);
|
||||
}
|
||||
|
||||
MySensorUptimeVector* mySensorUptime = nullptr;
|
||||
|
||||
void uptimeSensor() {
|
||||
myLineParsing.update();
|
||||
String key = myLineParsing.gkey();
|
||||
String interval = myLineParsing.gint();
|
||||
myLineParsing.clear();
|
||||
|
||||
static paramsUptime paramsUpt;
|
||||
|
||||
paramsUpt.key = key;
|
||||
paramsUpt.interval = interval.toInt() * 1000;
|
||||
|
||||
static bool firstTime = true;
|
||||
if (firstTime) mySensorUptime = new MySensorUptimeVector();
|
||||
firstTime = false;
|
||||
mySensorUptime->push_back(SensorUptime(paramsUpt));
|
||||
}
|
||||
Reference in New Issue
Block a user