diff --git a/.vscode/settings.json b/.vscode/settings.json index 37c9ae2c..63657b48 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,7 @@ { "files.associations": { "*.tcc": "cpp", - "string": "cpp" + "string": "cpp", + "functional": "cpp" } } \ No newline at end of file diff --git a/data/items/input-time.txt b/data/items/input-time.txt index 46e49666..e90f7689 100644 --- a/data/items/input-time.txt +++ b/data/items/input-time.txt @@ -1 +1 @@ -0;input-time;id;inputTime;Ввод;Введите#время;order;st[10-00-00] \ No newline at end of file +0;input-time;id;inputTime;Ввод;Введите#время;order;st[10:00:00] \ No newline at end of file diff --git a/data/items/uptime.txt b/data/items/uptime.txt index 9672a6f3..972241b4 100644 --- a/data/items/uptime.txt +++ b/data/items/uptime.txt @@ -1 +1 @@ -0;uptime;id;anydataTime;Системные;Uptime#(ver#%ver%);order \ No newline at end of file +0;uptime;id;anydataTime;Системные;%name%#uptime;order \ No newline at end of file diff --git a/data/s.conf.csv b/data/s.conf.csv index 2d2f8d1d..40b35ae1 100644 --- a/data/s.conf.csv +++ b/data/s.conf.csv @@ -1 +1 @@ -Тип элемента;Id;Виджет;Имя вкладки;Имя виджета;Позиция виджета \ No newline at end of file +Удалить;Тип элемента;Id;Виджет;Имя вкладки;Имя виджета;Позиция виджета \ No newline at end of file diff --git a/data/set.device.json b/data/set.device.json index 47b03164..93f7c3fa 100644 --- a/data/set.device.json +++ b/data/set.device.json @@ -31,7 +31,7 @@ }, { "type": "h4", - "title": "Time: {{time}}" + "title": "Time: {{timenow}}" }, { "type": "h4", @@ -43,7 +43,7 @@ }, { "type": "h4", - "title": "LittleFS version: 260" + "title": "LittleFS version: 261" }, { "type": "hr" diff --git a/data/set.wifi.json b/data/set.wifi.json index d68edc7f..936d1cc2 100644 --- a/data/set.wifi.json +++ b/data/set.wifi.json @@ -28,8 +28,7 @@ "type": "input", "title": "{{SetWiFiNameOfDev}}", "name": "devname-arg", - "state": "{{name}}", - "pattern": "[A-Za-z0-9]{6,12}" + "state": "{{name}}" }, { "type": "button", diff --git a/data/widgets/btn.json b/data/widgets/btn.json new file mode 100644 index 00000000..67dcc0d3 --- /dev/null +++ b/data/widgets/btn.json @@ -0,0 +1,6 @@ +{ + "widget": "btn", + "size": "large", + "color": "green", + "send": "test" +} \ No newline at end of file diff --git a/data/widgets/select.json b/data/widgets/select.json index c6531b70..bad018fd 100644 --- a/data/widgets/select.json +++ b/data/widgets/select.json @@ -1,7 +1,8 @@ { - "widget" : "select", - "size" : "small", - "fill" : "outline", - "options" : "["Zero item", "First item", "Second item"]", - "status" : 2 + "widget": "select", + "options": [ + "Выключен", + "Включен" + ], + "status": 0 } \ No newline at end of file diff --git a/include/Class/LineParsing.h b/include/Class/LineParsing.h index 05b55aa0..fa117948 100644 --- a/include/Class/LineParsing.h +++ b/include/Class/LineParsing.h @@ -92,6 +92,7 @@ class LineParsing { _descr.replace("#", " "); _descr.replace("%ver%", String(FIRMWARE_VERSION)); + _descr.replace("%name%", jsonReadStr(configSetupJson, F("name"))); createWidgetClass(_descr, _page, _order, _file, _key); } diff --git a/include/Clock.h b/include/Clock.h index eaddafde..dea567c8 100644 --- a/include/Clock.h +++ b/include/Clock.h @@ -1,17 +1,17 @@ #pragma once -#include "Utils/TimeUtils.h" -#include "Utils/PrintMessage.h" -#include "Global.h" #include "Clock.h" +#include "Global.h" +#include "Utils/TimeUtils.h" +#include "Utils\SerialPrint.h" + +extern void clock_init(); #ifdef ESP8266 #include "sntp.h" #endif class Clock { - - private: Time_t _time_local; Time_t _time_utc; @@ -39,7 +39,6 @@ class Clock { if (drift > 1) { // Обработать ситуации c дрифтом времени на значительные величины } - // TODO сохранять время на флеше _unixtime = now; @@ -71,27 +70,26 @@ class Clock { void startSync() { if (!_configured) { - //SerialPrint("I","module","sync to: " + _ntp + " timezone: " + String(_timezone)); + SerialPrint("I", "NTP", "sync to: " + _ntp + " timezone: " + String(_timezone)); setupSntp(); _configured = true; - // лучше не ждать, проверим в следующий раз return; } _hasSynced = hasTimeSynced(); if (_hasSynced) { - //SerialPrint("I","module","synced " + getDateDotFormated() + " " + getTime()); + SerialPrint("I", "NTP", "synced " + getDateDotFormated() + " " + getTime()); } else { - //SerialPrint("[E]","module","failed to obtain"); + SerialPrint("E", "NTP", "failed to obtain time"); } } void setupSntp() { -#ifdef ESP2866 +#ifdef ESP8266 sntp_setservername(0, _ntp.c_str()); sntp_setservername(1, "ru.pool.ntp.org"); sntp_setservername(2, "pool.ntp.org"); sntp_stop(); - sntp_set_timezone(0); // UTC time + sntp_set_timezone(0); sntp_init(); #else configTime(0, 0, _ntp.c_str(), "ru.pool.ntp.org", "pool.ntp.org"); @@ -164,4 +162,5 @@ class Clock { const String getUptime() { return prettyMillis(_uptime); } -}; \ No newline at end of file +}; +extern Clock* timeNow; \ No newline at end of file diff --git a/include/Consts.h b/include/Consts.h index b931e4a7..8f245051 100644 --- a/include/Consts.h +++ b/include/Consts.h @@ -5,7 +5,7 @@ // #ifdef ESP8266 #define FIRMWARE_NAME "esp8266-iotm" -#define FIRMWARE_VERSION 260 +#define FIRMWARE_VERSION 261 #endif #ifdef ESP32 #define FIRMWARE_NAME "esp32-iotm" @@ -85,7 +85,8 @@ struct Time_t { enum TimerTask_t { WIFI_SCAN, WIFI_MQTT_CONNECTION_CHECK, - SENSORS, + SENSORS10SEC, + SENSORS30SEC, STEPPER1, STEPPER2, LOG1, diff --git a/include/Errors.h b/include/Errors.h deleted file mode 100644 index 2b117273..00000000 --- a/include/Errors.h +++ /dev/null @@ -1,52 +0,0 @@ -#pragma once - -#include - -#include "Utils/StringUtils.h" - -class Error : public Printable { - public: - static Error OK() { - return Error(); - } - - static Error InfoMessage(const char *message) { - return Error(EL_INFO, message); - } - - static Error ErrorMessage(const char *message) { - return Error(EL_ERROR, message); - } - - public: - Error() : _type{ET_NONE}, _level{EL_NONE} {}; - - Error(const ErrorLevel_t level, const char *message) : Error(ET_FUNCTION, level, message){}; - - Error(const ErrorType_t type, const ErrorLevel_t level, const char *message) : _type{type}, _level{level} { - strncpy(_message, message, sizeof(_message)); - }; - - const ErrorLevel_t level() const { return _level; } - - const ErrorType_t type() const { return _type; } - - const char *message() const { return _message; } - - operator bool() const { return _level != EL_NONE; } - - const String toString() const { - char buf[128]; - sprintf(buf, "[%c] %s", getErrorLevelStr(_level), _message); - return String(buf); - } - - virtual size_t printTo(Print &p) const { - return p.println(toString().c_str()); - } - - private: - char _message[128]; - ErrorType_t _type; - ErrorLevel_t _level; -}; diff --git a/include/Global.h b/include/Global.h index e5d0eaed..c6e76833 100644 --- a/include/Global.h +++ b/include/Global.h @@ -1,28 +1,10 @@ #pragma once //===================Libraries=================================================================================================================================================== -#include -#include - -#include "ESP32.h" -#include "ESP8266.h" - -#include "Consts.h" -#include "Errors.h" -#include "GyverFilters.h" -#include "Upgrade.h" -#include "Clock.h" - -#include "MqttClient.h" -#include "Utils/FileUtils.h" -#include "Utils/JsonUtils.h" -#include "Utils/StringUtils.h" -#include "Utils/SysUtils.h" -#include "Utils/PrintMessage.h" -#include "Utils/WiFiUtils.h" -#include "Utils/SerialPrint.h" - #include #include +#include +#include +#include #include #include #include @@ -32,27 +14,37 @@ #include #include #include -#include - +#include "Clock.h" +#include "Consts.h" +#include "ESP32.h" +#include "ESP8266.h" +#include "GyverFilters.h" +#include "MqttClient.h" +#include "Upgrade.h" +#include "Utils/FileUtils.h" +#include "Utils/JsonUtils.h" +#include "Utils/SerialPrint.h" +#include "Utils/StringUtils.h" +#include "Utils/SysUtils.h" +#include "Utils/WiFiUtils.h" #ifdef WEBSOCKET_ENABLED extern AsyncWebSocket ws; //extern AsyncEventSource events; #endif -extern Clock* timeNow; + extern TickerScheduler ts; extern WiFiClient espClient; extern PubSubClient mqtt; extern StringCommand sCmd; extern AsyncWebServer server; extern DallasTemperature sensors; -extern OneWire *oneWire; +extern OneWire* oneWire; extern boolean but[NUM_BUTTONS]; extern Bounce* buttons; - //Global vars extern boolean just_load; @@ -74,7 +66,8 @@ extern String itemsFile; extern String itemsLine; // Sensors -extern String sensorReadingMap; +extern String sensorReadingMap10sec; +extern String sensorReadingMap30sec; extern int8_t dallasEnterCounter; extern String logging_value_names_list; @@ -98,7 +91,6 @@ extern String getURL(const String& urls); extern void do_fscheck(); extern void doBusScan(); extern void servo_(); -extern void clock_init(); extern void setLedStatus(LedStatus_t); @@ -106,8 +98,6 @@ extern void setLedStatus(LedStatus_t); extern void eventGen(String event_name, String number); extern String add_set(String param_name); - - //Timers extern void Timer_countdown_init(); extern void timerStart_(); @@ -132,8 +122,6 @@ extern void pushControl(); //extern void do_udp_data_parse(); //extern void do_mqtt_send_settings_to_udp(); - - extern void do_update(); // Init @@ -141,4 +129,3 @@ extern void uptime_init(); // Web extern void web_init(); - diff --git a/include/Utils/PrintMessage.h b/include/Utils/PrintMessage.h deleted file mode 100644 index f33f4252..00000000 --- a/include/Utils/PrintMessage.h +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once - -#include "Arduino.h" -#include "Utils/StringUtils.h" -#include "Utils/TimeUtils.h" -#include "Errors.h" -#include "Global.h" - -#define pm PrintMessage(MODULE) - -class PrintMessage { - public: - PrintMessage(const char* module) { - _module = module; - } - - void error(const String& str) { - print(EL_ERROR, str); - } - - void info(const String& str) { - print(EL_INFO, str); - } - - private: - void printErrorLevel(ErrorLevel_t level) { - Serial.printf("[%c] ", getErrorLevelStr(level)); - } - - void printUptime() { - Serial.printf("%lu ", ((unsigned long)millis() / 1000)); - } - - void printModule() { - Serial.printf("[%s] ", _module); - } - - void print(const ErrorLevel_t level, const String& str) { - printUptime(); - printErrorLevel(level); - printModule(); - Serial.println(str.c_str()); - } - - private: - const char* _module; -}; diff --git a/include/items/InputClass.h b/include/items/InputClass.h index 7d072423..afe5a0f8 100644 --- a/include/items/InputClass.h +++ b/include/items/InputClass.h @@ -24,7 +24,7 @@ class InputClass : public LineParsing { void inputSetStr(String key, String state) { eventGen(key, ""); jsonWriteStr(configLiveJson, key, state); - publishStatus(key, state); + publishStatus(key, state); } }; diff --git a/include/items/SensorAnalogClass.h b/include/items/SensorAnalogClass.h index 2c1eab4d..f1659263 100644 --- a/include/items/SensorAnalogClass.h +++ b/include/items/SensorAnalogClass.h @@ -29,7 +29,7 @@ class SensorAnalogClass : public SensorConvertingClass { eventGen(key, ""); jsonWriteStr(configLiveJson, key, String(valueFl)); publishStatus(key, String(valueFl)); - Serial.println("I sensor '" + key + "' data: " + String(valueFl)); + SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl)); return value; } }; diff --git a/include/items/SensorBme280Class.h b/include/items/SensorBme280Class.h index 35641652..11e97169 100644 --- a/include/items/SensorBme280Class.h +++ b/include/items/SensorBme280Class.h @@ -18,7 +18,7 @@ class SensorBme280Class : public SensorConvertingClass { bme.begin(hexStringToUint8(_addr)); jsonWriteStr(configOptionJson, _key + "_map", _map); jsonWriteStr(configOptionJson, _key + "_с", _c); - sensorReadingMap += _key + ","; + sensorReadingMap10sec += _key + ","; } void SensorBme280ReadTmp(String key) { @@ -28,7 +28,7 @@ class SensorBme280Class : public SensorConvertingClass { eventGen(key, ""); jsonWriteStr(configLiveJson, key, String(valueFl)); publishStatus(key, String(valueFl)); - Serial.println("I sensor '" + key + "' data: " + String(valueFl)); + SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl)); } void SensorBme280ReadHum(String key) { @@ -38,7 +38,7 @@ class SensorBme280Class : public SensorConvertingClass { eventGen(key, ""); jsonWriteStr(configLiveJson, key, String(valueFl)); publishStatus(key, String(valueFl)); - Serial.println("I sensor '" + key + "' data: " + String(valueFl)); + SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl)); } void SensorBme280ReadPress(String key) { @@ -49,7 +49,7 @@ class SensorBme280Class : public SensorConvertingClass { eventGen(key, ""); jsonWriteStr(configLiveJson, key, String(valueFl)); publishStatus(key, String(valueFl)); - Serial.println("I sensor '" + key + "' data: " + String(valueFl)); + SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl)); } }; extern SensorBme280Class mySensorBme280; \ No newline at end of file diff --git a/include/items/SensorBmp280Class.h b/include/items/SensorBmp280Class.h index 438258fc..28ef71a0 100644 --- a/include/items/SensorBmp280Class.h +++ b/include/items/SensorBmp280Class.h @@ -17,7 +17,7 @@ class SensorBmp280Class : public SensorConvertingClass { bmp.begin(hexStringToUint8(_addr)); jsonWriteStr(configOptionJson, _key + "_map", _map); jsonWriteStr(configOptionJson, _key + "_с", _c); - sensorReadingMap += _key + ","; + sensorReadingMap10sec += _key + ","; } void SensorBmp280ReadTmp(String key) { @@ -29,7 +29,7 @@ class SensorBmp280Class : public SensorConvertingClass { eventGen(key, ""); jsonWriteStr(configLiveJson, key, String(valueFl)); publishStatus(key, String(valueFl)); - Serial.println("I sensor '" + key + "' data: " + String(valueFl)); + SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl)); } void SensorBmp280ReadPress(String key) { @@ -42,7 +42,7 @@ class SensorBmp280Class : public SensorConvertingClass { eventGen(key, ""); jsonWriteStr(configLiveJson, key, String(valueFl)); publishStatus(key, String(valueFl)); - Serial.println("I sensor '" + key + "' data: " + String(valueFl)); + SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl)); } }; extern SensorBmp280Class mySensorBmp280; \ No newline at end of file diff --git a/include/items/SensorDallasClass.h b/include/items/SensorDallasClass.h index ff7e11bf..203bd7f0 100644 --- a/include/items/SensorDallasClass.h +++ b/include/items/SensorDallasClass.h @@ -14,7 +14,7 @@ class SensorDallasClass : public SensorConvertingClass { sensors.begin(); sensors.setResolution(48); - sensorReadingMap += _key + ","; + sensorReadingMap10sec += _key + ","; dallasEnterCounter++; jsonWriteInt(configOptionJson, _key + "_num", dallasEnterCounter); @@ -37,7 +37,7 @@ class SensorDallasClass : public SensorConvertingClass { eventGen(key, ""); jsonWriteStr(configLiveJson, key, String(valueFl)); publishStatus(key, String(valueFl)); - Serial.println("I sensor '" + key + "' data: " + String(valueFl)); + SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl)); } } } diff --git a/include/items/SensorDhtClass.h b/include/items/SensorDhtClass.h index bea2edb9..c90fc578 100644 --- a/include/items/SensorDhtClass.h +++ b/include/items/SensorDhtClass.h @@ -17,7 +17,7 @@ class SensorDhtClass : public SensorConvertingClass { if (_type == "dht22") { dht.setup(_pin.toInt(), DHTesp::DHT22); } - sensorReadingMap += _key + ","; + sensorReadingMap10sec += _key + ","; //to do если надо будет читать несколько dht //dhtEnterCounter++; @@ -44,7 +44,7 @@ class SensorDhtClass : public SensorConvertingClass { eventGen(key, ""); jsonWriteStr(configLiveJson, key, String(valueFl)); publishStatus(key, String(valueFl)); - Serial.println("I sensor '" + key + "' data: " + String(valueFl)); + SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl)); } else { Serial.println("[E] sensor '" + key); } @@ -68,7 +68,7 @@ class SensorDhtClass : public SensorConvertingClass { eventGen(key, ""); jsonWriteStr(configLiveJson, key, String(valueFl)); publishStatus(key, String(valueFl)); - Serial.println("I sensor '" + key + "' data: " + String(valueFl)); + SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl)); } else { Serial.println("[E] sensor '" + key); } diff --git a/include/items/SensorModbusClass.h b/include/items/SensorModbusClass.h index 27f36c66..39c3d8bd 100644 --- a/include/items/SensorModbusClass.h +++ b/include/items/SensorModbusClass.h @@ -18,8 +18,8 @@ // uart.begin(9600); // jsonWriteStr(configOptionJson, _key + "_map", _map); // jsonWriteStr(configOptionJson, _key + "_с", _c); -// sensorReadingMap += _key + " " + _addr + " " + _reg + ","; -// Serial.println(sensorReadingMap); +// sensorReadingMap10sec += _key + " " + _addr + " " + _reg + ","; +// Serial.println(sensorReadingMap10sec); // } // // void SensorModbusRead(String key, uint8_t slaveAddress, uint16_t regAddress) { @@ -38,7 +38,7 @@ // eventGen(key, ""); // jsonWriteStr(configLiveJson, key, String(valueFl)); // publishStatus(key, String(valueFl)); -// Serial.println("I sensor '" + key + "' data: " + String(valueFl) + ", Slave dev addr: " + String(slaveAddress) + ", Register: " + String(regAddress)); +// SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl) + ", Slave dev addr: " + String(slaveAddress) + ", Register: " + String(regAddress)); // } // // bool getResultMsg(ModbusMaster* modbus1, uint16_t result) { diff --git a/include/items/SensorUltrasonicClass.h b/include/items/SensorUltrasonicClass.h index 06d6a972..5dee38dd 100644 --- a/include/items/SensorUltrasonicClass.h +++ b/include/items/SensorUltrasonicClass.h @@ -12,7 +12,7 @@ class SensorUltrasonic : public SensorConvertingClass { public: SensorUltrasonic() : SensorConvertingClass(){}; void init() { - sensorReadingMap += _key + ","; + sensorReadingMap10sec += _key + ","; String trig = selectFromMarkerToMarker(_pin, ",", 0); String echo = selectFromMarkerToMarker(_pin, ",", 1); pinMode(trig.toInt(), OUTPUT); @@ -43,7 +43,7 @@ class SensorUltrasonic : public SensorConvertingClass { eventGen(key, ""); jsonWriteStr(configLiveJson, key, String(valueFl)); publishStatus(key, String(valueFl)); - Serial.println("I sensor '" + key + "' data: " + String(valueFl)); + SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl)); } }; extern SensorUltrasonic mySensorUltrasonic; \ No newline at end of file diff --git a/src/BufferExecute.cpp b/src/BufferExecute.cpp index ef78ca8d..83d6ab45 100644 --- a/src/BufferExecute.cpp +++ b/src/BufferExecute.cpp @@ -1,9 +1,7 @@ #include "BufferExecute.h" + #include "Global.h" #include "Module/Terminal.h" -#include "Errors.h" - - void loopCmdAdd(const String &cmdStr) { orderBuf += cmdStr; @@ -18,7 +16,6 @@ void fileCmdExecute(const String &filename) { } void csvCmdExecute(String &cmdStr) { - cmdStr.replace(";", " "); cmdStr += "\r\n"; cmdStr.replace("\r\n", "\n"); @@ -26,7 +23,7 @@ void csvCmdExecute(String &cmdStr) { int count = 0; while (cmdStr.length()) { String buf = selectToMarker(cmdStr, "\n"); - buf = deleteBeforeDelimiter(buf, " "); //отсечка чекбокса + buf = deleteBeforeDelimiter(buf, " "); //отсечка чекбокса count++; if (count > 1) sCmd.readStr(buf); cmdStr = deleteBeforeDelimiter(cmdStr, "\n"); @@ -47,16 +44,27 @@ void spaceCmdExecute(String &cmdStr) { void loopCmdExecute() { if (orderBuf.length()) { String tmp = selectToMarker(orderBuf, ","); //выделяем первую команду rel 5 1, - SerialPrint("I","CMD","do: " + tmp); - sCmd.readStr(tmp); //выполняем + SerialPrint("I", "CMD", "do: " + tmp); + sCmd.readStr(tmp); //выполняем orderBuf = deleteBeforeDelimiter(orderBuf, ","); //осекаем } } void sensorsInit() { ts.add( - SENSORS, 10000, [&](void *) { - String buf = sensorReadingMap; + SENSORS10SEC, 10000, [&](void *) { + String buf = sensorReadingMap10sec; + while (buf.length()) { + String tmp = selectToMarker(buf, ","); + sCmd.readStr(tmp); + buf = deleteBeforeDelimiter(buf, ","); + } + }, + nullptr, true); + + ts.add( + SENSORS30SEC, 30000, [&](void *) { + String buf = sensorReadingMap30sec; while (buf.length()) { String tmp = selectToMarker(buf, ","); sCmd.readStr(tmp); @@ -66,8 +74,3 @@ void sensorsInit() { nullptr, true); } -//void loopSerial() { -// if (term) { -// term->loop(); -// } -//} diff --git a/src/Clock.cpp b/src/Clock.cpp new file mode 100644 index 00000000..888f9d5b --- /dev/null +++ b/src/Clock.cpp @@ -0,0 +1,16 @@ +#include "Clock.h" + +#include "Global.h" + +Clock* timeNow; +void clock_init() { + timeNow = new Clock; + timeNow->setNtpPool(jsonReadStr(configSetupJson, "ntp")); + timeNow->setTimezone(jsonReadStr(configSetupJson, "timezone").toInt()); + + ts.add( + TIME_SYNC, 30000, [&](void*) { + timeNow->hasSync(); + }, + nullptr, true); +} diff --git a/src/Global.cpp b/src/Global.cpp index 2c033a2d..18cb15b4 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -4,7 +4,7 @@ AsyncWebSocket ws; //AsyncEventSource events; #endif -Clock* timeNow; + TickerScheduler ts(TEST + 1); WiFiClient espClient; PubSubClient mqtt(espClient); @@ -39,7 +39,8 @@ String itemsLine = ""; // Sensors int8_t dallasEnterCounter = -1; -String sensorReadingMap; +String sensorReadingMap10sec; +String sensorReadingMap30sec; // Logging String logging_value_names_list; diff --git a/src/Init.cpp b/src/Init.cpp index e704cc1d..f2e5c82e 100644 --- a/src/Init.cpp +++ b/src/Init.cpp @@ -5,7 +5,7 @@ void loadConfig() { configSetupJson = readFile("config.json", 4096); - configSetupJson.replace(" ", ""); + //configSetupJson.replace(" ", ""); configSetupJson.replace("\r\n", ""); jsonWriteStr(configSetupJson, "chipID", chipId); @@ -24,7 +24,7 @@ void all_init() { void Device_init() { - sensorReadingMap = ""; + sensorReadingMap10sec = ""; dallasEnterCounter = -1; //logging_value_names_list = ""; diff --git a/src/MqttClient.cpp b/src/MqttClient.cpp index e2c76b0c..34d83bbd 100644 --- a/src/MqttClient.cpp +++ b/src/MqttClient.cpp @@ -117,8 +117,7 @@ void mqttCallback(char* topic, uint8_t* payload, size_t length) { #endif } else if (topicStr.indexOf("control")) { - //iotTeam/12882830-1458415/light 1 - + String key = selectFromMarkerToMarker(topicStr, "/", 3); orderBuf += key; @@ -135,14 +134,6 @@ void mqttCallback(char* topic, uint8_t* payload, size_t length) { if (payloadStr == "1") { myNotAsyncActions->make(do_UPGRADE); } - - } else if (topicStr.indexOf("devc")) { - writeFile(String(DEVICE_CONFIG_FILE), payloadStr); - Device_init(); - - } else if (topicStr.indexOf("devs")) { - writeFile(String(DEVICE_SCENARIO_FILE), payloadStr); - loadScenario(); } } @@ -231,9 +222,6 @@ void publishWidgets() { void publishState() { // берет строку json и ключи превращает в топики а значения колючей в них посылает - // {"name":"MODULES","lang":"","ip":"192.168.43.60","DS":"34.00","rel1":"1","rel2":"1"} - // "name":"MODULES","lang":"","ip":"192.168.43.60","DS":"34.00","rel1":"1","rel2":"1" - // "name":"MODULES","lang":"","ip":"192.168.43.60","DS":"34.00","rel1":"1","rel2":"1", String str = configLiveJson; str.replace("{", ""); str.replace("}", ""); @@ -242,13 +230,13 @@ void publishState() { while (str.length()) { String tmp = selectToMarker(str, ","); - String topic = selectToMarker(tmp, ":"); + String topic = selectToMarker(tmp, "\":"); topic.replace("\"", ""); - String state = selectToMarkerLast(tmp, ":"); + String state = selectToMarkerLast(tmp, "\":"); state.replace("\"", ""); - if ((topic != "time") && (topic != "name") && (topic != "lang") && (topic != "ip") && (topic.indexOf("_in") < 0)) { + if (topic != "timenow") { publishStatus(topic, state); } str = deleteBeforeDelimiter(str, ","); diff --git a/src/SSDP.cpp b/src/SSDP.cpp index b42f6db7..c84d99ca 100644 --- a/src/SSDP.cpp +++ b/src/SSDP.cpp @@ -14,8 +14,6 @@ String xmlNode(String tags, String data); String decToHex(uint32_t decValue, byte desiredStringLength); -//39164 -//457684 void SsdpInit() { server.on("/description.xml", HTTP_GET, [](AsyncWebServerRequest* request) { String ssdpSend = F(""); diff --git a/src/Sensors.cpp b/src/Sensors.cpp index a4fe9bf1..d3a0817b 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -57,7 +57,7 @@ // //eventGen(dhtT_value_name, ""); // //jsonWriteStr(configLiveJson, dhtT_value_name, String(value)); // // publishStatus(dhtT_value_name, String(value)); -// //Serial.println("I sensor '" + dhtT_value_name + "' data: " + String(value)); +// //SerialPrint("I", "Sensor", "'" + dhtT_value_name + "' data: " + String(value)); // } // } //} @@ -95,7 +95,7 @@ // //eventGen(dhtH_value_name, ""); // //jsonWriteStr(configLiveJson, dhtH_value_name, String(value)); // // publishStatus(dhtH_value_name, String(value)); -// //Serial.println("I sensor '" + dhtH_value_name + "' data: " + String(value)); +// //SerialPrint("I", "Sensor", "'" + dhtH_value_name + "' data: " + String(value)); // } // } //} @@ -120,7 +120,7 @@ // eventGen("dhtPerception", ""); // publishStatus("dhtPerception", final_line); // if (mqtt.connected()) { -// Serial.println("I sensor 'dhtPerception' data: " + final_line); +// SerialPrint("I", "Sensor", "'dhtPerception' data: " + final_line); // } // } //} @@ -144,7 +144,7 @@ // jsonWriteStr(configLiveJson, "dhtComfort", final_line); // eventGen("dhtComfort", ""); // publishStatus("dhtComfort", final_line); -// Serial.println("I sensor 'dhtComfort' send date " + final_line); +// SerialPrint("I", "Sensor", "'dhtComfort' send date " + final_line); // } //} // @@ -236,7 +236,7 @@ // jsonWriteInt(configLiveJson, "dhtDewpoint", value); // eventGen("dhtDewpoint", ""); // publishStatus("dhtDewpoint", String(value)); -// Serial.println("I sensor 'dhtDewpoint' data: " + String(value)); +// SerialPrint("I", "Sensor", "'dhtDewpoint' data: " + String(value)); // } //} //#endif @@ -272,7 +272,7 @@ // //jsonWriteStr(configLiveJson, bmp280T_value_name, String(value)); // //eventGen(bmp280T_value_name, ""); // // publishStatus(bmp280T_value_name, String(value)); -// //Serial.println("I sensor '" + bmp280T_value_name + "' data: " + String(value)); +// //SerialPrint("I", "Sensor", "'" + bmp280T_value_name + "' data: " + String(value)); //} // ////bmp280P press1 0x76 Давление#bmp280 Датчики any-data 2 @@ -304,7 +304,7 @@ // //jsonWriteStr(configLiveJson, bmp280P_value_name, String(value)); // //eventGen(bmp280P_value_name, ""); // // publishStatus(bmp280P_value_name, String(value)); -// //Serial.println("I sensor '" + bmp280P_value_name + "' data: " + String(value)); +// //SerialPrint("I", "Sensor", "'" + bmp280P_value_name + "' data: " + String(value)); //} // ////========================================================================================================================================= @@ -329,7 +329,7 @@ // //jsonWriteStr(configLiveJson, bme280T_value_name, String(value)); // //eventGen(bme280T_value_name, ""); // // publishStatus(bme280T_value_name, String(value)); -// //Serial.println("I sensor '" + bme280T_value_name + "' data: " + String(value)); +// //SerialPrint("I", "Sensor", "'" + bme280T_value_name + "' data: " + String(value)); //} // ////bme280P pres1 0x76 Давление#bmp280 Датчики any-data 1 @@ -353,7 +353,7 @@ // //jsonWriteStr(configLiveJson, bme280P_value_name, String(value)); // //eventGen(bme280P_value_name, ""); // // publishStatus(bme280P_value_name, String(value)); -// //Serial.println("I sensor '" + bme280P_value_name + "' data: " + String(value)); +// //SerialPrint("I", "Sensor", "'" + bme280P_value_name + "' data: " + String(value)); //} // ////bme280H hum1 0x76 Влажность#bmp280 Датчики any-data 1 @@ -376,7 +376,7 @@ // //jsonWriteStr(configLiveJson, bme280H_value_name, String(value)); // //eventGen(bme280H_value_name, ""); // // publishStatus(bme280H_value_name, String(value)); -// //Serial.println("I sensor '" + bme280H_value_name + "' data: " + String(value)); +// //SerialPrint("I", "Sensor", "'" + bme280H_value_name + "' data: " + String(value)); //} // ////bme280A altit1 0x76 Высота#bmp280 Датчики any-data 1 @@ -401,5 +401,5 @@ // // // publishStatus(bme280A_value_name, String(value)); // -// //Serial.println("I sensor '" + bme280A_value_name + "' data: " + String(value)); +// //SerialPrint("I", "Sensor", "'" + bme280A_value_name + "' data: " + String(value)); //} diff --git a/src/UpgradeFirm.cpp b/src/UpgradeFirm.cpp index a1b7ac3c..f98312dd 100644 --- a/src/UpgradeFirm.cpp +++ b/src/UpgradeFirm.cpp @@ -25,7 +25,7 @@ void upgradeInit() { if (isNetworkActive()) { getLastVersion(); if (lastVersion > 0) { - SerialPrint("I", "Update", "available version: " + lastVersion); + SerialPrint("I", "Update", "available version: " + String(lastVersion)); } }; } diff --git a/src/Utils/FileUtils.cpp b/src/Utils/FileUtils.cpp index 5d7fe2ba..32b52beb 100644 --- a/src/Utils/FileUtils.cpp +++ b/src/Utils/FileUtils.cpp @@ -1,5 +1,6 @@ #include "Utils/FileUtils.h" -#include "Utils/PrintMessage.h" +#include "Utils\SerialPrint.h" +#include "Utils/StringUtils.h" diff --git a/src/Utils/SerialPrint.cpp b/src/Utils/SerialPrint.cpp index 8f57b3dd..77f6047c 100644 --- a/src/Utils/SerialPrint.cpp +++ b/src/Utils/SerialPrint.cpp @@ -3,7 +3,7 @@ #include "Global.h" void SerialPrint(String errorLevel, String module, String msg) { - //if (module == "Stat" || module == "Update") { + //if (module == "Stat") { Serial.println(prettyMillis(millis()) + " [" + errorLevel + "] [" + module + "] " + msg); //} } \ No newline at end of file diff --git a/src/Utils/SysUtils.cpp b/src/Utils/SysUtils.cpp index eefdc87a..a9f507a1 100644 --- a/src/Utils/SysUtils.cpp +++ b/src/Utils/SysUtils.cpp @@ -1,7 +1,7 @@ #include "Utils/SysUtils.h" #include "Global.h" -#include "Utils/PrintMessage.h" + const String getUniqueId(const char* name) { return String(name) + getMacAddress(); diff --git a/src/items/InputTimeClass.cpp b/src/items/InputTimeClass.cpp index fa98061e..43d14b3f 100644 --- a/src/items/InputTimeClass.cpp +++ b/src/items/InputTimeClass.cpp @@ -1,7 +1,6 @@ #include "ItemsCmd.h" #include "items/InputClass.h" //==========================================Модуль ввода времени============================================ -//input-time time1 inputTime Ввод Введите.время 4 st[10-00-00] //========================================================================================================== InputClass myInputTime; void inputTime() { @@ -21,8 +20,7 @@ void inputTimeSet() { void handle_time_init() { ts.add( TIME, 1000, [&](void *) { - jsonWriteStr(configLiveJson, "time", timeNow->getTime()); - jsonWriteStr(configLiveJson, "timenow", timeNow->getTimeJson()); + jsonWriteStr(configLiveJson, "timenow", timeNow->getTime()); eventGen("timenow", ""); }, nullptr, true); diff --git a/src/items/SensorAnalogClass.cpp b/src/items/SensorAnalogClass.cpp index b335cc01..bba5cc60 100644 --- a/src/items/SensorAnalogClass.cpp +++ b/src/items/SensorAnalogClass.cpp @@ -8,7 +8,7 @@ void analogAdc() { mySensorAnalog.update(); String key = mySensorAnalog.gkey(); sCmd.addCommand(key.c_str(), analogReading); - sensorReadingMap += key + ","; + sensorReadingMap10sec += key + ","; mySensorAnalog.SensorAnalogInit(); mySensorAnalog.clear(); } diff --git a/src/items/sysUptime.cpp b/src/items/sysUptime.cpp index d52868ac..2f1b222c 100644 --- a/src/items/sysUptime.cpp +++ b/src/items/sysUptime.cpp @@ -7,16 +7,14 @@ void sysUptime() { myLineParsing.update(); String key = myLineParsing.gkey(); sCmd.addCommand(key.c_str(), uptimeReading); - sensorReadingMap += key + ","; + sensorReadingMap30sec += key + ","; myLineParsing.clear(); } void uptimeReading() { String key = sCmd.order(); - eventGen(key, ""); String uptime = timeNow->getUptime(); - uptime.replace(":", "-"); jsonWriteStr(configLiveJson, key, uptime); publishStatus(key, uptime); - Serial.println("I sensor '" + key + "' data: " + uptime); + SerialPrint("I", "Sensor", "'" + key + "' data: " + uptime); } \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index fce31a41..d6a64e9f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -116,16 +116,4 @@ void loop() { myNotAsyncActions->loop(); ts.update(); -} - -void clock_init() { - timeNow = new Clock(); - timeNow->setNtpPool(jsonReadStr(configSetupJson, "ntp")); - timeNow->setTimezone(jsonReadStr(configSetupJson, "timezone").toInt()); - - ts.add( - TIME_SYNC, 30000, [&](void*) { - timeNow->hasSync(); - }, - nullptr, true); -} +} \ No newline at end of file