From 5af6067d8eab7e852e88853252373c293baa4fec Mon Sep 17 00:00:00 2001 From: David Sutton Date: Thu, 30 Jul 2026 10:47:45 +0930 Subject: [PATCH 1/2] Speaker: Change logging config This change updates the config for logging so that colours aren't used, and the time printed is the system time, and not millis since boot --- esp/speaker-netsender/sdkconfig | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/esp/speaker-netsender/sdkconfig b/esp/speaker-netsender/sdkconfig index f26f51a..630b1ef 100644 --- a/esp/speaker-netsender/sdkconfig +++ b/esp/speaker-netsender/sdkconfig @@ -1898,12 +1898,9 @@ CONFIG_LOG_TAG_LEVEL_IMPL_CACHE_SIZE=31 # # Format # -# default: # CONFIG_LOG_COLORS is not set -# default: -CONFIG_LOG_TIMESTAMP_SOURCE_RTOS=y -# default: -# CONFIG_LOG_TIMESTAMP_SOURCE_SYSTEM is not set +# CONFIG_LOG_TIMESTAMP_SOURCE_RTOS is not set +CONFIG_LOG_TIMESTAMP_SOURCE_SYSTEM=y # end of Format # From 6ed32f89225708a38fa1a75fc88ae43faeefe1a7 Mon Sep 17 00:00:00 2001 From: David Sutton Date: Fri, 31 Jul 2026 11:01:30 +0930 Subject: [PATCH 2/2] ESP/Speaker: Use Network Time Sync This change initialises network time using SNTP. As part of this change, UDP logging has been disabled due to conflicts on the network interface. Since this will be getting adjusted in future changes, it has just been removed for now. --- esp/speaker-netsender/main/CMakeLists.txt | 2 +- esp/speaker-netsender/main/include/time.hpp | 29 ++++++++++ esp/speaker-netsender/main/main.cpp | 10 ++-- esp/speaker-netsender/main/time.cpp | 59 +++++++++++++++++++++ 4 files changed, 94 insertions(+), 6 deletions(-) create mode 100644 esp/speaker-netsender/main/include/time.hpp create mode 100644 esp/speaker-netsender/main/time.cpp diff --git a/esp/speaker-netsender/main/CMakeLists.txt b/esp/speaker-netsender/main/CMakeLists.txt index 728062e..c82750f 100755 --- a/esp/speaker-netsender/main/CMakeLists.txt +++ b/esp/speaker-netsender/main/CMakeLists.txt @@ -1,4 +1,4 @@ -idf_component_register(SRCS "main.cpp" "audio.cpp" "ethernet.cpp" "sd.cpp" "self_check.cpp" +idf_component_register(SRCS "main.cpp" "audio.cpp" "ethernet.cpp" "sd.cpp" "self_check.cpp" "time.cpp" INCLUDE_DIRS "." "include" REQUIRES esp_driver_sdspi esp_eth esp_netif fatfs sdmmc driver tas5805 netsender ota_tcp pipi) diff --git a/esp/speaker-netsender/main/include/time.hpp b/esp/speaker-netsender/main/include/time.hpp new file mode 100644 index 0000000..4581e53 --- /dev/null +++ b/esp/speaker-netsender/main/include/time.hpp @@ -0,0 +1,29 @@ +/* + Name: + time.hpp - Time management utilities and helpers. + + Authors: + David Sutton + + License: + Copyright (C) 2026 The Australian Ocean Lab (AusOcean). + + This file is part of NetSender. NetSender is free software: you can + redistribute it and/or modify it under the terms of the GNU + General Public License as published by the Free Software + Foundation, either version 3 of the License, or (at your option) + any later version. + + NetSender is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with NetSender in gpl.txt. If not, see + . +*/ + +// Initialises network time syncing. +// NOTE: All times are handled in UTC. +void initialise_sntp(); diff --git a/esp/speaker-netsender/main/main.cpp b/esp/speaker-netsender/main/main.cpp index aa02be2..6d92bc1 100644 --- a/esp/speaker-netsender/main/main.cpp +++ b/esp/speaker-netsender/main/main.cpp @@ -40,10 +40,10 @@ #include "include/audio.hpp" #include "include/ethernet.hpp" #include "include/globals.h" -#include "include/log.hpp" #include "include/netsender_vars.hpp" #include "include/sd.hpp" #include "include/self_check.hpp" +#include "include/time.hpp" #include "netsender.hpp" #include "ota_tcp.hpp" #include "tas5805.hpp" @@ -126,10 +126,6 @@ void app_main(void) init_ethernet(); ESP_LOGI(TAG, "Ethernet initialised"); - ESP_LOGI(TAG, "Initialising UDP Logging"); - init_udp_logging(); - ESP_LOGI(TAG, "Logging Initialised"); - ESP_LOGI(TAG, "Initialising SD card"); init_sd(); ESP_LOGI(TAG, "SD initialised"); @@ -142,6 +138,10 @@ void app_main(void) const auto valid_partition = self_check_ok(&); ota_tcp_validate_partition(valid_partition); + ESP_LOGI(TAG, "Initialising SNTP"); + initialise_sntp(); + ESP_LOGI(TAG, "SNTP Initialised"); + ESP_LOGI(TAG, "Initialising OTA listener"); init_ota_tcp(); ESP_LOGI(TAG, "OTA Initialised"); diff --git a/esp/speaker-netsender/main/time.cpp b/esp/speaker-netsender/main/time.cpp new file mode 100644 index 0000000..14fcfbc --- /dev/null +++ b/esp/speaker-netsender/main/time.cpp @@ -0,0 +1,59 @@ +/* + Name: + time.cpp - Time management utilities and helpers. + + Authors: + David Sutton + + License: + Copyright (C) 2026 The Australian Ocean Lab (AusOcean). + + This file is part of NetSender. NetSender is free software: you can + redistribute it and/or modify it under the terms of the GNU + General Public License as published by the Free Software + Foundation, either version 3 of the License, or (at your option) + any later version. + + NetSender is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with NetSender in gpl.txt. If not, see + . +*/ + +// Logging TAG. +#include "include/time.hpp" + +#include + +#include "esp_err.h" +#include "esp_log.h" +#include "esp_netif_sntp.h" + +// Logging TAG. +static constexpr auto TAG = "time"; + +void initialise_sntp() +{ + esp_sntp_config_t config = ESP_NETIF_SNTP_DEFAULT_CONFIG("pool.ntp.org"); + auto err = esp_netif_sntp_init(&config); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to initialize SNTP (%s)", esp_err_to_name(err)); + return; + } + + auto retry = 0; + const auto max_retries = 10; + while ((err = esp_netif_sntp_sync_wait(pdMS_TO_TICKS(2000))) != ESP_OK && ++retry < max_retries) { + ESP_LOGI(TAG, "Attempt to synchronise time (%d/%d) failed: %s", retry, max_retries, esp_err_to_name(err)); + } + + if (retry >= max_retries) { + ESP_LOGE(TAG, "Failed to synchronize time within timeout!"); + } else { + ESP_LOGI(TAG, "System time set successfully"); + } +}