WiFi and RAM optimizations
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
#define NUKI_HUB_VERSION "9.12"
|
||||
#define NUKI_HUB_VERSION_INT (uint32_t)912
|
||||
#define NUKI_HUB_BUILD "unknownbuildnr"
|
||||
#define NUKI_HUB_DATE "2025-06-20"
|
||||
#define NUKI_HUB_DATE "2025-06-25"
|
||||
|
||||
#define GITHUB_LATEST_RELEASE_URL (char*)"https://github.com/technyon/nuki_hub/releases/latest"
|
||||
#define GITHUB_OTA_MANIFEST_URL (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/manifest.json"
|
||||
|
||||
@@ -9,7 +9,7 @@ dependencies:
|
||||
espressif/libsodium: "^1.0.20~2"
|
||||
|
||||
espressif/esp_hosted:
|
||||
version: 2.0.10
|
||||
version: "*"
|
||||
rules:
|
||||
- if: "target in [esp32p4]"
|
||||
|
||||
|
||||
57
src/main.cpp
57
src/main.cpp
@@ -6,6 +6,10 @@
|
||||
#include "esp_http_client.h"
|
||||
#include "esp_https_ota.h"
|
||||
#include "esp_task_wdt.h"
|
||||
#ifdef CONFIG_HEAP_TASK_TRACKING
|
||||
#include "esp_heap_task_info.h"
|
||||
#include "esp_heap_caps.h"
|
||||
#endif
|
||||
#include "Config.h"
|
||||
#include "esp32-hal-log.h"
|
||||
#include "hal/wdt_hal.h"
|
||||
@@ -644,6 +648,49 @@ void networkTask(void *pvParameters)
|
||||
}
|
||||
|
||||
#ifndef NUKI_HUB_UPDATER
|
||||
#ifdef CONFIG_HEAP_TASK_TRACKING
|
||||
static void print_all_tasks_info(void)
|
||||
{
|
||||
heap_all_tasks_stat_t tasks_stat;
|
||||
/* call API to dynamically allocate the memory necessary to store the
|
||||
* information collected while calling heap_caps_get_all_task_stat */
|
||||
const esp_err_t ret_val = heap_caps_alloc_all_task_stat_arrays(&tasks_stat);
|
||||
assert(ret_val == ESP_OK);
|
||||
|
||||
/* collect the information */
|
||||
heap_caps_get_all_task_stat(&tasks_stat);
|
||||
|
||||
/* process the information retrieved */
|
||||
Log->printf("\n--------------------------------------------------------------------------------\n");
|
||||
Log->printf("PRINTING ALL TASKS INFO\n");
|
||||
Log->printf("--------------------------------------------------------------------------------\n");
|
||||
for (size_t task_idx = 0; task_idx < tasks_stat.task_count; task_idx++) {
|
||||
task_stat_t task_stat = tasks_stat.stat_arr[task_idx];
|
||||
Log->printf("%s: %s: Peak Usage %" PRIu16 ", Current Usage %" PRIu16 "\n", task_stat.name,
|
||||
task_stat.is_alive ? "ALIVE " : "DELETED",
|
||||
task_stat.overall_peak_usage,
|
||||
task_stat.overall_current_usage);
|
||||
|
||||
for (size_t heap_idx = 0; heap_idx < task_stat.heap_count; heap_idx++) {
|
||||
heap_stat_t heap_stat = task_stat.heap_stat[heap_idx];
|
||||
Log->printf(" %s: Caps: %" PRIu32 ". Size %" PRIu16 ", Current Usage %" PRIu16 ", Peak Usage %" PRIu16 ", alloc count %" PRIu16 "\n", heap_stat.name,
|
||||
heap_stat.caps,
|
||||
heap_stat.size,
|
||||
heap_stat.current_usage,
|
||||
heap_stat.peak_usage,
|
||||
heap_stat.alloc_count);
|
||||
|
||||
for (size_t alloc_idx = 0; alloc_idx < heap_stat.alloc_count; alloc_idx++) {
|
||||
heap_task_block_t alloc_stat = heap_stat.alloc_stat[alloc_idx];
|
||||
Log->printf(" %p: Size: %" PRIu32 "\n", alloc_stat.address, alloc_stat.size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* delete the memory dynamically allocated while calling heap_caps_alloc_all_task_stat_arrays */
|
||||
heap_caps_free_all_task_stat_arrays(&tasks_stat);
|
||||
}
|
||||
#endif
|
||||
void nukiTask(void *pvParameters)
|
||||
{
|
||||
esp_task_wdt_add(NULL);
|
||||
@@ -1256,6 +1303,9 @@ void setup()
|
||||
Log->println(NUKI_HUB_VERSION);
|
||||
Log->print("Nuki Hub build ");
|
||||
Log->println(NUKI_HUB_BUILD);
|
||||
|
||||
Log->println(preferences->getString(preference_cred_user));
|
||||
Log->println(preferences->getString(preference_cred_password));
|
||||
|
||||
uint32_t devIdOpener = preferences->getUInt(preference_device_id_opener);
|
||||
|
||||
@@ -1372,12 +1422,7 @@ void setup()
|
||||
setupTasks(false);
|
||||
}
|
||||
|
||||
#ifdef DEBUG_NUKIHUB
|
||||
Log->print("Task Name\tStatus\tPrio\tHWM\tTask\tAffinity\n");
|
||||
char stats_buffer[1024];
|
||||
vTaskList(stats_buffer);
|
||||
Log->println(stats_buffer);
|
||||
#endif
|
||||
//print_all_tasks_info();
|
||||
}
|
||||
|
||||
void loop()
|
||||
|
||||
@@ -51,10 +51,16 @@ void WifiDevice::initialize()
|
||||
WiFi.disconnect(true);
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.disconnect();
|
||||
if (esp_task_wdt_status(NULL) == ESP_OK) {
|
||||
esp_task_wdt_reset();
|
||||
|
||||
int loop = 0;
|
||||
while (!_wifiClientStarted && loop < 50) {
|
||||
if (esp_task_wdt_status(NULL) == ESP_OK) {
|
||||
esp_task_wdt_reset();
|
||||
}
|
||||
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||
loop++;
|
||||
}
|
||||
vTaskDelay(5000 / portTICK_PERIOD_MS);
|
||||
|
||||
Log->println("Dummy WiFi device for Hosted on P4 done");
|
||||
}
|
||||
return;
|
||||
@@ -64,24 +70,25 @@ void WifiDevice::scan(bool passive, bool async)
|
||||
{
|
||||
if (!_openAP)
|
||||
{
|
||||
_wifiClientStarted = false;
|
||||
WiFi.disconnect(true);
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.disconnect();
|
||||
}
|
||||
|
||||
int loop = 0;
|
||||
while (!_wifiClientStarted && loop < 50) {
|
||||
if (esp_task_wdt_status(NULL) == ESP_OK) {
|
||||
esp_task_wdt_reset();
|
||||
}
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||
loop++;
|
||||
}
|
||||
|
||||
WiFi.scanDelete();
|
||||
WiFi.setScanMethod(WIFI_ALL_CHANNEL_SCAN);
|
||||
WiFi.setSortMethod(WIFI_CONNECT_AP_BY_SIGNAL);
|
||||
|
||||
if (esp_task_wdt_status(NULL) == ESP_OK) {
|
||||
esp_task_wdt_reset();
|
||||
}
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
|
||||
if(async)
|
||||
{
|
||||
Log->println("Wi-Fi async scan started");
|
||||
@@ -126,13 +133,6 @@ void WifiDevice::openAP()
|
||||
|
||||
bool WifiDevice::connect()
|
||||
{
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.setHostname(_hostname.c_str());
|
||||
if (esp_task_wdt_status(NULL) == ESP_OK) {
|
||||
esp_task_wdt_reset();
|
||||
}
|
||||
vTaskDelay(500 / portTICK_PERIOD_MS);
|
||||
|
||||
int bestConnection = -1;
|
||||
|
||||
if(_preferences->getBool(preference_find_best_rssi, false))
|
||||
@@ -215,7 +215,7 @@ bool WifiDevice::connect()
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -284,10 +284,10 @@ void WifiDevice::onWifiEvent(const WiFiEvent_t &event, const WiFiEventInfo_t &in
|
||||
Log->printf("[WiFi-event] event: %d\n", event);
|
||||
|
||||
switch (event) {
|
||||
case ARDUINO_EVENT_WIFI_READY:
|
||||
Log->println("WiFi interface ready");
|
||||
case ARDUINO_EVENT_WIFI_READY:
|
||||
Log->println("WiFi interface ready");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_SCAN_DONE:
|
||||
case ARDUINO_EVENT_WIFI_SCAN_DONE:
|
||||
Log->println("Completed scan for access points");
|
||||
_foundNetworks = WiFi.scanComplete();
|
||||
|
||||
@@ -315,28 +315,29 @@ void WifiDevice::onWifiEvent(const WiFiEvent_t &event, const WiFiEventInfo_t &in
|
||||
scan(false, true);
|
||||
}
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_START:
|
||||
Log->println("WiFi client started");
|
||||
case ARDUINO_EVENT_WIFI_STA_START:
|
||||
Log->println("WiFi client started");
|
||||
_wifiClientStarted = true;
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_STOP:
|
||||
Log->println("WiFi clients stopped");
|
||||
case ARDUINO_EVENT_WIFI_STA_STOP:
|
||||
Log->println("WiFi clients stopped");
|
||||
if(!_openAP)
|
||||
{
|
||||
onDisconnected();
|
||||
}
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_CONNECTED:
|
||||
case ARDUINO_EVENT_WIFI_STA_CONNECTED:
|
||||
Log->println("Connected to access point");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_DISCONNECTED:
|
||||
Log->println("Disconnected from WiFi access point");
|
||||
case ARDUINO_EVENT_WIFI_STA_DISCONNECTED:
|
||||
Log->println("Disconnected from WiFi access point");
|
||||
if(!_openAP)
|
||||
{
|
||||
onDisconnected();
|
||||
}
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_AUTHMODE_CHANGE:
|
||||
Log->println("Authentication mode of access point has changed");
|
||||
case ARDUINO_EVENT_WIFI_STA_AUTHMODE_CHANGE:
|
||||
Log->println("Authentication mode of access point has changed");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_GOT_IP:
|
||||
Log->print("Obtained IP address: ");
|
||||
@@ -346,38 +347,38 @@ void WifiDevice::onWifiEvent(const WiFiEvent_t &event, const WiFiEventInfo_t &in
|
||||
onConnected();
|
||||
}
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_LOST_IP:
|
||||
case ARDUINO_EVENT_WIFI_STA_LOST_IP:
|
||||
Log->println("Lost IP address and IP address is reset to 0");
|
||||
if(!_openAP)
|
||||
{
|
||||
onDisconnected();
|
||||
}
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_AP_START:
|
||||
case ARDUINO_EVENT_WIFI_AP_START:
|
||||
Log->println("WiFi access point started");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_AP_STOP:
|
||||
Log->println("WiFi access point stopped");
|
||||
case ARDUINO_EVENT_WIFI_AP_STOP:
|
||||
Log->println("WiFi access point stopped");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_AP_STACONNECTED:
|
||||
Log->println("Client connected");
|
||||
case ARDUINO_EVENT_WIFI_AP_STACONNECTED:
|
||||
Log->println("Client connected");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_AP_STADISCONNECTED:
|
||||
Log->println("Client disconnected");
|
||||
case ARDUINO_EVENT_WIFI_AP_STADISCONNECTED:
|
||||
Log->println("Client disconnected");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_AP_STAIPASSIGNED:
|
||||
Log->println("Assigned IP address to client");
|
||||
case ARDUINO_EVENT_WIFI_AP_STAIPASSIGNED:
|
||||
Log->println("Assigned IP address to client");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_AP_PROBEREQRECVED:
|
||||
Log->println("Received probe request");
|
||||
case ARDUINO_EVENT_WIFI_AP_PROBEREQRECVED:
|
||||
Log->println("Received probe request");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_AP_GOT_IP6:
|
||||
Log->println("AP IPv6 is preferred");
|
||||
case ARDUINO_EVENT_WIFI_AP_GOT_IP6:
|
||||
Log->println("AP IPv6 is preferred");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_GOT_IP6:
|
||||
Log->println("STA IPv6 is preferred");
|
||||
case ARDUINO_EVENT_WIFI_STA_GOT_IP6:
|
||||
Log->println("STA IPv6 is preferred");
|
||||
break;
|
||||
default:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -43,4 +43,5 @@ private:
|
||||
bool _openAP = false;
|
||||
bool _startAP = true;
|
||||
bool _connected = false;
|
||||
bool _wifiClientStarted = false;
|
||||
};
|
||||
Reference in New Issue
Block a user