Files
DigiRadio/Software/components/net/include/net/StaClient.hpp
T
micheleandClaude Sonnet 5 6f7b6dd12c 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>
2026-08-08 21:15:22 +02:00

117 lines
3.1 KiB
C++

/**
* @file StaClient.hpp
* @brief RAII helper that joins a Wi-Fi network in STA mode.
*
* DigiRadio firmware — https://github.com/manvalan/DigiRadio
*
* Copyright 2026 Michele Bigi
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* @author Michele Bigi
* @date 2026-07-06
*/
#pragma once
#include "core/WifiCredentials.hpp"
#include "net/NetError.hpp"
#include "esp_event.h"
#include <expected>
#include <string_view>
namespace net {
/**
* @brief StaClient — connects the ESP32 to a stored Wi-Fi network.
*
* @dname StaClient
* @return n/a (type)
* @pubstate Owns connected_ (whether STA link + IP are up). Assumes
* esp_wifi_init() was already called by NetBootstrap.
*
* @author Michele Bigi
* @date 2026-07-06
*/
class StaClient {
public:
/**
* @brief StaClient — construct an unconnected STA client.
*
* @dname StaClient
* @pubstate clears connected_.
*
* @author Michele Bigi
* @date 2026-07-06
*/
StaClient();
/**
* @brief ~StaClient — disconnect STA if connected.
*
* @dname ~StaClient
* @pubstate stops Wi-Fi when connected_ is true.
*
* @author Michele Bigi
* @date 2026-07-06
*/
~StaClient();
StaClient(const StaClient&) = delete;
StaClient& operator=(const StaClient&) = delete;
/**
* @brief StaClient — move-construct, transferring connection state.
*
* @dname StaClient
* @param other Source client; left disconnected after the move.
* @pubstate transfers connected_ from other.
*
* @author Michele Bigi
* @date 2026-07-06
*/
StaClient(StaClient&& other) noexcept;
/**
* @brief operator= — move-assign, transferring connection state.
*
* @dname operator=
* @param other Source client; left disconnected after the move.
* @return Reference to this instance.
* @pubstate transfers connected_ from other.
*
* @author Michele Bigi
* @date 2026-07-06
*/
StaClient& operator=(StaClient&& other) noexcept;
/**
* @brief connect — join the network described by creds.
*
* @dname connect
* @param creds Validated domain credentials from ISecureStore.
* @param hostname STA hostname / mDNS label (no .local suffix).
* @return Ok on success, or NetError::StaConnectTimeout /
* NetError::StaConnectFailed.
* @pubstate writes connected_ on success; uses creds via Secret.
*
* @author Michele Bigi
* @date 2026-07-06
*/
[[nodiscard]] std::expected<void, NetError>
connect(const core::WifiCredentials& creds,
std::string_view hostname = {});
private:
bool connected_;
esp_event_handler_instance_t wifiHandler_;
esp_event_handler_instance_t ipHandler_;
};
} // namespace net