From 3bafbb88df4ff13423a891700b2e164c9d068c79 Mon Sep 17 00:00:00 2001 From: Yuri Trikoz Date: Sun, 18 Oct 2020 00:07:57 +0300 Subject: [PATCH 1/7] ESP32 target --- include/FSEditor.h | 7 +- include/SSDP.h | 3 +- include/Servo/Servos.h | 4 ++ include/{UpgradeFirm.h => Upgrade.h} | 0 include/items/SensorAnalogClass.h | 6 +- platformio.ini | 6 +- src/FSEditor.cpp | 101 +++++++++++++++------------ src/SSDP.cpp | 8 ++- src/UpgradeFirm.cpp | 19 ++++- src/Utils/statUtils.cpp | 67 +++++++++++++++--- 10 files changed, 157 insertions(+), 64 deletions(-) rename include/{UpgradeFirm.h => Upgrade.h} (100%) diff --git a/include/FSEditor.h b/include/FSEditor.h index 394fb0e2..69282648 100644 --- a/include/FSEditor.h +++ b/include/FSEditor.h @@ -15,6 +15,9 @@ class FSEditor : public AsyncWebHandler { bool _authenticated; uint32_t _startTime; + private: + void getDirList(const String& path, String& output); + public: #ifdef ESP32 FSEditor(const fs::FS& fs, const String& username = String(), const String& password = String()); @@ -24,5 +27,7 @@ class FSEditor : public AsyncWebHandler { virtual bool canHandle(AsyncWebServerRequest* request) override final; virtual void handleRequest(AsyncWebServerRequest* request) override final; virtual void handleUpload(AsyncWebServerRequest* request, const String& filename, size_t index, uint8_t* data, size_t len, bool final) override final; - virtual bool isRequestHandlerTrivial() override final { return false; } + virtual bool isRequestHandlerTrivial() override final { + return false; + } }; \ No newline at end of file diff --git a/include/SSDP.h b/include/SSDP.h index 0b13d706..db6afb58 100644 --- a/include/SSDP.h +++ b/include/SSDP.h @@ -1,6 +1,7 @@ #pragma once -#include "Global.h" + #include + #ifdef SSDP_EN extern void SsdpInit(); extern String xmlNode(String tags, String data); diff --git a/include/Servo/Servos.h b/include/Servo/Servos.h index c4ac44dd..db53c01e 100644 --- a/include/Servo/Servos.h +++ b/include/Servo/Servos.h @@ -1,7 +1,11 @@ #pragma once #include +#ifdef ESP8266 #include +#else +#include +#endif struct Servo_t { uint8_t num; diff --git a/include/UpgradeFirm.h b/include/Upgrade.h similarity index 100% rename from include/UpgradeFirm.h rename to include/Upgrade.h diff --git a/include/items/SensorAnalogClass.h b/include/items/SensorAnalogClass.h index 2a5c601b..2c1eab4d 100644 --- a/include/items/SensorAnalogClass.h +++ b/include/items/SensorAnalogClass.h @@ -16,21 +16,19 @@ class SensorAnalogClass : public SensorConvertingClass { } int SensorAnalogRead(String key, String pin) { - int pinInt = pin.toInt(); int value; - #ifdef ESP32 + int pinInt = pin.toInt(); value = analogRead(pinInt); #endif #ifdef ESP8266 value = analogRead(A0); #endif - value = this->mapping(key, value); float valueFl = this->correction(key, value); eventGen(key, ""); jsonWriteStr(configLiveJson, key, String(valueFl)); - publishStatus(key, String(valueFl)); + publishStatus(key, String(valueFl)); Serial.println("I sensor '" + key + "' data: " + String(valueFl)); return value; } diff --git a/platformio.ini b/platformio.ini index c8a85a0f..91d47aa1 100644 --- a/platformio.ini +++ b/platformio.ini @@ -37,7 +37,7 @@ lib_deps = ESP32Servo LITTLEFS monitor_filters = esp32_exception_decoder -upload_speed = 921600 +;upload_speed = 921600 monitor_speed = 115200 board_build.filesystem = littlefs @@ -56,7 +56,7 @@ monitor_filters = esp8266_exception_decoder upload_speed = 921600 monitor_speed = 115200 board_build.filesystem = littlefs -board_build.f_cpu = 160000000L +;board_build.f_cpu = 160000000L [env:esp8266] framework = arduino @@ -69,7 +69,7 @@ lib_deps = ESPAsyncUDP EspSoftwareSerial monitor_filters = esp8266_exception_decoder -upload_speed = 921600 +;upload_speed = 921600 monitor_speed = 115200 board_build.filesystem = littlefs board_build.f_cpu = 160000000L diff --git a/src/FSEditor.cpp b/src/FSEditor.cpp index bdaa5129..5f33d075 100644 --- a/src/FSEditor.cpp +++ b/src/FSEditor.cpp @@ -167,58 +167,73 @@ bool FSEditor::canHandle(AsyncWebServerRequest *request) { return false; } +#ifdef ESP8266 +void FSEditor::getDirList(const String &path, String &output) { + auto dir = _fs.openDir(path.c_str()); + while (dir.next()) { + String fname = dir.fileName(); + if (!path.endsWith("/") && !fname.startsWith("/")) { + fname = "/" + fname; + } + fname = path + fname; + if (isExcluded(_fs, fname.c_str())) { + continue; + } + if (dir.isDirectory()) { + getDirList(fname, output); + continue; + } + if (output != "[") output += ','; + char buf[128]; + sprintf(buf, "{\"type\":\"file\",\"name\":\"%s\",\"size\":%d}", fname.c_str(), dir.fileSize()); + output += buf; + } +} +#else +void FSEditor::getDirList(const String &path, String &output) { + auto dir = _fs.open(path, FILE_READ); + dir.rewindDirectory(); + while (dir.openNextFile()) { + String fname = dir.name(); + if (!path.endsWith("/") && !fname.startsWith("/")) { + fname = "/" + fname; + } + fname = path + fname; + if (isExcluded(_fs, fname.c_str())) { + continue; + } + if (dir.isDirectory()) { + getDirList(fname, output); + continue; + } + if (output != "[") output += ','; + char buf[128]; + sprintf(buf, "{\"type\":\"file\",\"name\":\"%s\",\"size\":%d}", fname.c_str(), dir.size()); + output += buf; + } +} +#endif + void FSEditor::handleRequest(AsyncWebServerRequest *request) { if (_username.length() && _password.length() && !request->authenticate(_username.c_str(), _password.c_str())) return request->requestAuthentication(); if (request->method() == HTTP_GET) { if (request->hasParam("list")) { - String path = request->getParam("list")->value(); -#ifdef ESP32 - File dir = _fs.open(path); -#else - fs::Dir dir = _fs.openDir(path); -#endif - path = String(); - String output = "["; -#ifdef ESP32 - File entry = dir.openNextFile(); - while (entry) { -#else - while (dir.next()) { - fs::File entry = dir.openFile("r"); -#endif - String fname = entry.fullName(); - if (fname.charAt(0) != '/') fname = "/" + fname; - - if (isExcluded(_fs, fname.c_str())) { -#ifdef ESP32 - entry = dir.openNextFile(); -#endif - continue; - } - if (output != "[") output += ','; - output += "{\"type\":\""; - output += "file"; - output += "\",\"name\":\""; - output += String(fname); - output += "\",\"size\":"; - output += String(entry.size()); - output += "}"; -#ifdef ESP32 - entry = dir.openNextFile(); -#else - entry.close(); -#endif + if (request->hasParam("list")) { + String path = request->getParam("list")->value(); + String output = "["; + getDirList(path, output); + output += "]"; + request->send(200, "application/json", output); + output = String(); } -#ifdef ESP32 - dir.close(); -#endif - output += "]"; - request->send(200, "application/json", output); - output = String(); } else if (request->hasParam("edit") || request->hasParam("download")) { +#ifdef ESP8266 request->send(request->_tempFile, request->_tempFile.fullName(), String(), request->hasParam("download")); +#else + request->send(request->_tempFile, request->_tempFile.name(), String(), request->hasParam("download")); +#endif } else { const char *buildTime = __DATE__ " " __TIME__ " GMT"; if (request->header("If-Modified-Since").equals(buildTime)) { diff --git a/src/SSDP.cpp b/src/SSDP.cpp index 108bef62..f6dfc790 100644 --- a/src/SSDP.cpp +++ b/src/SSDP.cpp @@ -1,12 +1,14 @@ -#include +#include "SSDP.h" + #include "Global.h" + #ifdef SSDP_EN #ifdef ESP8266 - #include +#include #endif #ifdef ESP32 - #include +#include #endif //39164 //457684 diff --git a/src/UpgradeFirm.cpp b/src/UpgradeFirm.cpp index da099ac1..780dfdc7 100644 --- a/src/UpgradeFirm.cpp +++ b/src/UpgradeFirm.cpp @@ -1,7 +1,12 @@ -#include "UpgradeFirm.h" +#include "Upgrade.h" #include "Class/NotAsinc.h" +#ifdef ESP8266 #include "ESP8266.h" +#else +#include +#endif + #include "Global.h" void upgradeInit() { @@ -78,8 +83,13 @@ bool upgradeFS() { WiFiClient wifiClient; bool ret = false; Serial.println("Start upgrade LittleFS, please wait..."); +#ifdef ESP8266 ESPhttpUpdate.rebootOnUpdate(false); t_httpUpdate_return retFS = ESPhttpUpdate.updateSpiffs(wifiClient, F("http://95.128.182.133/projects/iotmanager/esp8266/littlefs/littlefs.bin")); +#else + httpUpdate.rebootOnUpdate(false); + HTTPUpdateResult retFS = httpUpdate.updateSpiffs(wifiClient, F("http://95.128.182.133/projects/iotmanager/esp8266/littlefs/littlefs.bin")); +#endif if (retFS == HTTP_UPDATE_OK) { //если FS обновилась успешно SerialPrint("I", "Update", "LittleFS upgrade done!"); ret = true; @@ -91,8 +101,15 @@ bool upgradeBuild() { WiFiClient wifiClient; bool ret = false; Serial.println("Start upgrade BUILD, please wait..."); + +#ifdef ESP8266 ESPhttpUpdate.rebootOnUpdate(false); t_httpUpdate_return retBuild = ESPhttpUpdate.update(wifiClient, F("http://95.128.182.133/projects/iotmanager/esp8266/firmware/firmware.bin")); +#else + httpUpdate.rebootOnUpdate(false); + HTTPUpdateResult retBuild = httpUpdate.update(wifiClient, F("http://95.128.182.133/projects/iotmanager/esp8266/firmware/firmware.bin")); +#endif + if (retBuild == HTTP_UPDATE_OK) { //если BUILD обновился успешно SerialPrint("I", "Update", "BUILD upgrade done!"); ret = true; diff --git a/src/Utils/statUtils.cpp b/src/Utils/statUtils.cpp index 25529ca6..7587ca21 100644 --- a/src/Utils/statUtils.cpp +++ b/src/Utils/statUtils.cpp @@ -6,6 +6,11 @@ #include "Global.h" #include "ItemsList.h" +#ifdef ESP32 +#include +#endif + +String ESP_getResetReason(void); void initSt() { addNewDevice(); @@ -25,7 +30,7 @@ void initSt() { void decide() { if ((WiFi.status() == WL_CONNECTED)) { uint8_t cnt = getNextNumber("stat.txt"); - SerialPrint("I","Stat","Total resets number: " + String(cnt)); + SerialPrint("I", "Stat", "Total resets number: " + String(cnt)); if (cnt <= 3) { //Serial.println("(get)"); getPsn(); @@ -81,7 +86,7 @@ String addNewDevice() { } http.end(); } - SerialPrint("I","Stat","New device registaration: " + ret); + SerialPrint("I", "Stat", "New device registaration: " + ret); return ret; } @@ -95,7 +100,7 @@ String updateDevicePsn(String lat, String lon, String accur) { http.addHeader("Content-Type", "application/json"); String mac = WiFi.macAddress().c_str(); int httpCode = http.POST("?id=" + mac + - "&resetReason=" + ESP.getResetReason() + + "&resetReason=" + ESP_getResetReason() + "&lat=" + lat + "&lon=" + lon + "&accuracy=" + accur + ""); @@ -110,7 +115,7 @@ String updateDevicePsn(String lat, String lon, String accur) { } http.end(); } - SerialPrint("I","Stat","Update device psn: " + ret); + SerialPrint("I", "Stat", "Update device psn: " + ret); return ret; } @@ -124,10 +129,10 @@ String updateDeviceStatus() { http.addHeader("Content-Type", "application/json"); String mac = WiFi.macAddress().c_str(); int httpCode = http.POST("?id=" + mac + - "&resetReason=" + ESP.getResetReason() + + "&resetReason=" + ESP_getResetReason() + "&uptime=" + timeNow->getUptime() + "&uptimeTotal=" + getUptimeTotal() + - "&version=" + FIRMWARE_VERSION + + "&version=" + FIRMWARE_VERSION + "&resetsTotal=" + String(getCurrentNumber("stat.txt")) + ""); if (httpCode > 0) { ret = httpCode; @@ -140,14 +145,14 @@ String updateDeviceStatus() { } http.end(); } - SerialPrint("I","Stat","Update device data: " + ret); + SerialPrint("I", "Stat", "Update device data: " + ret); return ret; } String getUptimeTotal() { uint8_t hrs = getCurrentNumber("totalhrs.txt"); String hrsStr = prettySeconds(hrs * 60 * 60); - SerialPrint("I","Stat","Total running time: " + hrsStr); + SerialPrint("I", "Stat", "Total running time: " + hrsStr); return hrsStr; } @@ -164,7 +169,53 @@ uint8_t getCurrentNumber(String file) { return number; } +#ifdef ESP8266 +String ESP_getResetReason(void) { + return ESP.getResetReason(); +} +#else +String ESP32GetResetReason(uint32_t cpu_no) { + // tools\sdk\include\esp32\rom\rtc.h + switch (rtc_get_reset_reason((RESET_REASON)cpu_no)) { + case POWERON_RESET: + return F("Vbat power on reset"); // 1 + case SW_RESET: + return F("Software reset digital core"); // 3 + case OWDT_RESET: + return F("Legacy watch dog reset digital core"); // 4 + case DEEPSLEEP_RESET: + return F("Deep Sleep reset digital core"); // 5 + case SDIO_RESET: + return F("Reset by SLC module, reset digital core"); // 6 + case TG0WDT_SYS_RESET: + return F("Timer Group0 Watch dog reset digital core"); // 7 + case TG1WDT_SYS_RESET: + return F("Timer Group1 Watch dog reset digital core"); // 8 + case RTCWDT_SYS_RESET: + return F("RTC Watch dog Reset digital core"); // 9 + case INTRUSION_RESET: + return F("Instrusion tested to reset CPU"); // 10 + case TGWDT_CPU_RESET: + return F("Time Group reset CPU"); // 11 + case SW_CPU_RESET: + return F("Software reset CPU"); // 12 + case RTCWDT_CPU_RESET: + return F("RTC Watch dog Reset CPU"); // 13 + case EXT_CPU_RESET: + return F("or APP CPU, reseted by PRO CPU"); // 14 + case RTCWDT_BROWN_OUT_RESET: + return F("Reset when the vdd voltage is not stable"); // 15 + case RTCWDT_RTC_RESET: + return F("RTC Watch dog reset digital core and rtc module"); // 16 + default: + return F("NO_MEAN"); // 0 + } +} +String ESP_getResetReason(void) { + return ESP32GetResetReason(0); // CPU 0 +} +#endif //String getUptimeTotal() { // static int hrs; // EEPROM.begin(512); From cd9a6c98fa21ba8f834b25960f6a777fa3cc91f3 Mon Sep 17 00:00:00 2001 From: Yuri Trikoz Date: Sun, 18 Oct 2020 01:47:02 +0300 Subject: [PATCH 2/7] SSDP_EN --- include/Consts.h | 3 +-- include/SSDP.h | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/Consts.h b/include/Consts.h index e023921c..46405583 100644 --- a/include/Consts.h +++ b/include/Consts.h @@ -25,7 +25,7 @@ //#define WEBSOCKET_ENABLED //#define LAYOUT_IN_RAM //#define UDP_ENABLED -//#define SSDP_EN +#define SSDP_EN //=========Sensors enable/disable=========== #define TANK_LEVEL_SAMPLES 10 @@ -45,7 +45,6 @@ #define SERIAL_ENABLED #define PUSH_ENABLED - struct Time_t { uint8_t second; uint8_t minute; diff --git a/include/SSDP.h b/include/SSDP.h index db6afb58..a93ccdaf 100644 --- a/include/SSDP.h +++ b/include/SSDP.h @@ -2,6 +2,8 @@ #include +#include "Consts.h" + #ifdef SSDP_EN extern void SsdpInit(); extern String xmlNode(String tags, String data); From 642695906066b0c076233f2ac725170b4c0996e9 Mon Sep 17 00:00:00 2001 From: Yuri Trikoz Date: Sun, 18 Oct 2020 02:27:08 +0300 Subject: [PATCH 3/7] ESP32 SSDP --- include/Utils/SysUtils.h | 4 +++- platformio.ini | 1 + src/SSDP.cpp | 2 +- src/Utils/SysUtils.cpp | 33 ++++++++++++++++++++++----------- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/include/Utils/SysUtils.h b/include/Utils/SysUtils.h index 1686e51f..de03e287 100644 --- a/include/Utils/SysUtils.h +++ b/include/Utils/SysUtils.h @@ -2,6 +2,8 @@ #include #include "Global.h" +uint32_t ESP_getChipId(); + const String getChipId(); void setLedStatus(LedStatus_t status); @@ -14,4 +16,4 @@ const String getHeapStats(); const String getMacAddress(); -void setChipId(); \ No newline at end of file +void setChipId(); diff --git a/platformio.ini b/platformio.ini index 91d47aa1..ccf0d6b1 100644 --- a/platformio.ini +++ b/platformio.ini @@ -36,6 +36,7 @@ lib_deps = AsyncTCP ESP32Servo LITTLEFS + luc-github/ESP32SSDP monitor_filters = esp32_exception_decoder ;upload_speed = 921600 monitor_speed = 115200 diff --git a/src/SSDP.cpp b/src/SSDP.cpp index f6dfc790..3b2f3c89 100644 --- a/src/SSDP.cpp +++ b/src/SSDP.cpp @@ -33,7 +33,7 @@ void SsdpInit() { ssdpDescription += xmlNode(F("modelURL"), F("https://github.com/IoTManagerProject/IoTManager/wiki")); ssdpDescription += xmlNode(F("manufacturer"), F("Borisenko Dmitry")); ssdpDescription += xmlNode(F("manufacturerURL"), F("https://github.com/IoTManagerProject/IoTManager")); - ssdpDescription += xmlNode(F("UDN"), "uuid:38323636-4558-4dda-9188-cda0e6" + decToHex(ESP.getChipId(), 6)); + ssdpDescription += xmlNode(F("UDN"), "uuid:38323636-4558-4dda-9188-cda0e6" + decToHex(ESP_getChipId(), 6)); ssdpDescription = xmlNode("device", ssdpDescription); ssdpHeder += ssdpDescription; ssdpSend += ssdpHeder; diff --git a/src/Utils/SysUtils.cpp b/src/Utils/SysUtils.cpp index 48704aea..eefdc87a 100644 --- a/src/Utils/SysUtils.cpp +++ b/src/Utils/SysUtils.cpp @@ -3,28 +3,39 @@ #include "Global.h" #include "Utils/PrintMessage.h" - const String getUniqueId(const char* name) { return String(name) + getMacAddress(); } -const String getChipId() { - String res; +uint32_t ESP_getChipId(void) { #ifdef ESP32 - char buf[32] = {0}; - uint32_t mac = ESP.getEfuseMac(); - sprintf(buf, "%0X", mac); - res = String(buf); + uint32_t id = 0; + for (uint32_t i = 0; i < 17; i = i + 8) { + id |= ((ESP.getEfuseMac() >> (40 - i)) & 0xff) << i; + } + return id; +#else + return ESP.getChipId(); #endif -#ifdef ESP8266 - res = String(ESP.getChipId()) + "-" + String(ESP.getFlashChipId()); +} + +uint32_t ESP_getFlashChipId(void) { +#ifdef ESP32 + // Нет аналогичной (без доп.кода) функций в 32 + // надо использовать другой id - варианты есть + return ESP_getChipId(); +#else + return ESP.getFlashChipId(); #endif - return res; +} + +const String getChipId() { + return String(ESP_getChipId()) + "-" + String(ESP_getFlashChipId()); } void setChipId() { chipId = getChipId(); - SerialPrint("I","System","id: " + chipId); + SerialPrint("I", "System", "id: " + chipId); } #ifdef ESP8266 From 74b526e2f1eeac376ec8f942c0f21de570fe0296 Mon Sep 17 00:00:00 2001 From: Yuri Trikoz Date: Sun, 18 Oct 2020 09:38:24 +0300 Subject: [PATCH 4/7] new platformio lib_deps format --- platformio.ini | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/platformio.ini b/platformio.ini index ccf0d6b1..a0075b81 100644 --- a/platformio.ini +++ b/platformio.ini @@ -13,14 +13,14 @@ default_envs = esp8266 [common_env_data] lib_deps_external = - ArduinoJson@5.* - Bounce2 - PubSubClient - DHT sensor library for ESPx - Adafruit BMP280 Library - Adafruit BME280 Library - DallasTemperature - ESP Async UDP + bblanchon/ArduinoJson @5.* + thomasfredericks/Bounce2 + knolleary/PubSubClient + beegee-tokyo/DHT sensor library for ESPx + adafruit/Adafruit BMP280 Library + adafruit/Adafruit BME280 Library + milesburton/DallasTemperature + me-no-dev/ESPAsyncUDP lib_deps_internal = ESP Async WebServer GyverFilters @@ -33,8 +33,8 @@ platform = https://github.com/platformio/platform-espressif32.git lib_deps = ${common_env_data.lib_deps_external} ${common_env_data.lib_deps_internal} - AsyncTCP - ESP32Servo + me-no-dev/ESPAsyncTCP + madhephaestus/ESP32Servo LITTLEFS luc-github/ESP32SSDP monitor_filters = esp32_exception_decoder From d3ad04eae6ab4c9ffbc8a154f165fbc118baa1e5 Mon Sep 17 00:00:00 2001 From: Yuri Trikoz Date: Sun, 18 Oct 2020 09:39:37 +0300 Subject: [PATCH 5/7] https://en.cppreference.com/w/c/comment --- include/Consts.h | 38 ++++++++++++++++++++++++++++---------- include/SSDP.h | 6 ++---- src/SSDP.cpp | 8 ++++++-- 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/include/Consts.h b/include/Consts.h index 46405583..3038dcfd 100644 --- a/include/Consts.h +++ b/include/Consts.h @@ -1,33 +1,47 @@ #pragma once -//=================Firmeare================= +// +// Firmware +// #define FIRMWARE_NAME "esp8266-iotm" #define FIRMWARE_VERSION 257 #define FLASH_4MB true -//=================System=================== +// +// System +// #define NUM_BUTTONS 6 #define LED_PIN 2 -//=================MQTT===================== +// +// MQTT +// #define MQTT_RECONNECT_INTERVAL 20000 -//===============Telemetry================== +// +// Telemetry +// #define TELEMETRY_UPDATE_INTERVAL_MIN 60 -//=============Configuration================ +// +// Configuration +// #define DEVICE_CONFIG_FILE "s.conf.csv" #define DEVICE_SCENARIO_FILE "s.scen.txt" -//=============System parts================= +// +// System parts +// //#define OTA_UPDATES_ENABLED //#define MDNS_ENABLED //#define WEBSOCKET_ENABLED //#define LAYOUT_IN_RAM //#define UDP_ENABLED -#define SSDP_EN +#define SSDP_ENABLED -//=========Sensors enable/disable=========== +// +// Sensors enable/disable +// #define TANK_LEVEL_SAMPLES 10 #define LEVEL_ENABLED #define ANALOG_ENABLED @@ -36,11 +50,15 @@ #define BMP_ENABLED #define BME_ENABLED -//=========Gears enable/disable=========== +// +// Gears enable/disable +// #define STEPPER_ENABLED #define SERVO_ENABLED -//=========Other enable/disable=========== +// +// Other enable/disable +// #define LOGGING_ENABLED #define SERIAL_ENABLED #define PUSH_ENABLED diff --git a/include/SSDP.h b/include/SSDP.h index a93ccdaf..353b193c 100644 --- a/include/SSDP.h +++ b/include/SSDP.h @@ -4,8 +4,6 @@ #include "Consts.h" -#ifdef SSDP_EN -extern void SsdpInit(); -extern String xmlNode(String tags, String data); -extern String decToHex(uint32_t decValue, byte desiredStringLength); +#ifdef SSDP_ENABLED +void SsdpInit(); #endif \ No newline at end of file diff --git a/src/SSDP.cpp b/src/SSDP.cpp index 3b2f3c89..b42f6db7 100644 --- a/src/SSDP.cpp +++ b/src/SSDP.cpp @@ -1,15 +1,19 @@ - #include "SSDP.h" #include "Global.h" -#ifdef SSDP_EN +#ifdef SSDP_ENABLED #ifdef ESP8266 #include #endif #ifdef ESP32 #include #endif + +String xmlNode(String tags, String data); + +String decToHex(uint32_t decValue, byte desiredStringLength); + //39164 //457684 void SsdpInit() { From 281f338f97fd015131303703bf460cfb9219524e Mon Sep 17 00:00:00 2001 From: Yuri Trikoz Date: Sun, 18 Oct 2020 09:52:17 +0300 Subject: [PATCH 6/7] Typos with Asinc and \ in path --- include/Class/NotAsinc.h | 31 ------------------------------- include/Class/NotAsync.h | 32 ++++++++++++++++++++++++++++++++ include/Consts.h | 2 +- include/Global.h | 14 +++++++------- include/Utils/PrintMessage.h | 4 ++-- platformio.ini | 1 - src/Bus.cpp | 4 ++-- src/Class/NotAsinc.cpp | 30 ------------------------------ src/Class/NotAsync.cpp | 30 ++++++++++++++++++++++++++++++ src/ItemsCmd.cpp | 4 ++-- src/ItemsList.cpp | 8 ++++---- src/MqttClient.cpp | 6 +++--- src/UpgradeFirm.cpp | 6 +++--- src/Utils/JsonUtils.cpp | 2 +- src/Utils/StringUtils.cpp | 2 +- src/Utils/TimeUtils.cpp | 4 ++-- src/Utils/WebUtils.cpp | 4 +--- src/Web.cpp | 24 ++++++++++++------------ src/main.cpp | 8 ++++---- 19 files changed, 107 insertions(+), 109 deletions(-) delete mode 100644 include/Class/NotAsinc.h create mode 100644 include/Class/NotAsync.h delete mode 100644 src/Class/NotAsinc.cpp create mode 100644 src/Class/NotAsync.cpp diff --git a/include/Class/NotAsinc.h b/include/Class/NotAsinc.h deleted file mode 100644 index 73d45196..00000000 --- a/include/Class/NotAsinc.h +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once -#include -#include - -#include - -typedef std::function NotAsincCb; - -struct NotAsincItem { - bool test; - NotAsincCb cb; - void * cb_arg; - volatile bool is_used = false; -}; - -class NotAsinc { - private: - uint8_t size; - uint8_t task = 0; - NotAsincItem* items = NULL; - void handle(NotAsincCb f, void* arg); - - public: - NotAsinc(uint8_t size); - ~NotAsinc(); - - void add(uint8_t i, NotAsincCb, void* arg); - void make(uint8_t task); - void loop(); -}; -extern NotAsinc* myNotAsincActions; \ No newline at end of file diff --git a/include/Class/NotAsync.h b/include/Class/NotAsync.h new file mode 100644 index 00000000..1d5278cc --- /dev/null +++ b/include/Class/NotAsync.h @@ -0,0 +1,32 @@ +#pragma once +#include +#include + +#include + +typedef std::function NotAsyncCb; + +struct NotAsyncItem { + bool test; + NotAsyncCb cb; + void* cb_arg; + volatile bool is_used = false; +}; + +class NotAsync { + private: + uint8_t size; + uint8_t task = 0; + NotAsyncItem* items = NULL; + void handle(NotAsyncCb f, void* arg); + + public: + NotAsync(uint8_t size); + ~NotAsync(); + + void add(uint8_t i, NotAsyncCb, void* arg); + void make(uint8_t task); + void loop(); +}; + +extern NotAsync* myNotAsyncActions; \ No newline at end of file diff --git a/include/Consts.h b/include/Consts.h index 3038dcfd..36bfcf3c 100644 --- a/include/Consts.h +++ b/include/Consts.h @@ -96,7 +96,7 @@ enum TimerTask_t { WIFI_SCAN, UDP_DB, TEST }; -enum notAsincActions { +enum NotAsyncActions { do_ZERO, do_UPGRADE, do_GETLASTVERSION, diff --git a/include/Global.h b/include/Global.h index d08aeab3..e5d0eaed 100644 --- a/include/Global.h +++ b/include/Global.h @@ -13,13 +13,13 @@ #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 "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 diff --git a/include/Utils/PrintMessage.h b/include/Utils/PrintMessage.h index 833342b6..637b793f 100644 --- a/include/Utils/PrintMessage.h +++ b/include/Utils/PrintMessage.h @@ -1,8 +1,8 @@ #pragma once #include "Arduino.h" -#include "Utils\StringUtils.h" -#include "Utils\TimeUtils.h" +#include "Utils/StringUtils.h" +#include "Utils/TimeUtils.h" #include "Errors.h" #include "Global.h" diff --git a/platformio.ini b/platformio.ini index a0075b81..31ac6233 100644 --- a/platformio.ini +++ b/platformio.ini @@ -20,7 +20,6 @@ lib_deps_external = adafruit/Adafruit BMP280 Library adafruit/Adafruit BME280 Library milesburton/DallasTemperature - me-no-dev/ESPAsyncUDP lib_deps_internal = ESP Async WebServer GyverFilters diff --git a/src/Bus.cpp b/src/Bus.cpp index 49cbaa54..12cbcf6a 100644 --- a/src/Bus.cpp +++ b/src/Bus.cpp @@ -1,9 +1,9 @@ #include "Bus.h" -#include "Class/NotAsinc.h" +#include "Class/NotAsync.h" #include "Global.h" void busInit() { - myNotAsincActions->add( + myNotAsyncActions->add( do_BUSSCAN, [&](void*) { String tmp = i2c_scan(); if (tmp == "error") { diff --git a/src/Class/NotAsinc.cpp b/src/Class/NotAsinc.cpp deleted file mode 100644 index f1c8f5f9..00000000 --- a/src/Class/NotAsinc.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include "Class/NotAsinc.h" - -NotAsinc::NotAsinc(uint8_t size) { - this->items = new NotAsincItem[size]; - this->size = size; -} - -NotAsinc::~NotAsinc() {} - -void NotAsinc::add(uint8_t i, NotAsincCb f, void* arg) { - this->items[i].cb = f; - this->items[i].cb_arg = arg; - this->items[i].is_used = true; -} - -void NotAsinc::loop() { - if (this->items[task].is_used) { - handle(this->items[task].cb, this->items[task].cb_arg); - task = 0; - } -} - -void NotAsinc::make(uint8_t task) { - this->task = task; -} - -void NotAsinc::handle(NotAsincCb f, void* arg) { - f(arg); -} -NotAsinc* myNotAsincActions; \ No newline at end of file diff --git a/src/Class/NotAsync.cpp b/src/Class/NotAsync.cpp new file mode 100644 index 00000000..75c2ce24 --- /dev/null +++ b/src/Class/NotAsync.cpp @@ -0,0 +1,30 @@ +#include "Class/NotAsync.h" + +NotAsync::NotAsync(uint8_t size) { + this->items = new NotAsyncItem[size]; + this->size = size; +} + +NotAsync::~NotAsync() {} + +void NotAsync::add(uint8_t i, NotAsyncCb f, void* arg) { + this->items[i].cb = f; + this->items[i].cb_arg = arg; + this->items[i].is_used = true; +} + +void NotAsync::loop() { + if (this->items[task].is_used) { + handle(this->items[task].cb, this->items[task].cb_arg); + task = 0; + } +} + +void NotAsync::make(uint8_t task) { + this->task = task; +} + +void NotAsync::handle(NotAsyncCb f, void* arg) { + f(arg); +} +NotAsync* myNotAsyncActions; \ No newline at end of file diff --git a/src/ItemsCmd.cpp b/src/ItemsCmd.cpp index 5521806c..af43621e 100644 --- a/src/ItemsCmd.cpp +++ b/src/ItemsCmd.cpp @@ -1,7 +1,7 @@ #include "ItemsCmd.h" #include "BufferExecute.h" -#include "Class/NotAsinc.h" +#include "Class/NotAsync.h" #include "Cmd.h" #include "Global.h" #include "Module/Terminal.h" @@ -313,7 +313,7 @@ void cmd_init() { //} // //void firmwareUpdate() { -// myNotAsincActions->make(do_UPGRADE); +// myNotAsyncActions->make(do_UPGRADE); //} // //void firmwareVersion() { diff --git a/src/ItemsList.cpp b/src/ItemsList.cpp index 4ad89cd6..d6803b23 100644 --- a/src/ItemsList.cpp +++ b/src/ItemsList.cpp @@ -1,19 +1,19 @@ #include "ItemsList.h" -#include "Class\NotAsinc.h" +#include "Class/NotAsync.h" #include "Init.h" -#include "Utils\StringUtils.h" +#include "Utils/StringUtils.h" static const char* firstLine PROGMEM = "Удалить;Тип элемента;Id;Виджет;Имя вкладки;Имя виджета;Позиция виджета"; void itemsListInit() { - myNotAsincActions->add( + myNotAsyncActions->add( do_deviceInit, [&](void*) { Device_init(); }, nullptr); - myNotAsincActions->add( + myNotAsyncActions->add( do_delChoosingItems, [&](void*) { delChoosingItems(); }, diff --git a/src/MqttClient.cpp b/src/MqttClient.cpp index 5d726c00..e2c76b0c 100644 --- a/src/MqttClient.cpp +++ b/src/MqttClient.cpp @@ -2,7 +2,7 @@ #include -#include "Class/NotAsinc.h" +#include "Class/NotAsync.h" #include "Global.h" #include "Init.h" @@ -10,7 +10,7 @@ String mqttPrefix; String mqttRootDevice; void mqttInit() { - myNotAsincActions->add( + myNotAsyncActions->add( do_MQTTPARAMSCHANGED, [&](void*) { mqttReconnect(); }, @@ -133,7 +133,7 @@ void mqttCallback(char* topic, uint8_t* payload, size_t length) { } else if (topicStr.indexOf("update")) { if (payloadStr == "1") { - myNotAsincActions->make(do_UPGRADE); + myNotAsyncActions->make(do_UPGRADE); } } else if (topicStr.indexOf("devc")) { diff --git a/src/UpgradeFirm.cpp b/src/UpgradeFirm.cpp index 780dfdc7..669870f9 100644 --- a/src/UpgradeFirm.cpp +++ b/src/UpgradeFirm.cpp @@ -1,6 +1,6 @@ #include "Upgrade.h" -#include "Class/NotAsinc.h" +#include "Class/NotAsync.h" #ifdef ESP8266 #include "ESP8266.h" #else @@ -10,13 +10,13 @@ #include "Global.h" void upgradeInit() { - myNotAsincActions->add( + myNotAsyncActions->add( do_UPGRADE, [&](void*) { upgrade_firmware(3); }, nullptr); - myNotAsincActions->add( + myNotAsyncActions->add( do_GETLASTVERSION, [&](void*) { getLastVersion(); }, diff --git a/src/Utils/JsonUtils.cpp b/src/Utils/JsonUtils.cpp index 04b4b926..bcc2c761 100644 --- a/src/Utils/JsonUtils.cpp +++ b/src/Utils/JsonUtils.cpp @@ -1,4 +1,4 @@ -#include "Utils\JsonUtils.h" +#include "Utils/JsonUtils.h" #include "Utils/FileUtils.h" #include "Global.h" diff --git a/src/Utils/StringUtils.cpp b/src/Utils/StringUtils.cpp index 7c043f0e..969cd59e 100644 --- a/src/Utils/StringUtils.cpp +++ b/src/Utils/StringUtils.cpp @@ -1,4 +1,4 @@ -#include "Utils\StringUtils.h" +#include "Utils/StringUtils.h" #include "Consts.h" String selectToMarkerLast(String str, String found) { diff --git a/src/Utils/TimeUtils.cpp b/src/Utils/TimeUtils.cpp index 1464a245..2b313e69 100644 --- a/src/Utils/TimeUtils.cpp +++ b/src/Utils/TimeUtils.cpp @@ -1,6 +1,6 @@ -#include "Utils\TimeUtils.h" +#include "Utils/TimeUtils.h" -#include "Utils\StringUtils.h" +#include "Utils/StringUtils.h" static const uint8_t days_in_month[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; static const char* week_days[7] = {"Sun", "Mon", "Tue", "Wed", "Thr", "Fri", "Sat"}; diff --git a/src/Utils/WebUtils.cpp b/src/Utils/WebUtils.cpp index fa0da202..8c766b0e 100644 --- a/src/Utils/WebUtils.cpp +++ b/src/Utils/WebUtils.cpp @@ -1,4 +1,4 @@ -#include "Utils\WebUtils.h" +#include "Utils/WebUtils.h" #include "ESPAsyncWebServer.h" String getURL(const String& urls) { @@ -17,8 +17,6 @@ String getURL(const String& urls) { - - const String getMethodName(AsyncWebServerRequest* request) { String res = F("UNKNOWN"); if (request->method() == HTTP_GET) diff --git a/src/Web.cpp b/src/Web.cpp index 07c8d914..409f9836 100644 --- a/src/Web.cpp +++ b/src/Web.cpp @@ -1,6 +1,6 @@ #include "Web.h" -#include "Class/NotAsinc.h" +#include "Class/NotAsync.h" #include "Global.h" #include "Init.h" #include "ItemsList.h" @@ -23,7 +23,7 @@ void web_init() { } if (request->hasArg("delChoosingItems")) { - myNotAsincActions->make(do_delChoosingItems); + myNotAsyncActions->make(do_delChoosingItems); request->send(200); } @@ -33,7 +33,7 @@ void web_init() { } if (request->hasArg("saveItems")) { - myNotAsincActions->make(do_deviceInit); + myNotAsyncActions->make(do_deviceInit); request->send(200); } @@ -142,37 +142,37 @@ void web_init() { if (request->hasArg("mqttServer")) { jsonWriteStr(configSetupJson, "mqttServer", request->getParam("mqttServer")->value()); saveConfig(); - myNotAsincActions->make(do_MQTTPARAMSCHANGED); + myNotAsyncActions->make(do_MQTTPARAMSCHANGED); request->send(200); } if (request->hasArg("mqttPort")) { int port = (request->getParam("mqttPort")->value()).toInt(); jsonWriteInt(configSetupJson, "mqttPort", port); saveConfig(); - myNotAsincActions->make(do_MQTTPARAMSCHANGED); + myNotAsyncActions->make(do_MQTTPARAMSCHANGED); request->send(200); } if (request->hasArg("mqttPrefix")) { jsonWriteStr(configSetupJson, "mqttPrefix", request->getParam("mqttPrefix")->value()); saveConfig(); - myNotAsincActions->make(do_MQTTPARAMSCHANGED); + myNotAsyncActions->make(do_MQTTPARAMSCHANGED); request->send(200); } if (request->hasArg("mqttUser")) { jsonWriteStr(configSetupJson, "mqttUser", request->getParam("mqttUser")->value()); saveConfig(); - myNotAsincActions->make(do_MQTTPARAMSCHANGED); + myNotAsyncActions->make(do_MQTTPARAMSCHANGED); request->send(200); } if (request->hasArg("mqttPass")) { jsonWriteStr(configSetupJson, "mqttPass", request->getParam("mqttPass")->value()); saveConfig(); - myNotAsincActions->make(do_MQTTPARAMSCHANGED); + myNotAsyncActions->make(do_MQTTPARAMSCHANGED); request->send(200); } if (request->hasArg("mqttsend")) { - myNotAsincActions->make(do_MQTTUDP); + myNotAsyncActions->make(do_MQTTUDP); request->send(200); } @@ -197,7 +197,7 @@ void web_init() { //==============================utilities settings============================================= if (request->hasArg("i2c")) { - myNotAsincActions->make(do_BUSSCAN); + myNotAsyncActions->make(do_BUSSCAN); request->redirect("/?set.utilities"); } }); @@ -219,7 +219,7 @@ void web_init() { * Check */ server.on("/check", HTTP_GET, [](AsyncWebServerRequest* request) { - myNotAsincActions->make(do_GETLASTVERSION); + myNotAsyncActions->make(do_GETLASTVERSION); SerialPrint("I", "Update", "firmware version: " + String(lastVersion)); String msg = ""; @@ -251,7 +251,7 @@ void web_init() { * Upgrade */ server.on("/upgrade", HTTP_GET, [](AsyncWebServerRequest* request) { - myNotAsincActions->make(do_UPGRADE); + myNotAsyncActions->make(do_UPGRADE); request->send(200, "text/html"); }); } diff --git a/src/main.cpp b/src/main.cpp index c86c10b9..c8ebba41 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,7 +3,7 @@ #include "BufferExecute.h" #include "Class/CallBackTest.h" -#include "Class/NotAsinc.h" +#include "Class/NotAsync.h" #include "Class/ScenarioClass.h" #include "Cmd.h" #include "Global.h" @@ -11,7 +11,7 @@ #include "ItemsList.h" #include "Utils/StatUtils.h" #include "Utils/Timings.h" -#include "Utils\WebUtils.h" +#include "Utils/WebUtils.h" #include "items/ButtonInClass.h" //#include "RemoteOrdersUdp.h" #include "Bus.h" @@ -32,7 +32,7 @@ void setup() { setChipId(); - myNotAsincActions = new NotAsinc(do_LAST); + myNotAsyncActions = new NotAsync(do_LAST); myScenario = new Scenario(); SerialPrint("I", "FS", "FS Init"); @@ -112,7 +112,7 @@ void loop() { loopCmdExecute(); //loopSerial(); - myNotAsincActions->loop(); + myNotAsyncActions->loop(); ts.update(); } From 8778de1ffd416dcd517064647378e7255187eb1f Mon Sep 17 00:00:00 2001 From: Yuri Trikoz Date: Sun, 18 Oct 2020 10:17:24 +0300 Subject: [PATCH 7/7] -40b --- include/Errors.h | 4 ++-- include/Utils/PrintMessage.h | 18 ++++++++++++++++-- include/Utils/StringUtils.h | 4 +++- src/Utils/StringUtils.cpp | 20 +++++--------------- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/include/Errors.h b/include/Errors.h index cefac965..2b117273 100644 --- a/include/Errors.h +++ b/include/Errors.h @@ -2,7 +2,7 @@ #include -String getErrorLevelStr(ErrorLevel_t level); +#include "Utils/StringUtils.h" class Error : public Printable { public: @@ -37,7 +37,7 @@ class Error : public Printable { const String toString() const { char buf[128]; - sprintf(buf, "[%s] %s", getErrorLevelStr(_level).c_str(), _message); + sprintf(buf, "[%c] %s", getErrorLevelStr(_level), _message); return String(buf); } diff --git a/include/Utils/PrintMessage.h b/include/Utils/PrintMessage.h index 637b793f..f33f4252 100644 --- a/include/Utils/PrintMessage.h +++ b/include/Utils/PrintMessage.h @@ -6,7 +6,6 @@ #include "Errors.h" #include "Global.h" - #define pm PrintMessage(MODULE) class PrintMessage { @@ -24,8 +23,23 @@ class PrintMessage { } 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) { - Serial.printf("%s [%s] [%s] %s\n", prettyMillis(millis()).c_str(), getErrorLevelStr(level).c_str(), _module, str.c_str()); + printUptime(); + printErrorLevel(level); + printModule(); + Serial.println(str.c_str()); } private: diff --git a/include/Utils/StringUtils.h b/include/Utils/StringUtils.h index 3c23ee4a..9dc91d6b 100644 --- a/include/Utils/StringUtils.h +++ b/include/Utils/StringUtils.h @@ -26,4 +26,6 @@ size_t itemsCount(String str, const String& separator); boolean isDigitStr(const String&); -String prettyBytes(size_t size); \ No newline at end of file +String prettyBytes(size_t size); + +const char getErrorLevelStr(uint8_t level); \ No newline at end of file diff --git a/src/Utils/StringUtils.cpp b/src/Utils/StringUtils.cpp index 969cd59e..bcb2351f 100644 --- a/src/Utils/StringUtils.cpp +++ b/src/Utils/StringUtils.cpp @@ -111,26 +111,16 @@ String prettyBytes(size_t size) { return String(size / 1024.0 / 1024.0 / 1024.0) + "GB"; } -static const char *str_info = "I"; -static const char *str_warn = "W"; -static const char *str_error = "E"; -static const char *str_unknown = "?"; - -String getErrorLevelStr(ErrorLevel_t level) { - const char *ptr; +const char getErrorLevelStr(uint8_t level) { switch (level) { case EL_INFO: - ptr = str_info; - break; + return 'I'; case EL_WARNING: - ptr = str_warn; - break; + return 'W'; case EL_ERROR: - ptr = str_error; - break; + return 'E'; default: - ptr = str_unknown; break; } - return String(ptr); + return '?'; } \ No newline at end of file