Skip to content

Commit

Permalink
Merge pull request #5046 from TD-er/build/RN2483_build_size
Browse files Browse the repository at this point in the history
[Build] Reduce build size on ESP8266
  • Loading branch information
TD-er committed May 4, 2024
2 parents 3c6ac2c + 7ab5bfc commit af44ba2
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 85 deletions.
18 changes: 17 additions & 1 deletion platformio_esp82xx_envs.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand All @@ -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}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}


Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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}


Expand All @@ -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}

Expand Down Expand Up @@ -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}

Expand Down
103 changes: 52 additions & 51 deletions src/_C018.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# define CPLUGIN_NAME_018 "LoRa TTN - RN2483/RN2903"



# include <ESPeasySerial.h>

# include "src/ControllerQueue/C018_queue_element.h"
Expand Down Expand Up @@ -190,7 +189,7 @@ bool CPlugin_018(CPlugin::Function function, struct EventStruct *event, String&
std::unique_ptr<C018_queue_element> 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()) {
Expand All @@ -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);
Expand Down Expand Up @@ -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<const C018_queue_element&>(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<unsigned long>(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<unsigned long>(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) {
Expand Down
1 change: 1 addition & 0 deletions src/src/ControllerQueue/C018_queue_element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#ifdef USES_C018

# include "../DataStructs/ESPEasy_EventStruct.h"
# include "../DataStructs/UnitMessageCount.h"

# include "../ESPEasyCore/ESPEasy_Log.h"

Expand Down
2 changes: 1 addition & 1 deletion src/src/ControllerQueue/C018_queue_element.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/src/Controller_config/C018_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
// Forward declaration
struct C018_data_struct;

# include <rn2xx3.h>

#include <rn2xx3_datatypes.h>

# define C018_DEVICE_EUI_LEN 17
# define C018_DEVICE_ADDR_LEN 33
Expand Down
5 changes: 5 additions & 0 deletions src/src/Controller_struct/C018_data_struct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

#ifdef USES_C018


# include <rn2xx3.h>
# include <ESPeasySerial.h>


C018_data_struct::C018_data_struct() :
C018_easySerial(nullptr),
myLora(nullptr) {}
Expand Down
5 changes: 4 additions & 1 deletion src/src/Controller_struct/C018_data_struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@

#ifdef USES_C018

# include <rn2xx3.h>
#include <rn2xx3_status.h>

class rn2xx3;
class ESPeasySerial;


struct C018_data_struct {
Expand Down
53 changes: 24 additions & 29 deletions tools/pio/concat_cpp_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,51 +11,46 @@ 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)

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'])

0 comments on commit af44ba2

Please sign in to comment.