From 120564fa3a3fa3f83112a39476fd67414dc7b8b8 Mon Sep 17 00:00:00 2001 From: andreas loeffler Date: Mon, 2 Dec 2024 23:12:19 +0100 Subject: [PATCH] AsyncElegantOTA -> legantOTA --- include/common.h | 2 + include/config.h | 4 +- platformio.ini | 88 +++++++++++++++---------------------- src/CMakeLists.txt | 8 +++- src/gui-LVGL.cpp | 6 +-- src/net-control.cpp | 103 ++++++++++++++++++++++---------------------- 6 files changed, 100 insertions(+), 111 deletions(-) diff --git a/include/common.h b/include/common.h index 2fba161..27a9462 100644 --- a/include/common.h +++ b/include/common.h @@ -1,6 +1,8 @@ #ifndef _ESP32_TTGO_FTMS_H_ #define _ESP32_TTGO_FTMS_H_ +#undef ARDUINO_RASPBERRY_PI_PICO_W + //#define DEBUG 1 //#define DEBUG_MQTT 1 //#include "debug_print.h" diff --git a/include/config.h b/include/config.h index 6901491..04ee29f 100644 --- a/include/config.h +++ b/include/config.h @@ -2,8 +2,8 @@ #define _CONFIG_H_ #include // for string type -#warning fix include error for string type remove arduino (use std:string?? it might be faster) -//#include +//#warning fix include error for string type remove arduino (use std:string?? it might be faster) +//#include extern const char* VERSION; diff --git a/platformio.ini b/platformio.ini index 88b9c86..089bc15 100644 --- a/platformio.ini +++ b/platformio.ini @@ -8,30 +8,24 @@ ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html -[platformio] -default_envs = ESP32_WT32-SC01 - [common_env_data] -lib_deps_ext = - ayushsharma82/AsyncElegantOTA @ ^2.2.6 +lib_deps_ext = h2zero/NimBLE-Arduino @ ^1.3.1 - ;h2zero/esp-nimble-cpp TODO: what is difference between NimBLE-Arduino and esp-nimble-cpp!? - ottowinter/ESPAsyncWebServer-esphome @ ^2.0.1 knolleary/PubSubClient @ ^2.8 bblanchon/ArduinoJson @ ^6.18.5 - lennarthennigs/Button2 @ ^1.6.5 + lennarthennigs/Button2 paulstoffregen/Time @ ^1.6.1 rfetick/MPU6050_light @ ^1.1.0 https://github.com/alanswx/ESPAsyncWiFiManager.git -build_flags_settings = + ayushsharma82/ElegantOTA@^3.1.6 +build_flags_settings = -Os -DCORE_DEBUG_LEVEL=0 + -DELEGANTOTA_USE_ASYNC_WEBSERVER=1 -I include/ - -;treadmill=Northtrack12_2_Si -;treadmill=SoleF85 -treadmill=Taurus9_5 - +lib_compat_mode = strict +lib_ldf_mode = chain +treadmill = Taurus9_5 [env:ESP32_TTGO_DISPLAY] platform = espressif32 @@ -42,18 +36,17 @@ framework = arduino monitor_speed = 115200 upload_speed = 921600 board_build.partitions = no_ota.csv -lib_deps = +lib_deps = ${common_env_data.lib_deps_ext} lovyan03/LovyanGFX@>=0.4.10 lvgl/lvgl@^8.1.0 - -build_flags = + mathieucarbou/ESPAsyncWebServer@^3.3.23 + mathieucarbou/AsyncTCP@^3.2.14 +build_flags = -DTARGET_TTGO_T_DISPLAY -DLGFX_TTGO_TDISPLAY -DLGFX_USE_V1 -DGUI_LVGL - ;-DBUTTON_1=35 - ;-DBUTTON_2=0 ${common_env_data.build_flags_settings} [env:ESP32_TTGO_DISPLAY_SSL] @@ -65,26 +58,22 @@ framework = arduino monitor_speed = 115200 upload_speed = 921600 board_build.partitions = ssl_app.csv - -lib_deps = - WiFiClientSecure +lib_deps = + WiFiClientSecure ${common_env_data.lib_deps_ext} lovyan03/LovyanGFX@>=0.4.10 lvgl/lvgl@^8.1.0 - -build_flags = + mathieucarbou/ESPAsyncWebServer@^3.3.23 + mathieucarbou/AsyncTCP@^3.2.14 +build_flags = -DMQTT_USE_SSL -DTARGET_TTGO_T_DISPLAY -DLGFX_TTGO_TDISPLAY -DLGFX_USE_V1 -DGUI_LVGL - ;-DBUTTON_1=35 - ;-DBUTTON_2=0 ${common_env_data.build_flags_settings} [env:ESP32_WT32-SC01] -; 4MB SPI Flash, 8MB PSRAM -; Screen model: WT-352215-A2 platform = espressif32 board = esp-wrover-kit board_build.filesystem = littlefs @@ -93,18 +82,16 @@ board_build.partitions = no_ota.csv framework = arduino upload_protocol = esptool monitor_speed = 115200 -upload_speed = 921600 -;upload_port = /dev/ttyUSB0 -;monitor_port = /dev/ttyUSB0 -; Set optimization level and amount of debug information generated by the compiler +upload_speed = 921600 debug_build_flags = -O0 -ggdb3 -g3 - -lib_deps = +lib_deps = ${common_env_data.lib_deps_ext} lovyan03/LovyanGFX@>=0.4.10 lvgl/lvgl@^8.1.0 - -build_flags = + mathieucarbou/ESPAsyncWebServer@^3.3.23 + mathieucarbou/AsyncTCP@^3.2.14 +build_flags = + -DMQTT_USE_SSL -DTARGET_WT32_SC01 -DLGFX_WT32_SC01 -DLGFX_USE_V1 @@ -116,8 +103,6 @@ build_flags = ${common_env_data.build_flags_settings} [env:ESP32_WT32-SC01_OLD_TFT_GUI] -; 4MB SPI Flash, 8MB PSRAM -; Screen model: WT-352215-A2 platform = espressif32 board = esp-wrover-kit board_build.filesystem = littlefs @@ -126,17 +111,14 @@ board_build.partitions = no_ota.csv framework = arduino upload_protocol = esptool monitor_speed = 115200 -upload_speed = 921600 -;upload_port = /dev/ttyUSB0 -;monitor_port = /dev/ttyUSB0 -; Set optimization level and amount of debug information generated by the compiler +upload_speed = 921600 debug_build_flags = -O0 -ggdb3 -g3 - -lib_deps = +lib_deps = ${common_env_data.lib_deps_ext} lovyan03/LovyanGFX@>=0.4.10 - -build_flags = + mathieucarbou/ESPAsyncWebServer@^3.3.23 + mathieucarbou/AsyncTCP@^3.2.14 +build_flags = -DTARGET_WT32_SC01 -DLGFX_WT32_SC01 -DLGFX_USE_V1 @@ -151,9 +133,7 @@ build_flags = -DTFT_BL=23 ${common_env_data.build_flags_settings} - [env:ESP32_TTGO_T4] -; ILI9341 platform = espressif32 board = esp-wrover-kit board_build.partitions = ssl_app.csv @@ -162,15 +142,13 @@ extra_scripts = post:scripts/prepare_littlefs.py framework = arduino monitor_speed = 115200 upload_speed = 921600 - -lib_deps = +lib_deps = ${common_env_data.lib_deps_ext} - ottowinter/ESPAsyncWebServer-esphome @ ^2.1.0 - ;lovyan03/LovyanGFX@>=0.4.10 -> change back once my pr gets merged! https://github.com/lefty01/LovyanGFX lvgl/lvgl@^8.1.0 - -build_flags = + mathieucarbou/ESPAsyncWebServer@^3.3.23 + mathieucarbou/AsyncTCP@^3.2.14 +build_flags = -DTARGET_TTGO_T4 -DLGFX_TTGO_T4_DISPLAY -DLGFX_USE_V1 @@ -206,6 +184,8 @@ monitor_speed = 115200 upload_speed = 921600 lib_deps = ${common_env_data.lib_deps_ext} + mathieucarbou/ESPAsyncWebServer@^3.3.23 + mathieucarbou/AsyncTCP@^3.2.14 build_flags = -DTARGET_WT32_WROOMD -DNO_DISPLAY diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 35171b6..8a6f99d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1 +1,7 @@ -idf_component_register(SRCS "net-control.cpp" "display.cpp" "Hardware.cpp" "config.cpp" "ESP32_TTGO_FTMS.cpp") +idf_component_register( SRCS + "net-control.cpp" + "display.cpp" + "Hardware.cpp" + "config.cpp" + "ESP32_TTGO_FTMS.cpp" +) diff --git a/src/gui-LVGL.cpp b/src/gui-LVGL.cpp index 2ed34dd..da22649 100644 --- a/src/gui-LVGL.cpp +++ b/src/gui-LVGL.cpp @@ -74,8 +74,8 @@ static void showGfxTopBar(lv_obj_t *parent) gfxLvTopText = lv_label_create(gfxLvTopBar); gfxLvVersionText = lv_label_create(gfxLvTopBar); //lv_obj_set_width(gfxLvTopText, lv_pct(100)); - lv_label_set_text(gfxLvTopText, "FTMS"); - lv_obj_set_flex_grow(gfxLvTopText, 1); + lv_label_set_text(gfxLvTopText, "FTMS by lefty01"); + lv_obj_set_flex_grow(gfxLvTopText, 1); gfxLvLedSpeed = lv_led_create(gfxLvTopBar); lv_obj_set_size(gfxLvLedSpeed, 12, 12); @@ -116,7 +116,7 @@ static lv_obj_t * createScreenBoot() { lv_obj_add_state(gfxLvLogTextArea, LV_STATE_FOCUSED); // show "cursor" lv_obj_set_size(gfxLvLogTextArea, lv_pct(100), lv_pct(100)); lv_obj_center(gfxLvLogTextArea); - lv_obj_set_flex_grow(gfxLvLogTextArea, 1); + lv_obj_set_flex_grow(gfxLvLogTextArea, 1); // TODO Could be good to have some progressbar also. return screenBoot; diff --git a/src/net-control.cpp b/src/net-control.cpp index 1b017ea..46f9ed5 100644 --- a/src/net-control.cpp +++ b/src/net-control.cpp @@ -5,22 +5,23 @@ TODO: Maybe we want to split this up in different files later? Lets see how it g */ #define NIMBLE #include -#include #include #include #include // https://playground.arduino.cc/Code/Time/ +//#include // https://github.com/tzapu/WiFiManager +#include //Local WebServer used to serve the configuration portal +#include //https://github.com/tzapu/WiFiManager WiFi Configuration Magic +#include + #include "common.h" #include "display.h" -#include "net-control.h" +#include "net-control.h" #include "config.h" #include "debug_print.h" #include "hardware.h" #include "wifi_mqtt_creds.h" -//#include // https://github.com/tzapu/WiFiManager -#include //Local WebServer used to serve the configuration portal -#include "ESPAsyncWiFiManager.h" //https://github.com/tzapu/WiFiManager WiFi Configuration Magic #include #ifdef MQTT_USE_SSL @@ -45,7 +46,7 @@ AsyncWebServer server(80); #endif AsyncWebSocket ws("/ws"); PubSubClient client(espClient); // mqtt client -DNSServer dns; +DNSServer dns; //extern AsyncWebServer server; //extern AsyncWebSocket ws; @@ -57,7 +58,7 @@ bool isMqttAvailable = false; bool isWifiAvailable = false; unsigned long wifiReconnectCounter = 0; -static unsigned long mqtt_reconnect_counter = 0; +static unsigned long mqtt_reconnect_counter = 0; unsigned long wifi_reconnect_timer = 0; String ipAddr; @@ -149,14 +150,14 @@ void loopHandleBLE() logText("BT Client connected!\n"); #ifndef NO_DISPLAY gfxUpdateHeader(); -#endif +#endif } else if (!bleClientConnected && bleClientConnectedPrev) { bleClientConnectedPrev = false; logText("BT Client disconnected!\n"); -#ifndef NO_DISPLAY +#ifndef NO_DISPLAY gfxUpdateHeader(); -#endif +#endif } } @@ -199,7 +200,7 @@ void initBLE() { //pAdvertising->setMinPreferred(0x06); // set value to 0x00 to not advertise this parameter pAdvertising->start(); - logText("done\n"); + logText("done\n"); } void updateBLEdata(void) @@ -267,7 +268,7 @@ void initWifi() { bool res; - logText("Init Wifi..."); + logText("Init Wifi..."); // reset settings - wipe stored credentials for testing // these are stored by the esp library // wm.resetSettings(); @@ -284,18 +285,18 @@ void initWifi() //res = wifiManager.autoConnect(); // auto generated AP name from chipid // res = wm.autoConnect("AutoConnectAP"); // anonymous ap res = wifiManager.autoConnect("FTMS Threadmill AP"); - + if (!res) { isWifiAvailable = false; logText("failed\n"); - } + } else { isWifiAvailable = true; - //if you get here you have connected to the WiFi + //if you get here you have connected to the WiFi ipAddr = WiFi.localIP().toString(); dnsAddr = WiFi.dnsIP().toString(); - logText(" OK\n"); + logText(" OK\n"); logText("IP address: "); logText(ipAddr.c_str()); logText("DNS address: "); @@ -304,12 +305,12 @@ void initWifi() } } -void loopHandleWIFI() +void loopHandleWIFI() { -// static unsigned long mqtt_reconnect_counter = 0; +// static unsigned long mqtt_reconnect_counter = 0; // unsigned long wifi_reconnect_timer = 0; // bool isWifiAvailable = false; - + // re-connect to wifi if ((WiFi.status() != WL_CONNECTED) && ((millis() - wifi_reconnect_timer) > WIFI_CHECK)) { wifi_reconnect_timer = millis(); @@ -322,7 +323,7 @@ void loopHandleWIFI() WiFi.reconnect(); } - if (!isWifiAvailable && (WiFi.status() == WL_CONNECTED)) + if (!isWifiAvailable && (WiFi.status() == WL_CONNECTED)) { // connection was lost and now got reconnected ... isWifiAvailable = true; @@ -336,7 +337,7 @@ void loopHandleWIFI() #ifndef NO_DISPLAY gfxUpdateHeader(); -#endif +#endif } if (!isMqttAvailable && isWifiAvailable) @@ -353,12 +354,12 @@ void loopHandleWIFI() #ifndef NO_DISPLAY gfxUpdateDisplay(true); //TODO replace this with gfxUpdateHeader(); gfxUpdateHeader(); -#endif +#endif } } } -const char* getTopic(topics_t topic) +const char* getTopic(topics_t topic) { return mqtt_topics[topic].c_str(); } @@ -391,7 +392,7 @@ int initMqtt(void) return isMqttAvailable; } -bool mqttConnect(void) +bool mqttConnect(void) { bool result = false; @@ -409,7 +410,7 @@ bool mqttConnect(void) client.setServer(mqtt_host, mqtt_port); if (client.connect(MQTTDEVICEID.c_str(), mqtt_user, mqtt_pass, - getTopic(MQTT_TOPIC_STATE), 1, 1, "OFFLINE")) + getTopic(MQTT_TOPIC_STATE), 1, 1, "OFFLINE")) { // Once connected, publish an announcement... logText("publish connected..."); @@ -423,10 +424,10 @@ bool mqttConnect(void) rc |= client.publish(getTopic(MQTT_TOPIC_IPADDR), ipAddr.c_str(), true); if (rc) logText("OK\n"); else logText("ERROR\n"); - + logText("MQTT CONNECTED\n"); result = true; - } + } else { logText("MQTT FAILED, rc="); @@ -462,20 +463,20 @@ String processor(const String& var) return String(); } -void onNotFound(AsyncWebServerRequest* request) +void onNotFound(AsyncWebServerRequest* request) { request->send(404, "text/plain", "Not found"); } -void onRootRequest(AsyncWebServerRequest *request) +void onRootRequest(AsyncWebServerRequest *request) { request->send(LittleFS, "/index.html", "text/html", false, processor); } #ifdef ASYNC_TCP_SSL_ENABLED -int sslFileRequestCallback(void *arg, const char *filename, uint8_t **buf) +int sslFileRequestCallback(void *arg, const char *filename, uint8_t **buf) { - //Serial.printf("SSL File: %s\n", filename); + //Serial.printf("SSL File: %s\n", filename); // sanitize filename!?? File file = SPIFFS.open(filename, "r"); if (file) { @@ -502,7 +503,7 @@ void initAsyncWebserver() server.on("/resetwifi", HTTP_GET, resetWifiConnection); server.serveStatic("/", LittleFS, "/"); - AsyncElegantOTA.begin(&server); + ElegantOTA.begin(&server); // Start server #ifdef ASYNC_TCP_SSL_ENABLED //server.onSslFileRequest(&sslFileRequestCallback, NULL); @@ -519,7 +520,7 @@ void initAsyncWebserver() // https://arduinojson.org/v6/assistant/ -void notifyClientsWebSockets() +void notifyClientsWebSockets() { StaticJsonDocument<256> doc; @@ -539,7 +540,7 @@ void notifyClientsWebSockets() } -void handleWebSocketMessage(void *arg, uint8_t *data, size_t len) +void handleWebSocketMessage(void *arg, uint8_t *data, size_t len) { AwsFrameInfo *info = (AwsFrameInfo*)arg; @@ -561,47 +562,47 @@ void handleWebSocketMessage(void *arg, uint8_t *data, size_t len) if (strcmp(command, "sensor_mode") == 0) { if (strcmp(value, "speed") == 0) - speedInclineMode ^= SPEED; // b'01 toggle bit + speedInclineMode ^= SPEED; // b'01 toggle bit if (strcmp(value, "incline") == 0) - speedInclineMode ^= INCLINE; // b'10 + speedInclineMode ^= INCLINE; // b'10 #ifndef NO_DISPLAY gfxUpdateHeader(); -#endif +#endif } if (strcmp(command, "speed") == 0) { if (strcmp(value, "up") == 0) - speedUp(); + speedUp(); if (strcmp(value, "down") == 0) - speedDown(); + speedDown(); } if (strcmp(command, "incline") == 0) { if (strcmp(value, "up") == 0) - inclineUp(); + inclineUp(); if (strcmp(value, "down") == 0) - inclineDown(); + inclineDown(); } if (strcmp(command, "speed_interval") == 0) { if (strcmp(value, "0.1") == 0) - setSpeedInterval(0.1); + setSpeedInterval(0.1); if (strcmp(value, "0.5") == 0) - setSpeedInterval(0.5); + setSpeedInterval(0.5); if (strcmp(value, "1.0") == 0) - setSpeedInterval(1.0); + setSpeedInterval(1.0); } notifyClientsWebSockets(); } } void onEvent(AsyncWebSocket *server, - AsyncWebSocketClient *client, - AwsEventType type, // connect/disconnect/data/pong - void *arg, - uint8_t *data, - size_t len) + AsyncWebSocketClient *client, + AwsEventType type, // connect/disconnect/data/pong + void *arg, + uint8_t *data, + size_t len) { - switch (type) + switch (type) { case WS_EVT_CONNECT: DEBUG_PRINTF("WebSocket client #%u connected from %s\n", client->id(), @@ -664,7 +665,7 @@ String readSecond() { return sStr; } -void initWebSocket() +void initWebSocket() { ws.onEvent(onEvent); server.addHandler(&ws);