[improv_serial] Support non-Wi-Fi network interfaces (#17598)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Keith Burzinski
2026-08-30 20:43:59 -05:00
committed by GitHub
co-authored by J. Nick Koston
parent fbe306f00b
commit 7b97c87390
7 changed files with 193 additions and 28 deletions
@@ -0,0 +1,17 @@
ethernet:
type: W5500
clk_pin: 19
mosi_pin: 21
miso_pin: 17
cs_pin: 18
interrupt_pin: 36
reset_pin: 12
clock_speed: 10Mhz
logger:
hardware_uart: UART0
# Exercises the per-interface webserver URL collection at compile time
web_server:
improv_serial:
@@ -0,0 +1,2 @@
packages:
improv_serial: !include common-ethernet.yaml
@@ -29,6 +29,8 @@ void WiFiComponent::set_sta(const WiFiAP &ap) { ESP_LOGI(TAG, "set_sta ssid=%s",
void WiFiComponent::start_connecting(const WiFiAP &ap) {
ESP_LOGI(TAG, "start_connecting ssid=%s", ap.get_ssid().c_str());
// Connecting succeeds immediately, so the requested network is the connected one
this->connected_ssid_ = ap.get_ssid().c_str();
}
void WiFiComponent::clear_sta() { ESP_LOGI(TAG, "clear_sta"); }
@@ -13,11 +13,15 @@
#include "esphome/core/component.h"
#include "esphome/core/string_ref.h"
#include <cstdio>
#include <span>
#include <string>
#include <vector>
namespace esphome::wifi {
static constexpr size_t SSID_BUFFER_SIZE = 33;
class WiFiAP {
public:
void set_ssid(const char *ssid) { this->ssid_ = ssid; }
@@ -58,6 +62,12 @@ class WiFiComponent : public Component {
bool is_disabled() const { return false; }
// Always connected so network::is_connected() keeps the API server accepting clients
bool is_connected() const { return true; }
// Reports the network start_connecting() was last asked for, so a consumer checking that it
// joined the network it requested (rather than an earlier one) sees the connect succeed
const char *wifi_ssid_to(std::span<char, SSID_BUFFER_SIZE> buffer) {
snprintf(buffer.data(), buffer.size(), "%s", this->connected_ssid_.c_str());
return buffer.data();
}
void start_scanning();
const std::vector<WiFiScanResult> &get_scan_result() const { return this->scan_result_; }
void set_sta(const WiFiAP &ap);
@@ -70,6 +80,7 @@ class WiFiComponent : public Component {
protected:
std::vector<WiFiScanResult> scan_result_;
std::string connected_ssid_;
};
extern WiFiComponent *global_wifi_component; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)