Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion esp/speaker-netsender/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
29 changes: 29 additions & 0 deletions esp/speaker-netsender/main/include/time.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Name:
time.hpp - Time management utilities and helpers.

Authors:
David Sutton <davidsutton@ausocean.org>

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
<http://www.gnu.org/licenses/>.
*/

// Initialises network time syncing.
// NOTE: All times are handled in UTC.
void initialise_sntp();
10 changes: 5 additions & 5 deletions esp/speaker-netsender/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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");
Expand All @@ -142,6 +138,10 @@ void app_main(void)
const auto valid_partition = self_check_ok(&amp);
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");
Expand Down
59 changes: 59 additions & 0 deletions esp/speaker-netsender/main/time.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
Name:
time.cpp - Time management utilities and helpers.

Authors:
David Sutton <davidsutton@ausocean.org>

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
<http://www.gnu.org/licenses/>.
*/

// Logging TAG.
#include "include/time.hpp"

#include <ctime>

#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");
}
}
7 changes: 2 additions & 5 deletions esp/speaker-netsender/sdkconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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

#
Expand Down
Loading