added udp logger to log over network and not uart

Added modem sleep for wif
This commit is contained in:
2026-03-14 17:27:24 -04:00
parent b702839f8e
commit a9d5aa83dc
9 changed files with 171 additions and 4 deletions

View File

@@ -5,6 +5,7 @@
// SDK
#include "esp_log.h"
#include "esp_ota_ops.h"
#include "esp_pm.h"
#include "esp_psram.h"
#include "esp_system.h"
#include "freertos/FreeRTOS.h"
@@ -24,6 +25,7 @@
#include "connect.cpp"
#include "http_server.cpp"
#include "mdns_service.cpp"
#include "udp_logger.cpp"
// clang-format on
internal const char *kTagMain = "MAIN";
@@ -35,11 +37,24 @@ uint8_t g_Active_WWW_Partition = 0;
constexpr bool kBlockUntilEthernetEstablished = false;
internal void my_timer_callback(void *arg)
{
ESP_LOGI(kTagMain, "Timer finished! Turning Led Off...");
destroy_led();
}
extern "C" void app_main()
{
ESP_LOGI(kTagMain, "Hello, Calendink OTA! [V0.1.1]");
ESP_LOGI(kTagMain, "PSRAM size: %d bytes", esp_psram_get_size());
#if CONFIG_PM_ENABLE
esp_pm_config_t pm_config = {
.max_freq_mhz = 240, .min_freq_mhz = 40, .light_sleep_enable = true};
esp_pm_configure(&pm_config);
ESP_LOGI(kTagMain, "Dynamic Power Management initialized (Tickless Idle).");
#endif
httpd_handle_t web_server = NULL;
esp_err_t err = nvs_flash_init();
@@ -252,6 +267,10 @@ extern "C" void app_main()
ESP_LOGI(kTagMain, "Connected! IP acquired.");
#if !defined(NDEBUG)
start_udp_logging(514);
#endif
// Start the webserver
web_server = start_webserver();
@@ -269,10 +288,58 @@ extern "C" void app_main()
}
}
// Keep the main task alive indefinitely
while (true)
{
vTaskDelay(pdMS_TO_TICKS(1000));
const esp_timer_create_args_t timer_args = {.callback = &my_timer_callback,
.arg = nullptr,
.dispatch_method =
ESP_TIMER_TASK,
.name = "Led Turn Off",
.skip_unhandled_events = true};
// Create and start timer if needed, or this was just stub code?
esp_timer_handle_t timer_handle;
if (esp_timer_create(&timer_args, &timer_handle) == ESP_OK)
{
esp_timer_start_once(timer_handle, 5'000'000); // 5 sec cooldown
}
}
// Keep the main task alive indefinitely
{
#if CONFIG_PM_PROFILING
int pm_dump_counter = 0;
#endif
while (true)
{
vTaskDelay(pdMS_TO_TICKS(100));
#if CONFIG_PM_PROFILING
if (++pm_dump_counter >= 50)
{ // Every 5 seconds
pm_dump_counter = 0;
ESP_LOGI(kTagMain, "--- PM Profiling Dump ---");
char *ptr = nullptr;
size_t size = 0;
FILE *f = open_memstream(&ptr, &size);
if (f != nullptr)
{
esp_pm_dump_locks(f);
fclose(f);
if (ptr != nullptr)
{
char *saveptr;
char *line = strtok_r(ptr, "\n", &saveptr);
while (line != nullptr) {
ESP_LOGI(kTagMain, "%s", line);
line = strtok_r(nullptr, "\n", &saveptr);
}
free(ptr);
}
}
}
#endif
}
}
shutdown: