From bb14ec4f8acda015148b4c3e21ee4a6f7a4bfcea Mon Sep 17 00:00:00 2001 From: TD-er Date: Wed, 1 May 2024 18:31:09 +0200 Subject: [PATCH 1/3] [C018] Reduce build size --- src/src/ControllerQueue/C018_queue_element.cpp | 1 + src/src/ControllerQueue/C018_queue_element.h | 2 +- src/src/Controller_config/C018_config.h | 3 +-- src/src/Controller_struct/C018_data_struct.cpp | 5 +++++ src/src/Controller_struct/C018_data_struct.h | 5 ++++- 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/src/ControllerQueue/C018_queue_element.cpp b/src/src/ControllerQueue/C018_queue_element.cpp index c6bbd41ffe..12dc14adb1 100644 --- a/src/src/ControllerQueue/C018_queue_element.cpp +++ b/src/src/ControllerQueue/C018_queue_element.cpp @@ -3,6 +3,7 @@ #ifdef USES_C018 # include "../DataStructs/ESPEasy_EventStruct.h" +# include "../DataStructs/UnitMessageCount.h" # include "../ESPEasyCore/ESPEasy_Log.h" diff --git a/src/src/ControllerQueue/C018_queue_element.h b/src/src/ControllerQueue/C018_queue_element.h index b2fa1f2a1c..9e6a4e9da9 100644 --- a/src/src/ControllerQueue/C018_queue_element.h +++ b/src/src/ControllerQueue/C018_queue_element.h @@ -7,11 +7,11 @@ # include "../ControllerQueue/Queue_element_base.h" # include "../CustomBuild/ESPEasyLimits.h" -# include "../DataStructs/UnitMessageCount.h" # include "../Globals/CPlugins.h" struct EventStruct; +struct UnitMessageCount_t; /*********************************************************************************************\ * C018_queue_element for queueing requests for C018: TTN/RN2483 diff --git a/src/src/Controller_config/C018_config.h b/src/src/Controller_config/C018_config.h index 8a142b352d..0bc9f4fde6 100644 --- a/src/src/Controller_config/C018_config.h +++ b/src/src/Controller_config/C018_config.h @@ -8,8 +8,7 @@ // Forward declaration struct C018_data_struct; -# include - +#include # define C018_DEVICE_EUI_LEN 17 # define C018_DEVICE_ADDR_LEN 33 diff --git a/src/src/Controller_struct/C018_data_struct.cpp b/src/src/Controller_struct/C018_data_struct.cpp index 782c7e4734..16e1ce911a 100644 --- a/src/src/Controller_struct/C018_data_struct.cpp +++ b/src/src/Controller_struct/C018_data_struct.cpp @@ -2,6 +2,11 @@ #ifdef USES_C018 + +# include +# include + + C018_data_struct::C018_data_struct() : C018_easySerial(nullptr), myLora(nullptr) {} diff --git a/src/src/Controller_struct/C018_data_struct.h b/src/src/Controller_struct/C018_data_struct.h index 97d266a97b..2d8961913b 100644 --- a/src/src/Controller_struct/C018_data_struct.h +++ b/src/src/Controller_struct/C018_data_struct.h @@ -5,7 +5,10 @@ #ifdef USES_C018 -# include +#include + +class rn2xx3; +class ESPeasySerial; struct C018_data_struct { From c909194f65fb393ca8478f80ff5eb1cf644fea4a Mon Sep 17 00:00:00 2001 From: TD-er Date: Wed, 1 May 2024 18:43:26 +0200 Subject: [PATCH 2/3] [Build] Reduce ESP8266 build size by concat all in single __tmpfile.cpp --- src/_C018.cpp | 103 +++++++++++++++++----------------- tools/pio/concat_cpp_files.py | 53 ++++++++--------- 2 files changed, 76 insertions(+), 80 deletions(-) diff --git a/src/_C018.cpp b/src/_C018.cpp index a25bb28810..17006dcd1c 100644 --- a/src/_C018.cpp +++ b/src/_C018.cpp @@ -11,7 +11,6 @@ # define CPLUGIN_NAME_018 "LoRa TTN - RN2483/RN2903" - # include # include "src/ControllerQueue/C018_queue_element.h" @@ -190,7 +189,7 @@ bool CPlugin_018(CPlugin::Function function, struct EventStruct *event, String& std::unique_ptr element(new C018_queue_element(event, C018_data->getSampleSetCount(event->TaskIndex))); success = C018_DelayHandler->addToQueue(std::move(element)); Scheduler.scheduleNextDelayQueue(SchedulerIntervalTimer_e::TIMER_C018_DELAY_QUEUE, - C018_DelayHandler->getNextScheduleTime()); + C018_DelayHandler->getNextScheduleTime()); } if (!C018_data->isInitialized()) { @@ -216,9 +215,11 @@ bool CPlugin_018(CPlugin::Function function, struct EventStruct *event, String& if (C018_data != nullptr) { if (C018_data->isInitialized()) { - const String command = parseString(string, 1); + const String command = parseString(string, 1); + if (equals(command, F("lorawan"))) { const String subcommand = parseString(string, 2); + if (equals(subcommand, F("write"))) { const String loraWriteCommand = parseStringToEnd(string, 3); const String res = C018_data->sendRawCommand(loraWriteCommand); @@ -358,65 +359,65 @@ bool C018_init(struct EventStruct *event) { bool do_process_c018_delay_queue(int controller_number, const Queue_element_base& element_base, ControllerSettingsStruct& ControllerSettings) { const C018_queue_element& element = static_cast(element_base); // *INDENT-ON* -uint8_t pl = (element.packed.length() / 2); -float airtime_ms = C018_data->getLoRaAirTime(pl); -bool mustSetDelay = false; -bool success = false; - -if (!C018_data->command_finished()) { - mustSetDelay = true; -} else { - success = C018_data->txHexBytes(element.packed, ControllerSettings.Port); - - if (success) { - if (airtime_ms > 0.0f) { - ADD_TIMER_STAT(C018_AIR_TIME, static_cast(airtime_ms * 1000)); - - if (loglevelActiveFor(LOG_LEVEL_INFO)) { - String log = F("LoRaWAN : Payload Length: "); - log += pl + 13; // We have a LoRaWAN header of 13 bytes. - log += F(" Air Time: "); - log += toString(airtime_ms, 3); - log += F(" ms"); - addLogMove(LOG_LEVEL_INFO, log); + uint8_t pl = (element.packed.length() / 2); + float airtime_ms = C018_data->getLoRaAirTime(pl); + bool mustSetDelay = false; + bool success = false; + + if (!C018_data->command_finished()) { + mustSetDelay = true; + } else { + success = C018_data->txHexBytes(element.packed, ControllerSettings.Port); + + if (success) { + if (airtime_ms > 0.0f) { + ADD_TIMER_STAT(C018_AIR_TIME, static_cast(airtime_ms * 1000)); + + if (loglevelActiveFor(LOG_LEVEL_INFO)) { + String log = F("LoRaWAN : Payload Length: "); + log += pl + 13; // We have a LoRaWAN header of 13 bytes. + log += F(" Air Time: "); + log += toString(airtime_ms, 3); + log += F(" ms"); + addLogMove(LOG_LEVEL_INFO, log); + } } } } -} -String error = C018_data->getLastError(); // Clear the error string. + String error = C018_data->getLastError(); // Clear the error string. -if (error.indexOf(F("no_free_ch")) != -1) { - mustSetDelay = true; -} + if (error.indexOf(F("no_free_ch")) != -1) { + mustSetDelay = true; + } -if (loglevelActiveFor(LOG_LEVEL_INFO)) { - String log = F("C018 : Sent: "); - log += element.packed; - log += F(" length: "); - log += String(element.packed.length()); + if (loglevelActiveFor(LOG_LEVEL_INFO)) { + String log = F("C018 : Sent: "); + log += element.packed; + log += F(" length: "); + log += String(element.packed.length()); - if (success) { - log += F(" (success) "); + if (success) { + log += F(" (success) "); + } + log += error; + addLogMove(LOG_LEVEL_INFO, log); } - log += error; - addLogMove(LOG_LEVEL_INFO, log); -} -if (mustSetDelay) { - // Module is still sending, delay for 10x expected air time, which is equivalent of 10% air time duty cycle. - // This can be retried a few times, so at most 10 retries like these are needed to get below 1% air time again. - // Very likely only 2 - 3 of these delays are needed, as we have 8 channels to send from and messages are likely sent in bursts. - C018_DelayHandler->setAdditionalDelay(10 * airtime_ms); + if (mustSetDelay) { + // Module is still sending, delay for 10x expected air time, which is equivalent of 10% air time duty cycle. + // This can be retried a few times, so at most 10 retries like these are needed to get below 1% air time again. + // Very likely only 2 - 3 of these delays are needed, as we have 8 channels to send from and messages are likely sent in bursts. + C018_DelayHandler->setAdditionalDelay(10 * airtime_ms); - if (loglevelActiveFor(LOG_LEVEL_INFO)) { - String log = F("LoRaWAN : Unable to send. Delay for "); - log += 10 * airtime_ms; - log += F(" ms"); - addLogMove(LOG_LEVEL_INFO, log); + if (loglevelActiveFor(LOG_LEVEL_INFO)) { + String log = F("LoRaWAN : Unable to send. Delay for "); + log += 10 * airtime_ms; + log += F(" ms"); + addLogMove(LOG_LEVEL_INFO, log); + } } -} -return success; + return success; } String c018_add_joinChanged_script_element_line(const String& id, bool forOTAA) { diff --git a/tools/pio/concat_cpp_files.py b/tools/pio/concat_cpp_files.py index f9ddd7a613..cec27bcc5f 100644 --- a/tools/pio/concat_cpp_files.py +++ b/tools/pio/concat_cpp_files.py @@ -11,13 +11,13 @@ def do_concat_cpp_files(cpp_files, output_file): newf.write(os.linesep.encode()) # append newline to separate files. -def concat_cpp_files(path_to_concat): +def concat_cpp_files(paths_to_concat): cpp_files = [] - cpp_path = path_to_concat + cpp_path = paths_to_concat[0] - cpp_path_out = '{}_tmp'.format(path_to_concat) + cpp_path_out = '{}_tmp'.format(cpp_path) if not os.path.exists(cpp_path_out): os.makedirs(cpp_path_out) @@ -25,37 +25,32 @@ def concat_cpp_files(path_to_concat): tmp_cpp_file = os.path.join(cpp_path_out, '__tmpfile.cpp') tmp2_cpp_file = os.path.join(cpp_path_out, '__tmpfile.cpp.test') - print("\u001b[32m Concat {}/*.cpp to {} \u001b[0m".format(cpp_path, tmp_cpp_file)) + for path_to_concat in paths_to_concat: + print("\u001b[32m Concat {}/*.cpp to {} \u001b[0m".format(path_to_concat, tmp_cpp_file)) - for root, dirs, files in os.walk(cpp_path): - for file in files: - if file.endswith('.cpp'): - fullname = os.path.join(root, file) - cpp_files.append(fullname) - print("\u001b[33m Add: \u001b[0m {}".format(fullname)) - if os.path.exists(tmp_cpp_file): - do_concat_cpp_files(cpp_files, tmp2_cpp_file) - - if filecmp.cmp(tmp_cpp_file, tmp2_cpp_file): - print("\u001b[32m Files not changed, will not touch __tmpfile.cpp \u001b[0m") - os.remove(tmp2_cpp_file) - else: + for root, dirs, files in os.walk(path_to_concat): + for file in files: + if file.endswith('.cpp'): + fullname = os.path.join(root, file) + cpp_files.append(fullname) + print("\u001b[33m Add: \u001b[0m {}".format(fullname)) + + if os.path.exists(tmp_cpp_file): os.remove(tmp_cpp_file) - os.rename(tmp2_cpp_file, tmp_cpp_file) - else: - do_concat_cpp_files(cpp_files, tmp_cpp_file) + + do_concat_cpp_files(cpp_files, tmp_cpp_file) print("\u001b[32m ------------------------------- \u001b[0m") -concat_cpp_files('./src/src/Commands') -concat_cpp_files('./src/src/ControllerQueue') -concat_cpp_files('./src/src/DataStructs') -concat_cpp_files('./src/src/DataTypes') -concat_cpp_files('./src/src/ESPEasyCore') -concat_cpp_files('./src/src/Globals') -concat_cpp_files('./src/src/Helpers') -concat_cpp_files('./src/src/PluginStructs') -concat_cpp_files('./src/src/WebServer') +concat_cpp_files(['./src/src/Commands', + './src/src/ControllerQueue', + './src/src/DataStructs', + './src/src/DataTypes', + './src/src/ESPEasyCore', + './src/src/Globals', + './src/src/Helpers', + './src/src/PluginStructs', + './src/src/WebServer']) From 7ab5bfc409dc8064f6c218752e72aa2096fc27aa Mon Sep 17 00:00:00 2001 From: TD-er Date: Thu, 2 May 2024 00:35:23 +0200 Subject: [PATCH 3/3] [Build] Reduce ESP8266 bin size disable LittleFS lib + OTA on 1M builds --- platformio_esp82xx_envs.ini | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/platformio_esp82xx_envs.ini b/platformio_esp82xx_envs.ini index c0cf103dd8..9cbff2de14 100644 --- a/platformio_esp82xx_envs.ini +++ b/platformio_esp82xx_envs.ini @@ -31,6 +31,8 @@ lib_ignore = ESP32_ping TinyWireM I2C AXP192 Power management EspSoftwareSerial + LittleFS + LittleFS(esp8266) extra_scripts = pre:tools/pio/pre_custom_esp82xx.py ${extra_scripts_esp8266.extra_scripts} @@ -45,6 +47,8 @@ lib_ignore = ESP32_ping ${no_ir.lib_ignore} TinyWireM I2C AXP192 Power management + LittleFS + LittleFS(esp8266) extra_scripts = pre:tools/pio/pre_custom_esp82xx.py ${extra_scripts_esp8266.extra_scripts} @@ -96,6 +100,7 @@ platform = ${ir.platform} platform_packages = ${ir.platform_packages} build_flags = ${ir.build_flags} ${esp8266_1M.build_flags} + -D NO_HTTP_UPDATER -DPLUGIN_BUILD_CUSTOM -DPLUGIN_BUILD_IR lib_ignore = ESP32_ping @@ -163,7 +168,13 @@ platform_packages = ${esp8266_custom_common_312.platform_packages} build_flags = ${esp8266_custom_common_312.build_flags} ${esp8266_4M1M.build_flags} -DPLUGIN_BUILD_CUSTOM -lib_ignore = ${esp8266_custom_common_312.lib_ignore} +lib_ignore = ESP32_ping + ESP32WebServer + ESP32HTTPUpdateServer + ServoESP32 + ${no_ir.lib_ignore} + TinyWireM + I2C AXP192 Power management extra_scripts = ${esp8266_custom_common_312.extra_scripts} @@ -174,6 +185,7 @@ platform = ${esp8266_custom_common_274.platform} platform_packages = ${esp8266_custom_common_274.platform_packages} build_flags = ${esp8266_custom_common_274.build_flags} ${esp8266_1M.build_flags} + -D NO_HTTP_UPDATER -DPLUGIN_BUILD_CUSTOM lib_ignore = ${esp8266_custom_common_274.lib_ignore} ESP8266SdFat @@ -191,6 +203,7 @@ platform = ${beta_platform.platform} platform_packages = ${beta_platform.platform_packages} build_flags = ${beta_platform.build_flags} ${esp8266_1M.build_flags} + -D NO_HTTP_UPDATER -DPLUGIN_BUILD_CUSTOM lib_ignore = ${esp8266_custom_common_312.lib_ignore} ESP8266SdFat @@ -225,6 +238,7 @@ platform = ${normal.platform} platform_packages = ${normal.platform_packages} build_flags = ${normal.build_flags} ${esp8266_1M.build_flags} + -D NO_HTTP_UPDATER lib_ignore = ${normal.lib_ignore} @@ -242,6 +256,7 @@ platform = ${normal.platform} platform_packages = ${normal.platform_packages} build_flags = ${normal.build_flags} ${esp8266_1M.build_flags} + -D NO_HTTP_UPDATER -D FEATURE_ADC_VCC=1 lib_ignore = ${normal.lib_ignore} @@ -746,6 +761,7 @@ platform = ${hard_esp82xx.platform} platform_packages = ${hard_esp82xx.platform_packages} build_flags = ${hard_esp82xx.build_flags} ${esp8266_1M.build_flags} + -D NO_HTTP_UPDATER -D PLUGIN_SET_LC_TECH_RELAY_X2 lib_ignore = ${hard_esp82xx.lib_ignore}