264 stable. Dallas bug fixed!

This commit is contained in:
Dmitry Borisenko
2020-11-03 19:07:22 +03:00
parent aba00d9a70
commit c02abefb43
21 changed files with 114 additions and 136 deletions

View File

@@ -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
View 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
View File

@@ -0,0 +1,6 @@
temp > inputU
button 0
end
temp < inputL
button 1
end

View File

@@ -43,7 +43,7 @@
}, },
{ {
"type": "h4", "type": "h4",
"title": "LittleFS version: 263" "title": "LittleFS version: 264"
}, },
{ {
"type": "hr" "type": "hr"
@@ -87,8 +87,8 @@
"style": "display:inline", "style": "display:inline",
"title": { "title": {
"#": "Выберите пресет из списка<span class=\"caret\"></span>", "#": "Выберите пресет из списка<span class=\"caret\"></span>",
"/set?addPreset=termostat.c": "1.Термостат на основе ds18b20 (устройство держит заданный уровень температуры)", "/set?addPreset=dal.c": "1.Термостат на основе ds18b20 (устройство держит заданный уровень температуры)",
"/set?addPreset=humstat.c": "2.Контроль влажности на основе DHT (устройство держит заданный уровень влажности)" "/set?addPreset=dht.c": "2.Контроль влажности на основе DHT (устройство держит заданный уровень влажности)"
} }
}, },
{ {

View File

@@ -24,6 +24,7 @@ class LineParsing {
String _int; String _int;
String _cnt; String _cnt;
String _val; String _val;
String _index;
public: public:
LineParsing() : LineParsing() :
@@ -44,7 +45,8 @@ class LineParsing {
_type{""}, _type{""},
_int{""}, _int{""},
_cnt{""}, _cnt{""},
_val{""} _val{""},
_index{""}
{}; {};
@@ -98,6 +100,9 @@ class LineParsing {
if (arg.indexOf("val[") != -1) { if (arg.indexOf("val[") != -1) {
_val = extractInner(arg); _val = extractInner(arg);
} }
if (arg.indexOf("index[") != -1) {
_index = extractInner(arg);
}
} }
} }
@@ -161,6 +166,10 @@ class LineParsing {
String gval() { String gval() {
return _val; return _val;
} }
String gindex() {
return _index;
}
void clear() { void clear() {
_key = ""; _key = "";
@@ -180,6 +189,7 @@ class LineParsing {
_int = ""; _int = "";
_cnt = ""; _cnt = "";
_val = ""; _val = "";
_index = "";
} }
String extractInnerDigit(String str) { String extractInnerDigit(String str) {

View File

@@ -4,7 +4,7 @@
#include "Global.h" #include "Global.h"
class Scenario { class Scenario {
protected: protected:
String _scenarioTmp; String _scenarioTmp;
String _condition; String _condition;
String _conditionParam; String _conditionParam;
@@ -15,16 +15,16 @@ class Scenario {
String _eventParam; String _eventParam;
String _eventValue; String _eventValue;
public: public:
Scenario() : _scenarioTmp{""}, Scenario() : _scenarioTmp{ "" },
_condition{""}, _condition{ "" },
_conditionParam{""}, _conditionParam{ "" },
_conditionSign{""}, _conditionSign{ "" },
_conditionValue{""}, _conditionValue{ "" },
_scenBlok{""}, _scenBlok{ "" },
_event{""}, _event{ "" },
_eventParam{""}, _eventParam{ "" },
_eventValue{""} {}; _eventValue{ "" } {};
void load() { void load() {
_scenarioTmp = scenario; _scenarioTmp = scenario;
@@ -69,22 +69,28 @@ class Scenario {
if (_conditionSign == "=") { if (_conditionSign == "=") {
flag = _eventValue == _conditionValue; flag = _eventValue == _conditionValue;
} else if (_conditionSign == "!=") { }
else if (_conditionSign == "!=") {
flag = _eventValue != _conditionValue; flag = _eventValue != _conditionValue;
} else if (_conditionSign == "<") { }
else if (_conditionSign == "<") {
flag = _eventValue.toFloat() < _conditionValue.toFloat(); flag = _eventValue.toFloat() < _conditionValue.toFloat();
} else if (_conditionSign == ">") { }
else if (_conditionSign == ">") {
flag = _eventValue.toFloat() > _conditionValue.toFloat(); flag = _eventValue.toFloat() > _conditionValue.toFloat();
} else if (_conditionSign == ">=") { }
else if (_conditionSign == ">=") {
flag = _eventValue.toFloat() >= _conditionValue.toFloat(); flag = _eventValue.toFloat() >= _conditionValue.toFloat();
} else if (_conditionSign == "<=") { }
else if (_conditionSign == "<=") {
flag = _eventValue.toFloat() <= _conditionValue.toFloat(); flag = _eventValue.toFloat() <= _conditionValue.toFloat();
} }
Serial.println("event Value: " + _eventValue); if (flag) {
Serial.println("cond Value: " + _conditionValue); //SerialPrint("I", "Scenario", "event value: " + _eventValue);
//SerialPrint("I", "Scenario", "condition value: " + _conditionValue);
if (flag) Serial.println("I Scenario event: " + _condition); SerialPrint("I", "Scenario", "event: " + _condition);
}
return flag; return flag;
} }
@@ -100,7 +106,12 @@ class Scenario {
this->calculate2(); this->calculate2();
if (this->isConditionSatisfied()) { //если вошедшее событие выполняет условие сценария if (this->isConditionSatisfied()) { //если вошедшее событие выполняет условие сценария
_scenBlok = deleteBeforeDelimiter(_scenBlok, "\n"); _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); spaceCmdExecute(_scenBlok);
} }
} }
@@ -113,4 +124,5 @@ class Scenario {
return jsonReadBool(configSetupJson, "scen") && eventBuf != ""; return jsonReadBool(configSetupJson, "scen") && eventBuf != "";
} }
}; };
extern Scenario* myScenario; extern Scenario* myScenario;

View File

@@ -3,7 +3,7 @@
//===========Firmware============================================================================================================================================= //===========Firmware=============================================================================================================================================
#ifdef ESP8266 #ifdef ESP8266
#define FIRMWARE_NAME "esp8266-iotm" #define FIRMWARE_NAME "esp8266-iotm"
#define FIRMWARE_VERSION 263 #define FIRMWARE_VERSION 264
#endif #endif
#ifdef ESP32 #ifdef ESP32
#define FIRMWARE_NAME "esp32-iotm" #define FIRMWARE_NAME "esp32-iotm"

View File

@@ -71,7 +71,7 @@ extern int impulsEnterCounter;
// Sensors // Sensors
extern String sensorReadingMap10sec; extern String sensorReadingMap10sec;
extern String sensorReadingMap30sec; extern String sensorReadingMap30sec;
extern int8_t dallasEnterCounter;
extern String loggingKeyList; extern String loggingKeyList;
extern int enter_to_logging_counter; extern int enter_to_logging_counter;

View File

@@ -10,26 +10,27 @@ class SensorDallas;
typedef std::vector<SensorDallas> MySensorDallasVector; typedef std::vector<SensorDallas> MySensorDallasVector;
class SensorDallas { 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(); ~SensorDallas();
void loop(); void loop();
void readDallas();
private: private:
unsigned long currentMillis; unsigned long currentMillis;
unsigned long prevMillis; unsigned long prevMillis;
unsigned long _period; unsigned long _interval;
String _key; String _key;
unsigned int _pin; unsigned int _pin;
uint8_t _deviceAddress; unsigned int _index;
void readDallas();
}; };
extern MySensorDallasVector* mySensorDallas2; extern MySensorDallasVector* mySensorDallas2;
extern void dallas();

View File

@@ -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;

View File

@@ -42,7 +42,6 @@ int impulsEnterCounter = -1;
// Sensors // Sensors
int8_t dallasEnterCounter = -1;
String sensorReadingMap10sec; String sensorReadingMap10sec;
String sensorReadingMap30sec; String sensorReadingMap30sec;

View File

@@ -4,6 +4,7 @@
#include "Global.h" #include "Global.h"
#include "items/LoggingClass.h" #include "items/LoggingClass.h"
#include "items/ImpulsOutClass.h" #include "items/ImpulsOutClass.h"
#include "items/SensorDallas.h"
void loadConfig() { void loadConfig() {
configSetupJson = readFile("config.json", 4096); configSetupJson = readFile("config.json", 4096);
@@ -30,7 +31,10 @@ void Device_init() {
sensorReadingMap10sec = ""; sensorReadingMap10sec = "";
dallasEnterCounter = -1; //======clear dallas params======
if (mySensorDallas2 != nullptr) {
mySensorDallas2->clear();
}
//======clear logging params====== //======clear logging params======
if (myLogging != nullptr) { if (myLogging != nullptr) {

View File

@@ -7,6 +7,8 @@
#include "Module/Terminal.h" #include "Module/Terminal.h"
#include "Servo/Servos.h" #include "Servo/Servos.h"
#include "items/SensorDallas.h"
Terminal *term = nullptr; Terminal *term = nullptr;
boolean but[NUM_BUTTONS]; boolean but[NUM_BUTTONS];
@@ -31,7 +33,7 @@ void cmd_init() {
sCmd.addCommand("analog-adc", analogAdc); sCmd.addCommand("analog-adc", analogAdc);
sCmd.addCommand("ultrasonic-cm", ultrasonicCm); sCmd.addCommand("ultrasonic-cm", ultrasonicCm);
sCmd.addCommand("dallas-temp", dallasTemp); sCmd.addCommand("dallas-temp", dallas);
sCmd.addCommand("dht-temp", dhtTemp); sCmd.addCommand("dht-temp", dhtTemp);
sCmd.addCommand("dht-hum", dhtHum); sCmd.addCommand("dht-hum", dhtHum);

View File

@@ -55,12 +55,14 @@ void addItem(String name) {
} }
void addPreset(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); addFile(DEVICE_CONFIG_FILE, "\n" + preset);
name.replace(".c",".s"); name.replace(".c",".s");
String scenario = readFile("presets/" + name + ".txt", 2024); String scenario = readFile("presets/" + name + ".txt", 4048);
removeFile(DEVICE_SCENARIO_FILE); removeFile(DEVICE_SCENARIO_FILE);
addFile(DEVICE_SCENARIO_FILE, scenario); addFile(DEVICE_SCENARIO_FILE, scenario);
} }

View File

@@ -4,11 +4,11 @@
#include "ItemsCmd.h" #include "ItemsCmd.h"
#include <Arduino.h> #include <Arduino.h>
SensorDallas::SensorDallas(unsigned long period, unsigned int pin, uint8_t deviceAddress, String key) { SensorDallas::SensorDallas(unsigned long interval, unsigned int pin, unsigned int index, String key) {
_period = period * 1000; _interval = interval * 1000;
_key = key; _key = key;
_pin = pin; _pin = pin;
_deviceAddress = deviceAddress; _index = index;
oneWire = new OneWire((uint8_t)_pin); oneWire = new OneWire((uint8_t)_pin);
sensors.setOneWire(oneWire); sensors.setOneWire(oneWire);
@@ -21,32 +21,34 @@ SensorDallas::~SensorDallas() {}
void SensorDallas::loop() { void SensorDallas::loop() {
currentMillis = millis(); currentMillis = millis();
unsigned long difference = currentMillis - prevMillis; unsigned long difference = currentMillis - prevMillis;
if (difference >= _period) { if (difference >= _interval) {
prevMillis = millis(); 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; MySensorDallasVector* mySensorDallas2 = nullptr;
//void logging() { void dallas() {
// myLineParsing.update(); myLineParsing.update();
// String loggingValueKey = myLineParsing.gval(); String interval = myLineParsing.gint();
// String key = myLineParsing.gkey(); String pin = myLineParsing.gpin();
// String interv = myLineParsing.gint(); String index = myLineParsing.gindex();
// String maxcnt = myLineParsing.gcnt(); String key = myLineParsing.gkey();
// myLineParsing.clear(); myLineParsing.clear();
//
// loggingKeyList += key + ","; static bool firstTime = true;
// if (firstTime) mySensorDallas2 = new MySensorDallasVector();
// static bool firstTime = true; firstTime = false;
// if (firstTime) myLogging = new MySensorDallasVector(); mySensorDallas2->push_back(SensorDallas(interval.toInt(), pin.toInt(), index.toInt(), key));
// firstTime = false; }
// myLogging->push_back(SensorDallas(interv.toInt(), maxcnt.toInt(), loggingValueKey, key));
//}

View File

@@ -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

View File

@@ -16,8 +16,8 @@
#include "Utils/WebUtils.h" #include "Utils/WebUtils.h"
#include "items/ButtonInClass.h" #include "items/ButtonInClass.h"
#include "items/LoggingClass.h" #include "items/LoggingClass.h"
#include "items/ImpulsOutClass.h" #include "items/ImpulsOutClass.h"
#include "items/SensorDallas.h"
void not_async_actions(); void not_async_actions();
@@ -101,11 +101,7 @@ void setup() {
just_load = false; 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) 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() { void loop() {
@@ -139,4 +135,10 @@ void loop() {
myImpulsOut->at(i).loop(); myImpulsOut->at(i).loop();
} }
} }
if (mySensorDallas2 != nullptr) {
for (unsigned int i = 0; i < mySensorDallas2->size(); i++) {
mySensorDallas2->at(i).loop();
}
}
} }