Add internet radio streaming with runtime API, modernize web UI, remove auto-tune/beep at boot

Streaming (main feature this session):
- New WebRadioConfig/WebRadioJson core types, ISecureStore-backed persistence
- New webradio::WebRadioService (thread-safe live config) + GET/POST /api/streaming
- web_radio_stream task now runtime-toggleable (no reboot), no hardcoded URL
- Content-Type diagnostic: warns clearly when a URL is a webpage, not an audio stream

Boot cleanup:
- Removed boot-time auto FM/DAB tune, auto-beep, and the (now-concluded) Si4684
  crystal IBIAS/CTUN empirical sweep from main.cpp — tuning/beep are on-demand
  via the existing REST API only

Web UI:
- Modernized styling (cards, gradients, toggle switches, light/dark theme)
- New Stream tab wired to /api/streaming

Fixes found via real idf.py build (not just clangd):
- Restored wrongly-removed si4684/Si4684Tuner.hpp include in main.cpp
- Fixed MP3Decode() argument types in web_radio_stream.cpp (unsigned char**/int*)

Quality-gate fixes:
- Host-test stub headers (esp_log.h, freertos/*) so TunerService.cpp's
  scanForStation logging/pacing compiles for station_service_test /
  integration_service_test instead of running stale binaries
- Added WifiScanner and WebRadioService manual sections; filled in missing
  Doxygen docs on BluetoothService, i2s_sdata_probe, test_firmware, Bt1035At
- Ignore clangd's .cache/ index directory

Also includes prior uncommitted work carried in the tree: Wi-Fi/Bluetooth
device scan REST API and UI (WifiScanner, BT scan), SigmaStudio TCP bridge,
and the current ADAU1701 SigmaStudio DSP program export.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-08 21:15:22 +02:00
co-authored by Claude Sonnet 5
parent 8a8523515d
commit 6f7b6dd12c
131 changed files with 20309 additions and 1702 deletions
@@ -122,6 +122,25 @@ public:
[[nodiscard]] std::expected<void, core::StoreError>
clearLastPresetIndex() override;
[[nodiscard]] bool hasBtSpeakerTarget() const override;
[[nodiscard]] std::expected<void, core::StoreError>
saveBtSpeakerTarget(const core::BtSpeakerTarget& target) override;
[[nodiscard]] std::expected<core::BtSpeakerTarget, core::StoreError>
loadBtSpeakerTarget() const override;
[[nodiscard]] std::expected<void, core::StoreError>
clearBtSpeakerTarget() override;
[[nodiscard]] bool hasWebRadioConfig() const override;
[[nodiscard]] std::expected<void, core::StoreError>
saveWebRadioConfigJson(std::string_view json) override;
[[nodiscard]] std::expected<std::string, core::StoreError>
loadWebRadioConfigJson() const override;
};
} // namespace secure_store
@@ -18,6 +18,7 @@
#include "secure_store/NvsSecureStore.hpp"
#include "core/Bt1035At.hpp"
#include "esp_log.h"
#include "nvs.h"
#include "nvs_flash.h"
@@ -33,6 +34,9 @@ constexpr char kSsidKey[] = "wifi_ssid";
constexpr char kPasswordKey[] = "wifi_pwd";
constexpr char kStationListKey[] = "station_list";
constexpr char kLastPresetKey[] = "last_preset";
constexpr char kBtSpeakerMacKey[] = "bt_spk_mac";
constexpr char kBtSpeakerNameKey[] = "bt_spk_name";
constexpr char kWebRadioConfigKey[] = "web_radio_cfg";
constexpr char kTag[] = "NvsSecureStore";
} // namespace
@@ -41,8 +45,15 @@ bool NvsSecureStore::hasWifiCredentials() const
nvs_handle_t handle = 0;
const esp_err_t openErr = nvs_open(kNamespace, NVS_READONLY, &handle);
if (openErr != ESP_OK) {
ESP_LOGW(kTag, "nvs_open failed in hasWifiCredentials (0x%x)",
static_cast<unsigned>(openErr));
if (openErr == ESP_ERR_NVS_NOT_FOUND) {
ESP_LOGD(kTag,
"no wifi credentials namespace yet in hasWifiCredentials "
"(0x%x)",
static_cast<unsigned>(openErr));
} else {
ESP_LOGW(kTag, "nvs_open failed in hasWifiCredentials (0x%x)",
static_cast<unsigned>(openErr));
}
return false;
}
@@ -313,4 +324,170 @@ std::expected<void, core::StoreError> NvsSecureStore::clearLastPresetIndex()
return {};
}
bool NvsSecureStore::hasBtSpeakerTarget() const
{
nvs_handle_t handle = 0;
if (nvs_open(kNamespace, NVS_READONLY, &handle) != ESP_OK) {
return false;
}
std::size_t macLen = 0;
const esp_err_t err = nvs_get_str(handle, kBtSpeakerMacKey, nullptr, &macLen);
nvs_close(handle);
return err == ESP_OK && macLen > 1U;
}
std::expected<void, core::StoreError>
NvsSecureStore::saveBtSpeakerTarget(const core::BtSpeakerTarget& target)
{
if (!core::isValidBt1035Mac(target.mac)) {
return std::unexpected(core::StoreError::InvalidData);
}
nvs_handle_t handle = 0;
if (nvs_open(kNamespace, NVS_READWRITE, &handle) != ESP_OK) {
return std::unexpected(core::StoreError::IoFailed);
}
esp_err_t err = nvs_set_str(handle, kBtSpeakerMacKey, target.mac.c_str());
if (err == ESP_OK) {
err = nvs_set_str(handle, kBtSpeakerNameKey, target.name.c_str());
}
if (err == ESP_OK) {
err = nvs_commit(handle);
}
nvs_close(handle);
if (err != ESP_OK) {
return std::unexpected(core::StoreError::IoFailed);
}
ESP_LOGI(kTag, "BT speaker target saved (%s)", target.mac.c_str());
return {};
}
std::expected<core::BtSpeakerTarget, core::StoreError>
NvsSecureStore::loadBtSpeakerTarget() const
{
nvs_handle_t handle = 0;
if (nvs_open(kNamespace, NVS_READONLY, &handle) != ESP_OK) {
return std::unexpected(core::StoreError::NotFound);
}
std::size_t macLen = 0;
if (nvs_get_str(handle, kBtSpeakerMacKey, nullptr, &macLen) != ESP_OK
|| macLen == 0U) {
nvs_close(handle);
return std::unexpected(core::StoreError::NotFound);
}
std::vector<char> macBuf(macLen);
if (nvs_get_str(handle, kBtSpeakerMacKey, macBuf.data(), &macLen) != ESP_OK) {
nvs_close(handle);
return std::unexpected(core::StoreError::IoFailed);
}
std::string name;
std::size_t nameLen = 0;
if (nvs_get_str(handle, kBtSpeakerNameKey, nullptr, &nameLen) == ESP_OK
&& nameLen > 0U) {
std::vector<char> nameBuf(nameLen);
if (nvs_get_str(handle, kBtSpeakerNameKey, nameBuf.data(), &nameLen)
== ESP_OK) {
name.assign(nameBuf.data());
}
}
nvs_close(handle);
const std::string mac = core::normalizeBt1035Mac(macBuf.data());
if (!core::isValidBt1035Mac(mac)) {
return std::unexpected(core::StoreError::InvalidData);
}
return core::BtSpeakerTarget{.mac = mac, .name = std::move(name)};
}
std::expected<void, core::StoreError> NvsSecureStore::clearBtSpeakerTarget()
{
nvs_handle_t handle = 0;
if (nvs_open(kNamespace, NVS_READWRITE, &handle) != ESP_OK) {
return std::unexpected(core::StoreError::IoFailed);
}
esp_err_t err = nvs_erase_key(handle, kBtSpeakerMacKey);
if (err == ESP_OK || err == ESP_ERR_NVS_NOT_FOUND) {
err = nvs_erase_key(handle, kBtSpeakerNameKey);
}
if (err == ESP_OK || err == ESP_ERR_NVS_NOT_FOUND) {
err = nvs_commit(handle);
}
nvs_close(handle);
if (err != ESP_OK && err != ESP_ERR_NVS_NOT_FOUND) {
return std::unexpected(core::StoreError::IoFailed);
}
ESP_LOGI(kTag, "BT speaker target cleared");
return {};
}
bool NvsSecureStore::hasWebRadioConfig() const
{
nvs_handle_t handle = 0;
if (nvs_open(kNamespace, NVS_READONLY, &handle) != ESP_OK) {
return false;
}
std::size_t len = 0;
const esp_err_t err =
nvs_get_str(handle, kWebRadioConfigKey, nullptr, &len);
nvs_close(handle);
return err == ESP_OK && len > 1;
}
std::expected<void, core::StoreError>
NvsSecureStore::saveWebRadioConfigJson(std::string_view json)
{
nvs_handle_t handle = 0;
if (nvs_open(kNamespace, NVS_READWRITE, &handle) != ESP_OK) {
return std::unexpected(core::StoreError::IoFailed);
}
const std::string payload(json);
esp_err_t err = nvs_set_str(handle, kWebRadioConfigKey, payload.c_str());
if (err == ESP_OK) {
err = nvs_commit(handle);
}
nvs_close(handle);
if (err != ESP_OK) {
return std::unexpected(core::StoreError::IoFailed);
}
return {};
}
std::expected<std::string, core::StoreError>
NvsSecureStore::loadWebRadioConfigJson() const
{
nvs_handle_t handle = 0;
if (nvs_open(kNamespace, NVS_READONLY, &handle) != ESP_OK) {
return std::unexpected(core::StoreError::NotFound);
}
std::size_t len = 0;
if (nvs_get_str(handle, kWebRadioConfigKey, nullptr, &len) != ESP_OK
|| len == 0) {
nvs_close(handle);
return std::unexpected(core::StoreError::NotFound);
}
std::vector<char> buffer(len);
if (nvs_get_str(handle, kWebRadioConfigKey, buffer.data(), &len)
!= ESP_OK) {
nvs_close(handle);
return std::unexpected(core::StoreError::IoFailed);
}
nvs_close(handle);
return std::string(buffer.data());
}
} // namespace secure_store