mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 11:59:12 +03:00
@@ -3,8 +3,8 @@
|
|||||||
"chipID": "",
|
"chipID": "",
|
||||||
"apssid": "IoTmanager",
|
"apssid": "IoTmanager",
|
||||||
"appass": "",
|
"appass": "",
|
||||||
"routerssid": "VOLODYA",
|
"routerssid": "rise",
|
||||||
"routerpass": "BELCHENKO",
|
"routerpass": "hostel3333",
|
||||||
"timezone": 2,
|
"timezone": 2,
|
||||||
"ntp": "pool.ntp.org",
|
"ntp": "pool.ntp.org",
|
||||||
"mqttServer": "91.204.228.124",
|
"mqttServer": "91.204.228.124",
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
"weblogin": "admin",
|
"weblogin": "admin",
|
||||||
"webpass": "admin",
|
"webpass": "admin",
|
||||||
"udponoff": "1",
|
"udponoff": "1",
|
||||||
"blink": "0",
|
"blink": "1",
|
||||||
"oneWirePin": "2",
|
"oneWirePin": "2",
|
||||||
"serverip": "http://206.189.49.244"
|
"serverip": "http://206.189.49.244"
|
||||||
}
|
}
|
||||||
@@ -1 +1 @@
|
|||||||
0;button-out;id;toggleSunMoon;Кнопки;Освещение;order;st[0]
|
0;button-out;id;toggle;Кнопки;Освещение;order;st[0]
|
||||||
@@ -1 +1 @@
|
|||||||
0;dallas-temp;id;anydataTemp;Сенсоры;Температура;order;sal;c[1]
|
0;dallas-temp;id;anydataTemp;Сенсоры;Температура;order;sal;index[0];int[10]
|
||||||
1
data/items/impuls-out.txt
Normal file
1
data/items/impuls-out.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
0;impuls-out;id;na;na;na;order;pin
|
||||||
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
|
||||||
5
data/presets/dht.c.txt
Normal file
5
data/presets/dht.c.txt
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
0;dht-hum;hum;anydataHum;Теплица;Влажность;1;pin[2];type[dht11];c[1]
|
||||||
|
0;logging;log;chart;Теплица;Влажность;2;val[hum];int[60];cnt[100]
|
||||||
|
0;input-digit;inputU;inputDigit;Теплица;Верхний#порог;3;st[45]
|
||||||
|
0;input-digit;inputL;inputDigit;Теплица;Нижний#порог;4;st[35]
|
||||||
|
0;button-out;button;toggle;Теплица;Полив;5;pin[12];st[0]
|
||||||
6
data/presets/dht.s.txt
Normal file
6
data/presets/dht.s.txt
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
hum > inputU
|
||||||
|
button 0
|
||||||
|
end
|
||||||
|
hum < inputL
|
||||||
|
button 1
|
||||||
|
end
|
||||||
@@ -43,14 +43,14 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "h4",
|
"type": "h4",
|
||||||
"title": "LittleFS version: 262"
|
"title": "LittleFS version: 264"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "hr"
|
"type": "hr"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "dropdown",
|
"type": "dropdown",
|
||||||
"name": "help-url",
|
"name": "help-url1",
|
||||||
"class": "btn btn-default",
|
"class": "btn btn-default",
|
||||||
"style": "display:inline",
|
"style": "display:inline",
|
||||||
"title": {
|
"title": {
|
||||||
@@ -74,12 +74,23 @@
|
|||||||
"/set?addItem=bme280-press": "17.Датчик давления bme280",
|
"/set?addItem=bme280-press": "17.Датчик давления bme280",
|
||||||
"/set?addItem=bmp280-temp": "18.Датчик температуры bmp280",
|
"/set?addItem=bmp280-temp": "18.Датчик температуры bmp280",
|
||||||
"/set?addItem=bmp280-press": "19.Датчик давления bmp280",
|
"/set?addItem=bmp280-press": "19.Датчик давления bmp280",
|
||||||
"/set?addItem=modbus": "20.Прочитать регистр modbus устройства",
|
"/set?addItem=impuls-out": "20.Создать импульсы через заданный промежуток времени (управление шд)",
|
||||||
|
"/set?addItem=modbus": "21.Прочитать регистр modbus устройства",
|
||||||
"/set?addItem=logging": "a.Логгирование и вывод в график любой величины",
|
"/set?addItem=logging": "a.Логгирование и вывод в график любой величины",
|
||||||
"/set?addItem=uptime": "b.Отобразить время работы устройства"
|
"/set?addItem=uptime": "b.Отобразить время работы устройства"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "dropdown",
|
||||||
|
"name": "help-url2",
|
||||||
|
"class": "btn btn-default",
|
||||||
|
"style": "display:inline",
|
||||||
|
"title": {
|
||||||
|
"#": "Выберите пресет из списка<span class=\"caret\"></span>",
|
||||||
|
"/set?addPreset=dal.c": "1.Термостат на основе ds18b20 (устройство держит заданный уровень температуры)",
|
||||||
|
"/set?addPreset=dht.c": "2.Контроль влажности на основе DHT (устройство держит заданный уровень влажности)"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "hr"
|
"type": "hr"
|
||||||
},
|
},
|
||||||
@@ -116,7 +127,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "text",
|
"type": "text",
|
||||||
"title": "<div style='margin-top:10px;margin-bottom:10px;'><font color='black'><p style='border: 1px solid #DCDCDC; border-radius: 3px; background-color: #F5F5F5; padding: 10px;'>После любого изменения таблицы элементов, включая удаление/добавление строк, необходимо нажать кнопку <b>СОХРАНИТЬ ТАБЛИЦУ</b></p></font></div>"
|
"title": "<div style='margin-top:10px;margin-bottom:10px;'><font color='black'><p style='border: 1px solid #DCDCDC; border-radius: 3px; background-color: #F5F5F5; padding: 10px;'>После любого изменения таблицы элементов, включая удаление/добавление строк, необходимо нажать кнопку <b>СОХРАНИТЬ ТАБЛИЦУ</b>. Иногда, для корректной работы необходимо перезагрузить устройство после финального завершения его настройки</p></font></div>"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "h2",
|
"type": "h2",
|
||||||
|
|||||||
@@ -6,3 +6,5 @@ extern void fileCmdExecute(const String &filename);
|
|||||||
extern void csvCmdExecute(String& cmdStr);
|
extern void csvCmdExecute(String& cmdStr);
|
||||||
extern void spaceCmdExecute(String& cmdStr);
|
extern void spaceCmdExecute(String& cmdStr);
|
||||||
extern void loopCmdExecute();
|
extern void loopCmdExecute();
|
||||||
|
extern void addKey(String& key, String& keyNumberTable, int number);
|
||||||
|
extern int getKeyNum(String& key, String& keyNumberTable);
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,12 +160,16 @@ class LineParsing {
|
|||||||
String gint() {
|
String gint() {
|
||||||
return _int;
|
return _int;
|
||||||
}
|
}
|
||||||
String gmaxcnt() {
|
String gcnt() {
|
||||||
return _cnt;
|
return _cnt;
|
||||||
}
|
}
|
||||||
String gvalue() {
|
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) {
|
||||||
|
|||||||
@@ -69,19 +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 == "<") {
|
}
|
||||||
flag = _eventValue.toInt() < _conditionValue.toInt();
|
else if (_conditionSign == "<") {
|
||||||
} else if (_conditionSign == ">") {
|
flag = _eventValue.toFloat() < _conditionValue.toFloat();
|
||||||
flag = _eventValue.toInt() > _conditionValue.toInt();
|
}
|
||||||
} else if (_conditionSign == ">=") {
|
else if (_conditionSign == ">") {
|
||||||
flag = _eventValue.toInt() >= _conditionValue.toInt();
|
flag = _eventValue.toFloat() > _conditionValue.toFloat();
|
||||||
} else if (_conditionSign == "<=") {
|
}
|
||||||
flag = _eventValue.toInt() <= _conditionValue.toInt();
|
else if (_conditionSign == ">=") {
|
||||||
|
flag = _eventValue.toFloat() >= _conditionValue.toFloat();
|
||||||
|
}
|
||||||
|
else if (_conditionSign == "<=") {
|
||||||
|
flag = _eventValue.toFloat() <= _conditionValue.toFloat();
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
return flag;
|
||||||
}
|
}
|
||||||
@@ -97,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -110,4 +124,5 @@ class Scenario {
|
|||||||
return jsonReadBool(configSetupJson, "scen") && eventBuf != "";
|
return jsonReadBool(configSetupJson, "scen") && eventBuf != "";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
extern Scenario* myScenario;
|
extern Scenario* myScenario;
|
||||||
@@ -1,45 +1,32 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
//
|
//===========Firmware=============================================================================================================================================
|
||||||
// Firmware
|
|
||||||
//
|
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
#define FIRMWARE_NAME "esp8266-iotm"
|
#define FIRMWARE_NAME "esp8266-iotm"
|
||||||
#define FIRMWARE_VERSION 262
|
#define FIRMWARE_VERSION 264
|
||||||
#endif
|
#endif
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
#define FIRMWARE_NAME "esp32-iotm"
|
#define FIRMWARE_NAME "esp32-iotm"
|
||||||
#define FIRMWARE_VERSION 259
|
#define FIRMWARE_VERSION 259
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define FLASH_4MB true
|
#define FLASH_4MB true
|
||||||
|
|
||||||
//
|
//===========FSystem==============================================================================================================================================
|
||||||
// System
|
|
||||||
//
|
|
||||||
#define NUM_BUTTONS 6
|
#define NUM_BUTTONS 6
|
||||||
#define LED_PIN 2
|
#define LED_PIN 2
|
||||||
|
|
||||||
//
|
//===========MQTT=================================================================================================================================================
|
||||||
// MQTT
|
|
||||||
//
|
|
||||||
#define MQTT_RECONNECT_INTERVAL 20000
|
#define MQTT_RECONNECT_INTERVAL 20000
|
||||||
|
|
||||||
//
|
//==========Telemetry=============================================================================================================================================
|
||||||
// Telemetry
|
|
||||||
//
|
|
||||||
#define TELEMETRY_UPDATE_INTERVAL_MIN 60
|
#define TELEMETRY_UPDATE_INTERVAL_MIN 60
|
||||||
|
|
||||||
|
//=========Configuration==========================================================================================================================================
|
||||||
//
|
|
||||||
// Configuration
|
|
||||||
//
|
|
||||||
#define DEVICE_CONFIG_FILE "s.conf.csv"
|
#define DEVICE_CONFIG_FILE "s.conf.csv"
|
||||||
#define DEVICE_SCENARIO_FILE "s.scen.txt"
|
#define DEVICE_SCENARIO_FILE "s.scen.txt"
|
||||||
|
|
||||||
//
|
|
||||||
// System parts
|
//=========System parts===========================================================================================================================================
|
||||||
//
|
|
||||||
//#define OTA_UPDATES_ENABLED
|
//#define OTA_UPDATES_ENABLED
|
||||||
//#define MDNS_ENABLED
|
//#define MDNS_ENABLED
|
||||||
//#define WEBSOCKET_ENABLED
|
//#define WEBSOCKET_ENABLED
|
||||||
@@ -47,9 +34,7 @@
|
|||||||
//#define UDP_ENABLED
|
//#define UDP_ENABLED
|
||||||
//#define SSDP_ENABLED
|
//#define SSDP_ENABLED
|
||||||
|
|
||||||
//
|
//=========Sensors enable/disable=================================================================================================================================
|
||||||
// Sensors enable/disable
|
|
||||||
//
|
|
||||||
#define TANK_LEVEL_SAMPLES 10
|
#define TANK_LEVEL_SAMPLES 10
|
||||||
#define LEVEL_ENABLED
|
#define LEVEL_ENABLED
|
||||||
#define ANALOG_ENABLED
|
#define ANALOG_ENABLED
|
||||||
@@ -58,15 +43,13 @@
|
|||||||
#define BMP_ENABLED
|
#define BMP_ENABLED
|
||||||
#define BME_ENABLED
|
#define BME_ENABLED
|
||||||
|
|
||||||
//
|
|
||||||
// Gears enable/disable
|
//=========Gears enable/disable===================================================================================================================================
|
||||||
//
|
|
||||||
#define STEPPER_ENABLED
|
#define STEPPER_ENABLED
|
||||||
#define SERVO_ENABLED
|
#define SERVO_ENABLED
|
||||||
|
|
||||||
//
|
|
||||||
// Other enable/disable
|
//========Other enable/disable====================================================================================================================================
|
||||||
//
|
|
||||||
#define LOGGING_ENABLED
|
#define LOGGING_ENABLED
|
||||||
#define SERIAL_ENABLED
|
#define SERIAL_ENABLED
|
||||||
#define PUSH_ENABLED
|
#define PUSH_ENABLED
|
||||||
@@ -84,6 +67,7 @@ struct Time_t {
|
|||||||
unsigned long valid;
|
unsigned long valid;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//================================================================================================================================================================
|
||||||
enum TimerTask_t { WIFI_SCAN,
|
enum TimerTask_t { WIFI_SCAN,
|
||||||
WIFI_MQTT_CONNECTION_CHECK,
|
WIFI_MQTT_CONNECTION_CHECK,
|
||||||
SENSORS10SEC,
|
SENSORS10SEC,
|
||||||
|
|||||||
@@ -40,8 +40,7 @@ extern WiFiClient espClient;
|
|||||||
extern PubSubClient mqtt;
|
extern PubSubClient mqtt;
|
||||||
extern StringCommand sCmd;
|
extern StringCommand sCmd;
|
||||||
extern AsyncWebServer server;
|
extern AsyncWebServer server;
|
||||||
extern DallasTemperature sensors;
|
|
||||||
extern OneWire* oneWire;
|
|
||||||
extern boolean but[NUM_BUTTONS];
|
extern boolean but[NUM_BUTTONS];
|
||||||
extern Bounce* buttons;
|
extern Bounce* buttons;
|
||||||
|
|
||||||
@@ -65,23 +64,20 @@ extern String eventBuf;
|
|||||||
extern String itemsFile;
|
extern String itemsFile;
|
||||||
extern String itemsLine;
|
extern String itemsLine;
|
||||||
|
|
||||||
|
//key lists and numbers
|
||||||
|
extern String impulsKeyList;
|
||||||
|
extern int impulsEnterCounter;
|
||||||
|
|
||||||
// Sensors
|
// Sensors
|
||||||
extern String sensorReadingMap10sec;
|
extern String sensorReadingMap10sec;
|
||||||
extern String sensorReadingMap30sec;
|
extern String sensorReadingMap30sec;
|
||||||
extern int8_t dallasEnterCounter;
|
|
||||||
|
|
||||||
extern String logging_value_names_list;
|
|
||||||
|
extern String loggingKeyList;
|
||||||
extern int enter_to_logging_counter;
|
extern int enter_to_logging_counter;
|
||||||
extern int scenario_line_status[40];
|
extern int scenario_line_status[40];
|
||||||
extern int lastVersion;
|
extern int lastVersion;
|
||||||
|
|
||||||
//Global functions
|
|
||||||
// Logging
|
|
||||||
extern void logging();
|
|
||||||
extern void deleteOldDate(String filename, size_t max_lines, String date_to_add);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Main
|
// Main
|
||||||
extern void setChipId();
|
extern void setChipId();
|
||||||
extern void saveConfig();
|
extern void saveConfig();
|
||||||
|
|||||||
@@ -51,3 +51,5 @@ extern void sysUptime();
|
|||||||
extern void uptimeReading();
|
extern void uptimeReading();
|
||||||
|
|
||||||
extern void logging();
|
extern void logging();
|
||||||
|
|
||||||
|
extern void impuls();
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
extern void itemsListInit();
|
extern void itemsListInit();
|
||||||
extern void addItem(String name);
|
extern void addItem(String name);
|
||||||
|
extern void addPreset(String name);
|
||||||
extern void delChoosingItems();
|
extern void delChoosingItems();
|
||||||
extern void delAllItems();
|
extern void delAllItems();
|
||||||
extern uint8_t getNewElementNumber(String file);
|
extern uint8_t getNewElementNumber(String file);
|
||||||
|
|||||||
@@ -28,7 +28,8 @@ class ButtonOutClass : public LineParsing {
|
|||||||
|
|
||||||
if (inv == "") {
|
if (inv == "") {
|
||||||
digitalWrite(pinInt, state.toInt());
|
digitalWrite(pinInt, state.toInt());
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
digitalWrite(pinInt, !state.toInt());
|
digitalWrite(pinInt, !state.toInt());
|
||||||
}
|
}
|
||||||
eventGen(key, "");
|
eventGen(key, "");
|
||||||
|
|||||||
31
include/items/ImpulsOutClass.h
Normal file
31
include/items/ImpulsOutClass.h
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
#include "Global.h"
|
||||||
|
|
||||||
|
class ImpulsOutClass;
|
||||||
|
|
||||||
|
typedef std::vector<ImpulsOutClass> MyImpulsOutVector;
|
||||||
|
|
||||||
|
class ImpulsOutClass {
|
||||||
|
public:
|
||||||
|
ImpulsOutClass(unsigned int impulsPin);
|
||||||
|
~ImpulsOutClass();
|
||||||
|
|
||||||
|
void loop();
|
||||||
|
void execute(unsigned long impulsPeriod, unsigned int impulsCount);
|
||||||
|
|
||||||
|
private:
|
||||||
|
unsigned long currentMillis;
|
||||||
|
unsigned long prevMillis;
|
||||||
|
|
||||||
|
unsigned long _impulsPeriod = 0;
|
||||||
|
unsigned int _impulsCount = 0;
|
||||||
|
unsigned int _impulsCountBuf = 0;
|
||||||
|
unsigned int _impulsPin = 0;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
extern MyImpulsOutVector* myImpulsOut;
|
||||||
|
|
||||||
|
extern void impulsExecute();
|
||||||
36
include/items/SensorDallas.h
Normal file
36
include/items/SensorDallas.h
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "Global.h"
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
extern DallasTemperature sensors;
|
||||||
|
extern OneWire* oneWire;
|
||||||
|
|
||||||
|
class SensorDallas;
|
||||||
|
|
||||||
|
typedef std::vector<SensorDallas> MySensorDallasVector;
|
||||||
|
|
||||||
|
class SensorDallas {
|
||||||
|
public:
|
||||||
|
|
||||||
|
SensorDallas(unsigned long interval, unsigned int pin, unsigned int index, String key);
|
||||||
|
~SensorDallas();
|
||||||
|
|
||||||
|
void loop();
|
||||||
|
void readDallas();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
unsigned long currentMillis;
|
||||||
|
unsigned long prevMillis;
|
||||||
|
unsigned long _interval;
|
||||||
|
String _key;
|
||||||
|
unsigned int _pin;
|
||||||
|
unsigned int _index;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
extern MySensorDallasVector* mySensorDallas2;
|
||||||
|
|
||||||
|
extern void dallas();
|
||||||
|
|
||||||
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <Arduino.h>
|
|
||||||
#include "Class/LineParsing.h"
|
|
||||||
#include "Global.h"
|
|
||||||
#include "items/SensorConvertingClass.h"
|
|
||||||
|
|
||||||
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;
|
|
||||||
@@ -74,3 +74,21 @@ void sensorsInit() {
|
|||||||
nullptr, true);
|
nullptr, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void addKey(String& key, String& keyNumberTable, int number) {
|
||||||
|
keyNumberTable += key + " " + String(number) + ",";
|
||||||
|
}
|
||||||
|
|
||||||
|
int getKeyNum(String& key, String& keyNumberTable) {
|
||||||
|
String keyNumberTableBuf = keyNumberTable;
|
||||||
|
//SerialPrint("","",keyNumberTable);
|
||||||
|
int number = -1;
|
||||||
|
while (keyNumberTableBuf.length()) {
|
||||||
|
String tmp = selectToMarker(keyNumberTableBuf, ",");
|
||||||
|
String keyIncomming = selectToMarker(tmp, " ");
|
||||||
|
if (keyIncomming == key) {
|
||||||
|
number = selectToMarkerLast(tmp, " ").toInt();
|
||||||
|
}
|
||||||
|
keyNumberTableBuf = deleteBeforeDelimiter(keyNumberTableBuf, ",");
|
||||||
|
}
|
||||||
|
return number;
|
||||||
|
}
|
||||||
|
|||||||
@@ -33,17 +33,20 @@ String scenario = "";
|
|||||||
//orders and events
|
//orders and events
|
||||||
String orderBuf = "";
|
String orderBuf = "";
|
||||||
String eventBuf = "";
|
String eventBuf = "";
|
||||||
|
|
||||||
String itemsFile = "";
|
String itemsFile = "";
|
||||||
String itemsLine = "";
|
String itemsLine = "";
|
||||||
|
|
||||||
|
//key lists and numbers
|
||||||
|
String impulsKeyList = "";
|
||||||
|
int impulsEnterCounter = -1;
|
||||||
|
|
||||||
|
|
||||||
// Sensors
|
// Sensors
|
||||||
int8_t dallasEnterCounter = -1;
|
|
||||||
String sensorReadingMap10sec;
|
String sensorReadingMap10sec;
|
||||||
String sensorReadingMap30sec;
|
String sensorReadingMap30sec;
|
||||||
|
|
||||||
// Logging
|
// Logging
|
||||||
String logging_value_names_list;
|
String loggingKeyList;
|
||||||
int enter_to_logging_counter;
|
int enter_to_logging_counter;
|
||||||
|
|
||||||
// Upgrade
|
// Upgrade
|
||||||
|
|||||||
43
src/Init.cpp
43
src/Init.cpp
@@ -1,8 +1,10 @@
|
|||||||
#include "Init.h"
|
#include "Init.h"
|
||||||
|
#include "BufferExecute.h"
|
||||||
#include "Cmd.h"
|
#include "Cmd.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include "items/LoggingClass.h"
|
#include "items/LoggingClass.h"
|
||||||
|
#include "items/ImpulsOutClass.h"
|
||||||
|
#include "items/SensorDallas.h"
|
||||||
|
|
||||||
void loadConfig() {
|
void loadConfig() {
|
||||||
configSetupJson = readFile("config.json", 4096);
|
configSetupJson = readFile("config.json", 4096);
|
||||||
@@ -26,36 +28,27 @@ void all_init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Device_init() {
|
void Device_init() {
|
||||||
|
|
||||||
sensorReadingMap10sec = "";
|
sensorReadingMap10sec = "";
|
||||||
dallasEnterCounter = -1;
|
|
||||||
|
//======clear dallas params======
|
||||||
|
if (mySensorDallas2 != nullptr) {
|
||||||
|
mySensorDallas2->clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
//======clear logging params======
|
||||||
if (myLogging != nullptr) {
|
if (myLogging != nullptr) {
|
||||||
myLogging->clear();
|
myLogging->clear();
|
||||||
}
|
}
|
||||||
logging_value_names_list = "";
|
loggingKeyList = "";
|
||||||
|
|
||||||
|
//======clear impuls params=======
|
||||||
|
if (myImpulsOut != nullptr) {
|
||||||
|
myImpulsOut->clear();
|
||||||
|
}
|
||||||
|
impulsKeyList = "";
|
||||||
|
impulsEnterCounter = -1;
|
||||||
|
|
||||||
//enter_to_logging_counter = LOG1 - 1;
|
|
||||||
//analog_value_names_list = "";
|
|
||||||
//enter_to_analog_counter = 0;
|
|
||||||
//dallas_value_name = "";
|
|
||||||
//enter_to_dallas_counter = 0;
|
|
||||||
//levelPr_value_name = "";
|
|
||||||
//ultrasonicCm_value_name = "";
|
|
||||||
//dhtT_value_name = "";
|
|
||||||
//dhtH_value_name = "";
|
|
||||||
//bmp280T_value_name = "";
|
|
||||||
//bmp280P_value_name = "";
|
|
||||||
//bme280T_value_name = "";
|
|
||||||
//bme280P_value_name = "";
|
|
||||||
//bme280H_value_name = "";
|
|
||||||
//bme280A_value_name = "";
|
|
||||||
//int array_sz = sizeof(sensors_reading_map) / sizeof(sensors_reading_map[0]);
|
|
||||||
//for (int i = 0; i < array_sz; i++) {
|
|
||||||
// sensors_reading_map[i] = 0;
|
|
||||||
//}
|
|
||||||
//for (int i = LOG1; i <= LOG5; i++) {
|
|
||||||
// ts.remove(i);
|
|
||||||
//}
|
|
||||||
|
|
||||||
#ifdef LAYOUT_IN_RAM
|
#ifdef LAYOUT_IN_RAM
|
||||||
all_widgets = "";
|
all_widgets = "";
|
||||||
|
|||||||
@@ -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);
|
||||||
@@ -49,6 +51,8 @@ void cmd_init() {
|
|||||||
|
|
||||||
sCmd.addCommand("logging", logging);
|
sCmd.addCommand("logging", logging);
|
||||||
|
|
||||||
|
sCmd.addCommand("impuls-out", impuls);
|
||||||
|
|
||||||
handle_time_init();
|
handle_time_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,6 +54,17 @@ void addItem(String name) {
|
|||||||
addFile(DEVICE_CONFIG_FILE, "\n" + item);
|
addFile(DEVICE_CONFIG_FILE, "\n" + item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void addPreset(String name) {
|
||||||
|
String preset = readFile("presets/" + name + ".txt", 4048);
|
||||||
|
addFile(DEVICE_CONFIG_FILE, "\n" + preset);
|
||||||
|
|
||||||
|
name.replace(".c",".s");
|
||||||
|
|
||||||
|
String scenario = readFile("presets/" + name + ".txt", 4048);
|
||||||
|
removeFile(DEVICE_SCENARIO_FILE);
|
||||||
|
addFile(DEVICE_SCENARIO_FILE, scenario);
|
||||||
|
}
|
||||||
|
|
||||||
void delAllItems() {
|
void delAllItems() {
|
||||||
removeFile(DEVICE_CONFIG_FILE);
|
removeFile(DEVICE_CONFIG_FILE);
|
||||||
addFile(DEVICE_CONFIG_FILE, String(firstLine));
|
addFile(DEVICE_CONFIG_FILE, String(firstLine));
|
||||||
|
|||||||
@@ -26,11 +26,13 @@ void mqttInit() {
|
|||||||
if (mqtt.connected()) {
|
if (mqtt.connected()) {
|
||||||
SerialPrint("I", "MQTT", "OK");
|
SerialPrint("I", "MQTT", "OK");
|
||||||
setLedStatus(LED_OFF);
|
setLedStatus(LED_OFF);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
SerialPrint("E", "MQTT", "lost connection");
|
SerialPrint("E", "MQTT", "lost connection");
|
||||||
mqttConnect();
|
mqttConnect();
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
SerialPrint("E", "WIFI", "Lost WiFi connection");
|
SerialPrint("E", "WIFI", "Lost WiFi connection");
|
||||||
ts.remove(WIFI_MQTT_CONNECTION_CHECK);
|
ts.remove(WIFI_MQTT_CONNECTION_CHECK);
|
||||||
startAPMode();
|
startAPMode();
|
||||||
@@ -89,7 +91,8 @@ boolean mqttConnect() {
|
|||||||
setLedStatus(LED_OFF);
|
setLedStatus(LED_OFF);
|
||||||
mqttSubscribe();
|
mqttSubscribe();
|
||||||
res = true;
|
res = true;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
SerialPrint("E", "MQTT", "could't connect, retry in " + String(MQTT_RECONNECT_INTERVAL / 1000) + "s");
|
SerialPrint("E", "MQTT", "could't connect, retry in " + String(MQTT_RECONNECT_INTERVAL / 1000) + "s");
|
||||||
setLedStatus(LED_FAST);
|
setLedStatus(LED_FAST);
|
||||||
}
|
}
|
||||||
@@ -116,7 +119,8 @@ void mqttCallback(char* topic, uint8_t* payload, size_t length) {
|
|||||||
choose_log_date_and_send();
|
choose_log_date_and_send();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} else if (topicStr.indexOf("control")) {
|
}
|
||||||
|
else if (topicStr.indexOf("control")) {
|
||||||
|
|
||||||
String key = selectFromMarkerToMarker(topicStr, "/", 3);
|
String key = selectFromMarkerToMarker(topicStr, "/", 3);
|
||||||
|
|
||||||
@@ -125,12 +129,14 @@ void mqttCallback(char* topic, uint8_t* payload, size_t length) {
|
|||||||
orderBuf += payloadStr;
|
orderBuf += payloadStr;
|
||||||
orderBuf += ",";
|
orderBuf += ",";
|
||||||
|
|
||||||
} else if (topicStr.indexOf("order")) {
|
}
|
||||||
|
else if (topicStr.indexOf("order")) {
|
||||||
payloadStr.replace("_", " ");
|
payloadStr.replace("_", " ");
|
||||||
orderBuf += payloadStr;
|
orderBuf += payloadStr;
|
||||||
orderBuf += ",";
|
orderBuf += ",";
|
||||||
|
|
||||||
} else if (topicStr.indexOf("update")) {
|
}
|
||||||
|
else if (topicStr.indexOf("update")) {
|
||||||
if (payloadStr == "1") {
|
if (payloadStr == "1") {
|
||||||
myNotAsyncActions->make(do_UPGRADE);
|
myNotAsyncActions->make(do_UPGRADE);
|
||||||
}
|
}
|
||||||
|
|||||||
148
src/Scenario.cpp
148
src/Scenario.cpp
@@ -8,68 +8,68 @@ boolean isScenarioEnabled() {
|
|||||||
return jsonReadBool(configSetupJson, "scen") && eventBuf != "";
|
return jsonReadBool(configSetupJson, "scen") && eventBuf != "";
|
||||||
}
|
}
|
||||||
|
|
||||||
void loopScenario() {
|
//void loopScenario() {
|
||||||
if (!isScenarioEnabled()) {
|
// if (!isScenarioEnabled()) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
String scenarioTmp = scenario;
|
// String scenarioTmp = scenario;
|
||||||
scenarioTmp += "\n";
|
// scenarioTmp += "\n";
|
||||||
scenarioTmp.replace("\r\n", "\n");
|
// scenarioTmp.replace("\r\n", "\n");
|
||||||
scenarioTmp.replace("\r", "\n");
|
// scenarioTmp.replace("\r", "\n");
|
||||||
|
//
|
||||||
while (scenarioTmp.length()) {
|
// while (scenarioTmp.length()) {
|
||||||
String scenBlok = selectToMarker(scenarioTmp, "end"); //выделяем первый сценарий
|
// String scenBlok = selectToMarker(scenarioTmp, "end"); //выделяем первый сценарий
|
||||||
if (!scenBlok.length()) {
|
// if (!scenBlok.length()) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
size_t i = 0;
|
// size_t i = 0;
|
||||||
i++;
|
// i++;
|
||||||
if (scenario_line_status[i] == 1) {
|
// if (scenario_line_status[i] == 1) {
|
||||||
String condition = selectToMarker(scenBlok, "\n"); //выделяем условие
|
// String condition = selectToMarker(scenBlok, "\n"); //выделяем условие
|
||||||
|
//
|
||||||
String conditionParam = selectFromMarkerToMarker(condition, " ", 0); //выделяем параметр условия
|
// String conditionParam = selectFromMarkerToMarker(condition, " ", 0); //выделяем параметр условия
|
||||||
String order = eventBuf;
|
// String order = eventBuf;
|
||||||
String eventParam = selectToMarker(order, ","); //выделяем параметр события
|
// String eventParam = selectToMarker(order, ","); //выделяем параметр события
|
||||||
|
//
|
||||||
if (conditionParam == eventParam) { //если поступившее событие равно событию заданному buttonSet1 в файле начинаем его обработку
|
// if (conditionParam == eventParam) { //если поступившее событие равно событию заданному buttonSet1 в файле начинаем его обработку
|
||||||
|
//
|
||||||
String conditionSign = selectFromMarkerToMarker(condition, " ", 1); //выделяем знак (=)
|
// String conditionSign = selectFromMarkerToMarker(condition, " ", 1); //выделяем знак (=)
|
||||||
|
//
|
||||||
String conditionValue = selectFromMarkerToMarker(condition, " ", 2); //выделяем значение (1)
|
// String conditionValue = selectFromMarkerToMarker(condition, " ", 2); //выделяем значение (1)
|
||||||
|
//
|
||||||
boolean flag = false;
|
// boolean flag = false;
|
||||||
|
//
|
||||||
String eventParam = jsonReadStr(configLiveJson, conditionParam); //получаем значение этого параметра события из json
|
// String eventParam = jsonReadStr(configLiveJson, conditionParam); //получаем значение этого параметра события из json
|
||||||
|
//
|
||||||
if (conditionSign == "=") {
|
// if (conditionSign == "=") {
|
||||||
flag = eventParam == conditionValue;
|
// flag = eventParam == conditionValue;
|
||||||
} else if (conditionSign == "!=") {
|
// } else if (conditionSign == "!=") {
|
||||||
flag = eventParam != conditionValue;
|
// flag = eventParam != conditionValue;
|
||||||
} else if (conditionSign == "<") {
|
// } else if (conditionSign == "<") {
|
||||||
flag = eventParam.toInt() < conditionValue.toInt();
|
// flag = eventParam.toInt() < conditionValue.toInt();
|
||||||
} else if (conditionSign == ">") {
|
// } else if (conditionSign == ">") {
|
||||||
flag = eventParam.toInt() > conditionValue.toInt();
|
// flag = eventParam.toInt() > conditionValue.toInt();
|
||||||
} else if (conditionSign == ">=") {
|
// } else if (conditionSign == ">=") {
|
||||||
flag = eventParam.toInt() >= conditionValue.toInt();
|
// flag = eventParam.toInt() >= conditionValue.toInt();
|
||||||
} else if (conditionSign == "<=") {
|
// } else if (conditionSign == "<=") {
|
||||||
flag = eventParam.toInt() <= conditionValue.toInt();
|
// flag = eventParam.toInt() <= conditionValue.toInt();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if (flag) {
|
// if (flag) {
|
||||||
scenBlok = deleteBeforeDelimiter(scenBlok, "\n"); // удаляем строку самого сценария оставляя только команды
|
// scenBlok = deleteBeforeDelimiter(scenBlok, "\n"); // удаляем строку самого сценария оставляя только команды
|
||||||
SerialPrint("I","module","do: " + scenBlok);
|
// SerialPrint("I","module","do: " + scenBlok);
|
||||||
spaceCmdExecute(scenBlok); // выполняем все команды
|
// spaceCmdExecute(scenBlok); // выполняем все команды
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
scenarioTmp = deleteBeforeDelimiter(scenarioTmp, "end\n"); //удаляем первый сценарий
|
// scenarioTmp = deleteBeforeDelimiter(scenarioTmp, "end\n"); //удаляем первый сценарий
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
String eventBufTmp = eventBuf; //читаем файл событий
|
// String eventBufTmp = eventBuf; //читаем файл событий
|
||||||
eventBufTmp = deleteBeforeDelimiter(eventBufTmp, ","); //удаляем выполненное событие
|
// eventBufTmp = deleteBeforeDelimiter(eventBufTmp, ","); //удаляем выполненное событие
|
||||||
eventBuf = eventBufTmp; //записываем обновленный файл событий
|
// eventBuf = eventBufTmp; //записываем обновленный файл событий
|
||||||
}
|
//}
|
||||||
|
|
||||||
void eventGen(String event_name, String number) {
|
void eventGen(String event_name, String number) {
|
||||||
if (!jsonReadBool(configSetupJson, "scen")) {
|
if (!jsonReadBool(configSetupJson, "scen")) {
|
||||||
@@ -78,18 +78,18 @@ void eventGen(String event_name, String number) {
|
|||||||
eventBuf = event_name + number + ",";
|
eventBuf = event_name + number + ",";
|
||||||
}
|
}
|
||||||
|
|
||||||
String add_set(String str) {
|
//String add_set(String str) {
|
||||||
String num1 = str.substring(str.length() - 1);
|
// String num1 = str.substring(str.length() - 1);
|
||||||
String num2 = str.substring(str.length() - 2, str.length() - 1);
|
// String num2 = str.substring(str.length() - 2, str.length() - 1);
|
||||||
if (isDigitStr(num1) && isDigitStr(num2)) {
|
// if (isDigitStr(num1) && isDigitStr(num2)) {
|
||||||
str = str.substring(0, str.length() - 2) + "Set" + num2 + num1;
|
// str = str.substring(0, str.length() - 2) + "Set" + num2 + num1;
|
||||||
} else {
|
// } else {
|
||||||
if (isDigitStr(num1)) {
|
// if (isDigitStr(num1)) {
|
||||||
str = str.substring(0, str.length() - 1) + "Set" + num1;
|
// str = str.substring(0, str.length() - 1) + "Set" + num1;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return str;
|
// return str;
|
||||||
}
|
//}
|
||||||
|
|
||||||
//button-out1 = 1
|
//button-out1 = 1
|
||||||
//button-out2 1
|
//button-out2 1
|
||||||
|
|||||||
@@ -111,3 +111,5 @@ String prettyBytes(size_t size) {
|
|||||||
return String(size / 1024.0 / 1024.0 / 1024.0) + "GB";
|
return String(size / 1024.0 / 1024.0 / 1024.0) + "GB";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
11
src/Web.cpp
11
src/Web.cpp
@@ -1,9 +1,10 @@
|
|||||||
#include "Web.h"
|
#include "Web.h"
|
||||||
#include "items/LoggingClass.h"
|
|
||||||
#include "Class/NotAsync.h"
|
#include "Class/NotAsync.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include "Init.h"
|
#include "Init.h"
|
||||||
#include "ItemsList.h"
|
#include "ItemsList.h"
|
||||||
|
#include "items/LoggingClass.h"
|
||||||
|
|
||||||
bool parseRequestForPreset(AsyncWebServerRequest* request, uint8_t& preset) {
|
bool parseRequestForPreset(AsyncWebServerRequest* request, uint8_t& preset) {
|
||||||
if (request->hasArg("preset")) {
|
if (request->hasArg("preset")) {
|
||||||
@@ -22,6 +23,12 @@ void web_init() {
|
|||||||
request->redirect("/?set.device");
|
request->redirect("/?set.device");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (request->hasArg("addPreset")) {
|
||||||
|
String name = request->getParam("addPreset")->value();
|
||||||
|
addPreset(name);
|
||||||
|
request->redirect("/?set.device");
|
||||||
|
}
|
||||||
|
|
||||||
if (request->hasArg("delChoosingItems")) {
|
if (request->hasArg("delChoosingItems")) {
|
||||||
myNotAsyncActions->make(do_delChoosingItems);
|
myNotAsyncActions->make(do_delChoosingItems);
|
||||||
request->send(200);
|
request->send(200);
|
||||||
@@ -239,6 +246,8 @@ void web_init() {
|
|||||||
msg = F("Cервер не найден. Попробуйте повторить позже...");
|
msg = F("Cервер не найден. Попробуйте повторить позже...");
|
||||||
} else if (lastVersion == -2) {
|
} else if (lastVersion == -2) {
|
||||||
msg = F("Устройство не подключено к роутеру!");
|
msg = F("Устройство не подключено к роутеру!");
|
||||||
|
} else if (lastVersion < FIRMWARE_VERSION) {
|
||||||
|
msg = F("Ошибка версии. Попробуйте повторить позже...");
|
||||||
}
|
}
|
||||||
|
|
||||||
// else if (lastVersion == "") {
|
// else if (lastVersion == "") {
|
||||||
|
|||||||
70
src/items/ImpulsOutClass.cpp
Normal file
70
src/items/ImpulsOutClass.cpp
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
#include "items/ImpulsOutClass.h"
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include "BufferExecute.h"
|
||||||
|
#include "Class/LineParsing.h"
|
||||||
|
#include "Global.h"
|
||||||
|
#include "ItemsCmd.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();
|
||||||
|
unsigned long 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();
|
||||||
|
|
||||||
|
impulsEnterCounter++;
|
||||||
|
addKey(key, impulsKeyList, impulsEnterCounter);
|
||||||
|
|
||||||
|
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, impulsKeyList);
|
||||||
|
|
||||||
|
if (myImpulsOut != nullptr) {
|
||||||
|
if (number != -1) {
|
||||||
|
myImpulsOut->at(number).execute(impulsPeriod.toInt(), impulsCount.toInt());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -54,13 +54,13 @@ MyLoggingVector* myLogging = nullptr;
|
|||||||
|
|
||||||
void logging() {
|
void logging() {
|
||||||
myLineParsing.update();
|
myLineParsing.update();
|
||||||
String loggingValueKey = myLineParsing.gvalue();
|
String loggingValueKey = myLineParsing.gval();
|
||||||
String key = myLineParsing.gkey();
|
String key = myLineParsing.gkey();
|
||||||
String interv = myLineParsing.gint();
|
String interv = myLineParsing.gint();
|
||||||
String maxcnt = myLineParsing.gmaxcnt();
|
String maxcnt = myLineParsing.gcnt();
|
||||||
myLineParsing.clear();
|
myLineParsing.clear();
|
||||||
|
|
||||||
logging_value_names_list += key + ",";
|
loggingKeyList += key + ",";
|
||||||
|
|
||||||
static bool firstTime = true;
|
static bool firstTime = true;
|
||||||
if (firstTime) myLogging = new MyLoggingVector();
|
if (firstTime) myLogging = new MyLoggingVector();
|
||||||
@@ -69,7 +69,7 @@ void logging() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void choose_log_date_and_send() {
|
void choose_log_date_and_send() {
|
||||||
String all_line = logging_value_names_list;
|
String all_line = loggingKeyList;
|
||||||
while (all_line.length() != 0) {
|
while (all_line.length() != 0) {
|
||||||
String tmp = selectToMarker(all_line, ",");
|
String tmp = selectToMarker(all_line, ",");
|
||||||
sendLogData("logs/" + tmp + ".txt", tmp);
|
sendLogData("logs/" + tmp + ".txt", tmp);
|
||||||
|
|||||||
54
src/items/SensorDallas.cpp
Normal file
54
src/items/SensorDallas.cpp
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
#include "items/SensorDallas.h"
|
||||||
|
#include "Class/LineParsing.h"
|
||||||
|
#include "Global.h"
|
||||||
|
#include "ItemsCmd.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();
|
||||||
|
unsigned long difference = currentMillis - prevMillis;
|
||||||
|
if (difference >= _interval) {
|
||||||
|
prevMillis = millis();
|
||||||
|
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 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
|
|
||||||
16
src/main.cpp
16
src/main.cpp
@@ -16,6 +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/SensorDallas.h"
|
||||||
|
|
||||||
void not_async_actions();
|
void not_async_actions();
|
||||||
|
|
||||||
@@ -102,8 +104,6 @@ void setup() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
return;
|
return;
|
||||||
@@ -129,4 +129,16 @@ void loop() {
|
|||||||
myLogging->at(i).loop();
|
myLogging->at(i).loop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (myImpulsOut != nullptr) {
|
||||||
|
for (unsigned int i = 0; i < myImpulsOut->size(); i++) {
|
||||||
|
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