mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 14:12:16 +03:00
264 stable. Dallas bug fixed!
This commit is contained in:
@@ -1 +1 @@
|
||||
0;dallas-temp;id;anydataTemp;Сенсоры;Температура;order;sal;c[1]
|
||||
0;dallas-temp;id;anydataTemp;Сенсоры;Температура;order;sal;index[0];int[10]
|
||||
5
data/presets/dal.c.txt
Normal file
5
data/presets/dal.c.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
0;dallas-temp;temp;anydataTemp;Термостат;Температура;1;pin[2];index[0];int[10]
|
||||
0;logging;log;chart;Термостат;История;2;val[temp];int[60];cnt[100]
|
||||
0;input-digit;inputU;inputDigit;Термостат;Верхний#порог;3;st[30]
|
||||
0;input-digit;inputL;inputDigit;Термостат;Нижний#порог;4;st[20]
|
||||
0;button-out;button;toggle;Термостат;Нагрев;5;pin[12];st[0]
|
||||
6
data/presets/dal.s.txt
Normal file
6
data/presets/dal.s.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
temp > inputU
|
||||
button 0
|
||||
end
|
||||
temp < inputL
|
||||
button 1
|
||||
end
|
||||
@@ -43,7 +43,7 @@
|
||||
},
|
||||
{
|
||||
"type": "h4",
|
||||
"title": "LittleFS version: 263"
|
||||
"title": "LittleFS version: 264"
|
||||
},
|
||||
{
|
||||
"type": "hr"
|
||||
@@ -87,8 +87,8 @@
|
||||
"style": "display:inline",
|
||||
"title": {
|
||||
"#": "Выберите пресет из списка<span class=\"caret\"></span>",
|
||||
"/set?addPreset=termostat.c": "1.Термостат на основе ds18b20 (устройство держит заданный уровень температуры)",
|
||||
"/set?addPreset=humstat.c": "2.Контроль влажности на основе DHT (устройство держит заданный уровень влажности)"
|
||||
"/set?addPreset=dal.c": "1.Термостат на основе ds18b20 (устройство держит заданный уровень температуры)",
|
||||
"/set?addPreset=dht.c": "2.Контроль влажности на основе DHT (устройство держит заданный уровень влажности)"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@@ -24,6 +24,7 @@ class LineParsing {
|
||||
String _int;
|
||||
String _cnt;
|
||||
String _val;
|
||||
String _index;
|
||||
|
||||
public:
|
||||
LineParsing() :
|
||||
@@ -44,7 +45,8 @@ class LineParsing {
|
||||
_type{""},
|
||||
_int{""},
|
||||
_cnt{""},
|
||||
_val{""}
|
||||
_val{""},
|
||||
_index{""}
|
||||
|
||||
{};
|
||||
|
||||
@@ -98,6 +100,9 @@ class LineParsing {
|
||||
if (arg.indexOf("val[") != -1) {
|
||||
_val = extractInner(arg);
|
||||
}
|
||||
if (arg.indexOf("index[") != -1) {
|
||||
_index = extractInner(arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,6 +166,10 @@ class LineParsing {
|
||||
String gval() {
|
||||
return _val;
|
||||
}
|
||||
String gindex() {
|
||||
return _index;
|
||||
}
|
||||
|
||||
|
||||
void clear() {
|
||||
_key = "";
|
||||
@@ -180,6 +189,7 @@ class LineParsing {
|
||||
_int = "";
|
||||
_cnt = "";
|
||||
_val = "";
|
||||
_index = "";
|
||||
}
|
||||
|
||||
String extractInnerDigit(String str) {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "Global.h"
|
||||
|
||||
class Scenario {
|
||||
protected:
|
||||
protected:
|
||||
String _scenarioTmp;
|
||||
String _condition;
|
||||
String _conditionParam;
|
||||
@@ -15,16 +15,16 @@ class Scenario {
|
||||
String _eventParam;
|
||||
String _eventValue;
|
||||
|
||||
public:
|
||||
Scenario() : _scenarioTmp{""},
|
||||
_condition{""},
|
||||
_conditionParam{""},
|
||||
_conditionSign{""},
|
||||
_conditionValue{""},
|
||||
_scenBlok{""},
|
||||
_event{""},
|
||||
_eventParam{""},
|
||||
_eventValue{""} {};
|
||||
public:
|
||||
Scenario() : _scenarioTmp{ "" },
|
||||
_condition{ "" },
|
||||
_conditionParam{ "" },
|
||||
_conditionSign{ "" },
|
||||
_conditionValue{ "" },
|
||||
_scenBlok{ "" },
|
||||
_event{ "" },
|
||||
_eventParam{ "" },
|
||||
_eventValue{ "" } {};
|
||||
|
||||
void load() {
|
||||
_scenarioTmp = scenario;
|
||||
@@ -69,22 +69,28 @@ class Scenario {
|
||||
|
||||
if (_conditionSign == "=") {
|
||||
flag = _eventValue == _conditionValue;
|
||||
} else if (_conditionSign == "!=") {
|
||||
}
|
||||
else if (_conditionSign == "!=") {
|
||||
flag = _eventValue != _conditionValue;
|
||||
} else if (_conditionSign == "<") {
|
||||
}
|
||||
else if (_conditionSign == "<") {
|
||||
flag = _eventValue.toFloat() < _conditionValue.toFloat();
|
||||
} else if (_conditionSign == ">") {
|
||||
}
|
||||
else if (_conditionSign == ">") {
|
||||
flag = _eventValue.toFloat() > _conditionValue.toFloat();
|
||||
} else if (_conditionSign == ">=") {
|
||||
}
|
||||
else if (_conditionSign == ">=") {
|
||||
flag = _eventValue.toFloat() >= _conditionValue.toFloat();
|
||||
} else if (_conditionSign == "<=") {
|
||||
}
|
||||
else if (_conditionSign == "<=") {
|
||||
flag = _eventValue.toFloat() <= _conditionValue.toFloat();
|
||||
}
|
||||
|
||||
Serial.println("event Value: " + _eventValue);
|
||||
Serial.println("cond Value: " + _conditionValue);
|
||||
|
||||
if (flag) Serial.println("I Scenario event: " + _condition);
|
||||
if (flag) {
|
||||
//SerialPrint("I", "Scenario", "event value: " + _eventValue);
|
||||
//SerialPrint("I", "Scenario", "condition value: " + _conditionValue);
|
||||
SerialPrint("I", "Scenario", "event: " + _condition);
|
||||
}
|
||||
|
||||
return flag;
|
||||
}
|
||||
@@ -100,7 +106,12 @@ class Scenario {
|
||||
this->calculate2();
|
||||
if (this->isConditionSatisfied()) { //если вошедшее событие выполняет условие сценария
|
||||
_scenBlok = deleteBeforeDelimiter(_scenBlok, "\n");
|
||||
Serial.println(" [>] Making: " + _scenBlok);
|
||||
String forPrint = _scenBlok;
|
||||
forPrint.replace("end", "");
|
||||
forPrint.replace("\r\n", "");
|
||||
forPrint.replace("\r", "");
|
||||
forPrint.replace("\n", "");
|
||||
SerialPrint("I", "Scenario", "making: " + forPrint);
|
||||
spaceCmdExecute(_scenBlok);
|
||||
}
|
||||
}
|
||||
@@ -113,4 +124,5 @@ class Scenario {
|
||||
return jsonReadBool(configSetupJson, "scen") && eventBuf != "";
|
||||
}
|
||||
};
|
||||
|
||||
extern Scenario* myScenario;
|
||||
@@ -3,7 +3,7 @@
|
||||
//===========Firmware=============================================================================================================================================
|
||||
#ifdef ESP8266
|
||||
#define FIRMWARE_NAME "esp8266-iotm"
|
||||
#define FIRMWARE_VERSION 263
|
||||
#define FIRMWARE_VERSION 264
|
||||
#endif
|
||||
#ifdef ESP32
|
||||
#define FIRMWARE_NAME "esp32-iotm"
|
||||
|
||||
@@ -71,7 +71,7 @@ extern int impulsEnterCounter;
|
||||
// Sensors
|
||||
extern String sensorReadingMap10sec;
|
||||
extern String sensorReadingMap30sec;
|
||||
extern int8_t dallasEnterCounter;
|
||||
|
||||
|
||||
extern String loggingKeyList;
|
||||
extern int enter_to_logging_counter;
|
||||
|
||||
@@ -10,26 +10,27 @@ class SensorDallas;
|
||||
typedef std::vector<SensorDallas> MySensorDallasVector;
|
||||
|
||||
class SensorDallas {
|
||||
public:
|
||||
public:
|
||||
|
||||
SensorDallas(unsigned long period,unsigned int pin, uint8_t deviceAddress, String key);
|
||||
SensorDallas(unsigned long interval, unsigned int pin, unsigned int index, String key);
|
||||
~SensorDallas();
|
||||
|
||||
void loop();
|
||||
void readDallas();
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
unsigned long currentMillis;
|
||||
unsigned long prevMillis;
|
||||
unsigned long _period;
|
||||
unsigned long _interval;
|
||||
String _key;
|
||||
unsigned int _pin;
|
||||
uint8_t _deviceAddress;
|
||||
|
||||
void readDallas();
|
||||
unsigned int _index;
|
||||
|
||||
};
|
||||
|
||||
extern MySensorDallasVector* mySensorDallas2;
|
||||
|
||||
extern void dallas();
|
||||
|
||||
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
#include "items/SensorConvertingClass.h"
|
||||
|
||||
extern DallasTemperature sensors;
|
||||
extern OneWire* oneWire;
|
||||
class SensorDallasClass : public SensorConvertingClass {
|
||||
public:
|
||||
SensorDallasClass() : SensorConvertingClass() {};
|
||||
|
||||
void SensorDallasInit() {
|
||||
oneWire = new OneWire((uint8_t)_pin.toInt());
|
||||
sensors.setOneWire(oneWire);
|
||||
sensors.begin();
|
||||
sensors.setResolution(48);
|
||||
|
||||
sensorReadingMap10sec += _key + ",";
|
||||
dallasEnterCounter++;
|
||||
|
||||
jsonWriteInt(configOptionJson, _key + "_num", dallasEnterCounter);
|
||||
jsonWriteStr(configOptionJson, _key + "_map", _map);
|
||||
jsonWriteStr(configOptionJson, _key + "_с", _c);
|
||||
}
|
||||
|
||||
void SensorDallasRead(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));
|
||||
publishStatus(key, String(valueFl));
|
||||
SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
extern SensorDallasClass mySensorDallas;
|
||||
@@ -42,7 +42,6 @@ int impulsEnterCounter = -1;
|
||||
|
||||
|
||||
// Sensors
|
||||
int8_t dallasEnterCounter = -1;
|
||||
String sensorReadingMap10sec;
|
||||
String sensorReadingMap30sec;
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "Global.h"
|
||||
#include "items/LoggingClass.h"
|
||||
#include "items/ImpulsOutClass.h"
|
||||
#include "items/SensorDallas.h"
|
||||
|
||||
void loadConfig() {
|
||||
configSetupJson = readFile("config.json", 4096);
|
||||
@@ -30,7 +31,10 @@ void Device_init() {
|
||||
|
||||
sensorReadingMap10sec = "";
|
||||
|
||||
dallasEnterCounter = -1;
|
||||
//======clear dallas params======
|
||||
if (mySensorDallas2 != nullptr) {
|
||||
mySensorDallas2->clear();
|
||||
}
|
||||
|
||||
//======clear logging params======
|
||||
if (myLogging != nullptr) {
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#include "Module/Terminal.h"
|
||||
#include "Servo/Servos.h"
|
||||
|
||||
#include "items/SensorDallas.h"
|
||||
|
||||
Terminal *term = nullptr;
|
||||
|
||||
boolean but[NUM_BUTTONS];
|
||||
@@ -31,7 +33,7 @@ void cmd_init() {
|
||||
|
||||
sCmd.addCommand("analog-adc", analogAdc);
|
||||
sCmd.addCommand("ultrasonic-cm", ultrasonicCm);
|
||||
sCmd.addCommand("dallas-temp", dallasTemp);
|
||||
sCmd.addCommand("dallas-temp", dallas);
|
||||
|
||||
sCmd.addCommand("dht-temp", dhtTemp);
|
||||
sCmd.addCommand("dht-hum", dhtHum);
|
||||
|
||||
@@ -55,12 +55,14 @@ void addItem(String name) {
|
||||
}
|
||||
|
||||
void addPreset(String name) {
|
||||
String preset = readFile("presets/" + name + ".txt", 2024);
|
||||
Serial.println(name);
|
||||
String preset = readFile("presets/" + name + ".txt", 4048);
|
||||
Serial.println(preset);
|
||||
addFile(DEVICE_CONFIG_FILE, "\n" + preset);
|
||||
|
||||
name.replace(".c",".s");
|
||||
|
||||
String scenario = readFile("presets/" + name + ".txt", 2024);
|
||||
String scenario = readFile("presets/" + name + ".txt", 4048);
|
||||
removeFile(DEVICE_SCENARIO_FILE);
|
||||
addFile(DEVICE_SCENARIO_FILE, scenario);
|
||||
}
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
#include "ItemsCmd.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
SensorDallas::SensorDallas(unsigned long period, unsigned int pin, uint8_t deviceAddress, String key) {
|
||||
_period = period * 1000;
|
||||
SensorDallas::SensorDallas(unsigned long interval, unsigned int pin, unsigned int index, String key) {
|
||||
_interval = interval * 1000;
|
||||
_key = key;
|
||||
_pin = pin;
|
||||
_deviceAddress = deviceAddress;
|
||||
_index = index;
|
||||
|
||||
oneWire = new OneWire((uint8_t)_pin);
|
||||
sensors.setOneWire(oneWire);
|
||||
@@ -21,32 +21,34 @@ SensorDallas::~SensorDallas() {}
|
||||
void SensorDallas::loop() {
|
||||
currentMillis = millis();
|
||||
unsigned long difference = currentMillis - prevMillis;
|
||||
if (difference >= _period) {
|
||||
if (difference >= _interval) {
|
||||
prevMillis = millis();
|
||||
|
||||
readDallas();
|
||||
}
|
||||
}
|
||||
|
||||
void readDallas() {
|
||||
|
||||
void SensorDallas::readDallas() {
|
||||
sensors.requestTemperaturesByIndex(_index);
|
||||
float value = sensors.getTempCByIndex(_index);
|
||||
eventGen(_key, "");
|
||||
jsonWriteStr(configLiveJson, _key, String(value));
|
||||
publishStatus(_key, String(value));
|
||||
SerialPrint("I", "Sensor", "'" + _key + "' data: " + String(value));
|
||||
}
|
||||
|
||||
|
||||
MySensorDallasVector* mySensorDallas2 = nullptr;
|
||||
|
||||
//void logging() {
|
||||
// myLineParsing.update();
|
||||
// String loggingValueKey = myLineParsing.gval();
|
||||
// String key = myLineParsing.gkey();
|
||||
// String interv = myLineParsing.gint();
|
||||
// String maxcnt = myLineParsing.gcnt();
|
||||
// myLineParsing.clear();
|
||||
//
|
||||
// loggingKeyList += key + ",";
|
||||
//
|
||||
// static bool firstTime = true;
|
||||
// if (firstTime) myLogging = new MySensorDallasVector();
|
||||
// firstTime = false;
|
||||
// myLogging->push_back(SensorDallas(interv.toInt(), maxcnt.toInt(), loggingValueKey, key));
|
||||
//}
|
||||
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,20 +0,0 @@
|
||||
#include "ItemsCmd.h"
|
||||
#include "items/SensorDallasClass.h"
|
||||
//#ifdef SensorDallasEnabled
|
||||
//=========================================Модуль ультрозвукового дальномера==================================================================
|
||||
//dallas-temp;id;anydata;Сенсоры;Температура;order;pin;c[1]
|
||||
//=========================================================================================================================================
|
||||
SensorDallasClass mySensorDallas;
|
||||
void dallasTemp() {
|
||||
mySensorDallas.update();
|
||||
String key = mySensorDallas.gkey();
|
||||
sCmd.addCommand(key.c_str(), dallasReading);
|
||||
mySensorDallas.SensorDallasInit();
|
||||
mySensorDallas.clear();
|
||||
}
|
||||
|
||||
void dallasReading() {
|
||||
String key = sCmd.order();
|
||||
mySensorDallas.SensorDallasRead(key);
|
||||
}
|
||||
//#endif
|
||||
14
src/main.cpp
14
src/main.cpp
@@ -16,8 +16,8 @@
|
||||
#include "Utils/WebUtils.h"
|
||||
#include "items/ButtonInClass.h"
|
||||
#include "items/LoggingClass.h"
|
||||
|
||||
#include "items/ImpulsOutClass.h"
|
||||
#include "items/SensorDallas.h"
|
||||
|
||||
void not_async_actions();
|
||||
|
||||
@@ -101,11 +101,7 @@ void setup() {
|
||||
just_load = false;
|
||||
initialized = true; //this second POST makes the data to be processed (you don't need to connect as "keep-alive" for that to work)
|
||||
|
||||
//static bool firstTime = true;
|
||||
//if (firstTime) myImpulsOut = new MyImpulsOutVector();
|
||||
//firstTime = false;
|
||||
//myImpulsOut->push_back(ImpulsOutClass(500, 10, 13));
|
||||
//myImpulsOut->at(0).execute();
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
@@ -139,4 +135,10 @@ void loop() {
|
||||
myImpulsOut->at(i).loop();
|
||||
}
|
||||
}
|
||||
|
||||
if (mySensorDallas2 != nullptr) {
|
||||
for (unsigned int i = 0; i < mySensorDallas2->size(); i++) {
|
||||
mySensorDallas2->at(i).loop();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user