Skip to content

Commit

Permalink
Merge pull request letscontrolit#5262 from TD-er/cleanup/improve_memo…
Browse files Browse the repository at this point in the history
…ry_usage

[Memory] Improve memory usage
  • Loading branch information
TD-er authored Feb 26, 2025
2 parents 6260306 + c3e7eb5 commit e8b21ce
Show file tree
Hide file tree
Showing 57 changed files with 1,076 additions and 770 deletions.
6 changes: 3 additions & 3 deletions platformio_esp32s3_envs.ini
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ build_flags = ${esp32s3_common_LittleFS.build_flags}
-DPLUGIN_BUILD_IR_EXTENDED
-DCONFIG_PM_LIGHTSLEEP_RTC_OSC_CAL_INTERVAL=1
extra_scripts = ${esp32s3_common_LittleFS.extra_scripts}
custom_sdkconfig =
CONFIG_RMT_ISR_CACHE_SAFE=y
CONFIG_PM_LIGHTSLEEP_RTC_OSC_CAL_INTERVAL=1
;custom_sdkconfig =
; CONFIG_RMT_ISR_CACHE_SAFE=y
; CONFIG_PM_LIGHTSLEEP_RTC_OSC_CAL_INTERVAL=1



8 changes: 8 additions & 0 deletions platformio_esp82xx_base.ini
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ build_flags = ${beta_platform.build_flags}
lib_ignore = ${beta_platform.lib_ignore}
${no_ir.lib_ignore}

[normal_beta_2ndheap]
platform = ${beta_platform_2ndheap.platform}
platform_packages = ${beta_platform_2ndheap.platform_packages}
build_flags = ${beta_platform_2ndheap.build_flags}
-DBUILD_NO_DEBUG
lib_ignore = ${beta_platform.lib_ignore}
${no_ir.lib_ignore}

;;; COLLECTION ********************************************************
; additional plugins (and dependend code) that is marked as COLLECTION ;
; Includes "normal" + "collection" plugins ;
Expand Down
20 changes: 20 additions & 0 deletions platformio_esp82xx_envs.ini
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,26 @@ build_flags = ${normal.build_flags}
-D NO_LIMIT_BUILD_SIZE
lib_ignore = ${normal.lib_ignore}

[env:normal_beta_2ndheap_ESP8266_4M1M]
extends = esp8266_4M1M
platform = ${normal_beta_2ndheap.platform}
platform_packages = ${normal_beta_2ndheap.platform_packages}
build_flags = ${normal_beta_2ndheap.build_flags}
${esp8266_4M1M.build_flags}
-D NO_LIMIT_BUILD_SIZE
lib_ignore = ${normal_beta_2ndheap.lib_ignore}


[env:normal_beta_2ndheap_ESP8266_4M1M_VCC]
extends = esp8266_4M1M
platform = ${normal_beta_2ndheap.platform}
platform_packages = ${normal_beta_2ndheap.platform_packages}
build_flags = ${normal_beta_2ndheap.build_flags}
${esp8266_4M1M.build_flags}
-D FEATURE_ADC_VCC=1
-D NO_LIMIT_BUILD_SIZE
lib_ignore = ${normal_beta_2ndheap.lib_ignore}


; NORMAL: 16M version --- LittleFS --------------
; LittleFS is determined by using "LittleFS" in the pio env name
Expand Down
9 changes: 7 additions & 2 deletions src/_C001.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,14 @@ bool CPlugin_001(CPlugin::Function function, struct EventStruct *event, String&
url += mapVccToDomoticz();
# endif // if FEATURE_ADC_VCC

std::unique_ptr<C001_queue_element> element(new (std::nothrow) C001_queue_element(event->ControllerIndex, event->TaskIndex, std::move(url)));
constexpr unsigned size = sizeof(C001_queue_element);
void *ptr = special_calloc(1, size);

if (ptr != nullptr) {
std::unique_ptr<C001_queue_element> element(new (ptr) C001_queue_element(event->ControllerIndex, event->TaskIndex, std::move(url)));

success = C001_DelayHandler->addToQueue(std::move(element));
success = C001_DelayHandler->addToQueue(std::move(element));
}
Scheduler.scheduleNextDelayQueue(SchedulerIntervalTimer_e::TIMER_C001_DELAY_QUEUE,
C001_DelayHandler->getNextScheduleTime());
}
Expand Down
118 changes: 62 additions & 56 deletions src/_C003.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ bool CPlugin_003(CPlugin::Function function, struct EventStruct *event, String&
if (C003_DelayHandler == nullptr) {
break;
}

if (C003_DelayHandler->queueFull(event->ControllerIndex)) {
break;
}
Expand All @@ -58,13 +59,18 @@ bool CPlugin_003(CPlugin::Function function, struct EventStruct *event, String&
F("variableset %d,%s\n"),
event->idx,
formatUserVarNoCheck(event, 0).c_str());
std::unique_ptr<C003_queue_element> element(
new (std::nothrow) C003_queue_element(
event->ControllerIndex,
event->TaskIndex,
std::move(url)));
constexpr unsigned size = sizeof(C003_queue_element);
void *ptr = special_calloc(1, size);

if (ptr != nullptr) {
std::unique_ptr<C003_queue_element> element(
new (ptr) C003_queue_element(
event->ControllerIndex,
event->TaskIndex,
std::move(url)));

success = C003_DelayHandler->addToQueue(std::move(element));
success = C003_DelayHandler->addToQueue(std::move(element));
}
Scheduler.scheduleNextDelayQueue(SchedulerIntervalTimer_e::TIMER_C003_DELAY_QUEUE, C003_DelayHandler->getNextScheduleTime());

break;
Expand All @@ -88,69 +94,69 @@ bool CPlugin_003(CPlugin::Function function, struct EventStruct *event, String&
bool do_process_c003_delay_queue(cpluginID_t cpluginID, const Queue_element_base& element_base, ControllerSettingsStruct& ControllerSettings) {
const C003_queue_element& element = static_cast<const C003_queue_element&>(element_base);
// *INDENT-ON*
bool success = false;
bool success = false;

// Use WiFiClient class to create TCP connections
WiFiClient client;
// Use WiFiClient class to create TCP connections
WiFiClient client;

if (!try_connect_host(cpluginID, client, ControllerSettings, F("TELNT: ")))
{
return success;
}
if (!try_connect_host(cpluginID, client, ControllerSettings, F("TELNT: ")))
{
return success;
}

// strcpy_P(log, PSTR("TELNT: Sending enter"));
// addLog(LOG_LEVEL_ERROR, log);
client.print(" \n");
// strcpy_P(log, PSTR("TELNT: Sending enter"));
// addLog(LOG_LEVEL_ERROR, log);
client.print(" \n");

unsigned long timer = millis() + 200;
unsigned long timer = millis() + 200;

while (!client_available(client) && !timeOutReached(timer)) {
delay(1);
}
while (!client_available(client) && !timeOutReached(timer)) {
delay(1);
}

timer = millis() + 1000;
timer = millis() + 1000;

while (client_available(client) && !timeOutReached(timer) && !success)
{
// String line = client.readStringUntil('\n');
String line;
safeReadStringUntil(client, line, '\n');
while (client_available(client) && !timeOutReached(timer) && !success)
{
// String line = client.readStringUntil('\n');
String line;
safeReadStringUntil(client, line, '\n');

if (line.startsWith(F("Enter your password:")))
{
success = true;
#ifndef BUILD_NO_DEBUG
addLog(LOG_LEVEL_DEBUG, F("TELNT: Password request ok"));
#endif
}
delay(1);
}
#ifndef BUILD_NO_DEBUG
addLog(LOG_LEVEL_DEBUG, F("TELNT: Sending pw"));
#endif
client.println(getControllerPass(element._controller_idx, ControllerSettings));
delay(100);

while (client_available(client)) {
client.read();
if (line.startsWith(F("Enter your password:")))
{
success = true;
# ifndef BUILD_NO_DEBUG
addLog(LOG_LEVEL_DEBUG, F("TELNT: Password request ok"));
# endif
}
delay(1);
}
# ifndef BUILD_NO_DEBUG
addLog(LOG_LEVEL_DEBUG, F("TELNT: Sending pw"));
# endif
client.println(getControllerPass(element._controller_idx, ControllerSettings));
delay(100);

while (client_available(client)) {
client.read();
}

#ifndef BUILD_NO_DEBUG
addLog(LOG_LEVEL_DEBUG, F("TELNT: Sending cmd"));
#endif
client.print(element.txt);
delay(10);
# ifndef BUILD_NO_DEBUG
addLog(LOG_LEVEL_DEBUG, F("TELNT: Sending cmd"));
# endif
client.print(element.txt);
delay(10);

while (client_available(client)) {
client.read();
}
while (client_available(client)) {
client.read();
}

#ifndef BUILD_NO_DEBUG
addLog(LOG_LEVEL_DEBUG, F("TELNT: closing connection"));
#endif
# ifndef BUILD_NO_DEBUG
addLog(LOG_LEVEL_DEBUG, F("TELNT: closing connection"));
# endif

client.stop();
return success;
client.stop();
return success;
}

#endif // ifdef USES_C003
12 changes: 9 additions & 3 deletions src/_C004.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ bool CPlugin_004(CPlugin::Function function, struct EventStruct *event, String&
{
success = true;

switch (event->idx) {
switch (event->idx)
{
case ControllerSettingsStruct::CONTROLLER_USER:
string = F("ThingHTTP Name");
break;
Expand All @@ -72,9 +73,14 @@ bool CPlugin_004(CPlugin::Function function, struct EventStruct *event, String&
break;
}

std::unique_ptr<C004_queue_element> element(new (std::nothrow) C004_queue_element(event));
constexpr unsigned size = sizeof(C004_queue_element);
void *ptr = special_calloc(1, size);

success = C004_DelayHandler->addToQueue(std::move(element));
if (ptr != nullptr) {
std::unique_ptr<C004_queue_element> element(new (ptr) C004_queue_element(event));

success = C004_DelayHandler->addToQueue(std::move(element));
}
Scheduler.scheduleNextDelayQueue(SchedulerIntervalTimer_e::TIMER_C004_DELAY_QUEUE, C004_DelayHandler->getNextScheduleTime());

break;
Expand Down
54 changes: 30 additions & 24 deletions src/_C007.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,13 @@ bool CPlugin_007(CPlugin::Function function, struct EventStruct *event, String&
break;
}

std::unique_ptr<C007_queue_element> element(new (std::nothrow) C007_queue_element(event));
success = C007_DelayHandler->addToQueue(std::move(element));
constexpr unsigned size = sizeof(C007_queue_element);
void *ptr = special_calloc(1, size);

if (ptr != nullptr) {
std::unique_ptr<C007_queue_element> element(new (ptr) C007_queue_element(event));
success = C007_DelayHandler->addToQueue(std::move(element));
}

Scheduler.scheduleNextDelayQueue(SchedulerIntervalTimer_e::TIMER_C007_DELAY_QUEUE, C007_DelayHandler->getNextScheduleTime());
break;
Expand All @@ -101,35 +106,36 @@ bool CPlugin_007(CPlugin::Function function, struct EventStruct *event, String&
// *INDENT-OFF*
bool do_process_c007_delay_queue(cpluginID_t cpluginID, const Queue_element_base& element_base, ControllerSettingsStruct& ControllerSettings) {
const C007_queue_element& element = static_cast<const C007_queue_element&>(element_base);

// *INDENT-ON*
if (ControllerSettings.Publish[0] == '\0') {
strcpy_P(ControllerSettings.Publish, PSTR(C007_DEFAULT_URL));
}
String url = strformat(F("%s?node=%d&json="), ControllerSettings.Publish, Settings.Unit);
if (ControllerSettings.Publish[0] == '\0') {
strcpy_P(ControllerSettings.Publish, PSTR(C007_DEFAULT_URL));
}
String url = strformat(F("%s?node=%d&json="), ControllerSettings.Publish, Settings.Unit);

for (uint8_t i = 0; i < element.valueCount; ++i) {
url += strformat(F("%cfield%d:%s"), (i == 0) ? '{' : ',', element.idx + i, element.txt[i].c_str());
}
url += strformat(F("}&apikey=%s"), getControllerPass(element._controller_idx, ControllerSettings).c_str()); // "0UDNN17RW6XAS2E5" // api key
for (uint8_t i = 0; i < element.valueCount; ++i) {
url += strformat(F("%cfield%d:%s"), (i == 0) ? '{' : ',', element.idx + i, element.txt[i].c_str());
}
url += strformat(F("}&apikey=%s"), getControllerPass(element._controller_idx, ControllerSettings).c_str()); // "0UDNN17RW6XAS2E5" // api key

# ifndef BUILD_NO_DEBUG

if (loglevelActiveFor(LOG_LEVEL_DEBUG_MORE)) {
addLog(LOG_LEVEL_DEBUG_MORE, url);
}
if (loglevelActiveFor(LOG_LEVEL_DEBUG_MORE)) {
addLog(LOG_LEVEL_DEBUG_MORE, url);
}
# endif // ifndef BUILD_NO_DEBUG

int httpCode = -1;
send_via_http(
cpluginID,
ControllerSettings,
element._controller_idx,
url,
F("GET"),
EMPTY_STRING,
EMPTY_STRING,
httpCode);
return (httpCode >= 100) && (httpCode < 300);
int httpCode = -1;
send_via_http(
cpluginID,
ControllerSettings,
element._controller_idx,
url,
F("GET"),
EMPTY_STRING,
EMPTY_STRING,
httpCode);
return (httpCode >= 100) && (httpCode < 300);
}

#endif // ifdef USES_C007
Loading

0 comments on commit e8b21ce

Please sign in to comment.