- Guard the boot-time link bootstrap to observer ESP32 builds. It ran unconditionally in MyMesh::begin(), breaking every non-observer repeater/room server build (ESP32 and nRF52). - Rename NetworkInterface -> NetworkLink (class, accessor, files). Arduino-ESP32 3.x ships its own NetworkInterface class and header, which broke the ESP32-C6 builds. Drop WiFi.setAutoConnect(), a no-op on 2.x and removed in 3.x. - Refresh stored Wi-Fi credentials every bridge tick so the STA reconnect loop picks up `set wifi.ssid` / `set wifi.pwd` without a reboot, as the bridge did before the link moved out of it. Skip reconnects while the SSID is empty. - Restore the "WiFi connected: <ip>" / "WiFi disconnected: reason N" debug lines the bridge used to print. - Alert on Ethernet only once it has held a lease this boot or when no Wi-Fi is configured; Wi-Fi-only installs of an Ethernet-preferred image keep Wi-Fi alerts instead of reporting "Ethernet down". - Record wifi.setup_complete only for Ethernet LAN onboarding, so Wi-Fi builds keep the SSID-based first-boot portal rule. - Use seq_cst for the route-switch lock/mutation flag handshake. - Docs: SNMP RSSI sentinel is -127; describe link-return vs medium-switch reconnect behavior accurately; note runtime credential pickup. - Test: unknown keys inside a known /mqtt.json group are ignored, which keeps wifi.setup_complete downgrade-safe.
82 lines
3.1 KiB
C++
82 lines
3.1 KiB
C++
#pragma once
|
|
|
|
#include "NetworkPolicy.h"
|
|
|
|
#if defined(ESP_PLATFORM)
|
|
|
|
#include <Arduino.h>
|
|
#include <IPAddress.h>
|
|
#include "AlertFaultPolicy.h"
|
|
|
|
#ifndef NETWORK_ETHERNET_BOOT_WAIT_MS
|
|
#define NETWORK_ETHERNET_BOOT_WAIT_MS 8000UL
|
|
#endif
|
|
|
|
/**
|
|
* Physical network selected for IP-based services.
|
|
*
|
|
* The interface owns link bring-up and medium-specific maintenance. MQTT, NTP,
|
|
* OTA, and other socket users only consume connectivity and addressing. Normal
|
|
* MQTT shutdown deliberately does not stop this interface because an OTA
|
|
* download runs after the broker clients have been released.
|
|
*/
|
|
class NetworkLink {
|
|
public:
|
|
virtual ~NetworkLink() = default;
|
|
|
|
virtual const char* mediumName() const = 0;
|
|
virtual NetworkMedium medium() const = 0;
|
|
virtual const char* statusName() const = 0;
|
|
virtual int statusCode() const = 0;
|
|
virtual bool configValid(const char* wifi_ssid) const = 0;
|
|
// Configure the DHCP hostname before begin()/bootstrap(). Implementations
|
|
// retain it for any later fallback interface start.
|
|
virtual void setHostname(const char* hostname) = 0;
|
|
virtual bool begin(const char* wifi_ssid, const char* wifi_password) = 0;
|
|
// Latest stored credentials; the next reconnect attempt uses them without a reboot.
|
|
virtual void updateWifiCredentials(const char* wifi_ssid, const char* wifi_password) {
|
|
(void)wifi_ssid;
|
|
(void)wifi_password;
|
|
}
|
|
virtual NetworkTransition maintain(uint32_t now_ms, uint8_t wifi_power_save) = 0;
|
|
|
|
// Automatic selectors are boot-owned so first-run services can use the
|
|
// chosen link before MQTT starts. Compatibility Wi-Fi builds keep the
|
|
// original MQTT-task-owned begin() path.
|
|
virtual bool isAutomatic() const { return false; }
|
|
virtual bool bootstrap(const char* wifi_ssid, const char* wifi_password,
|
|
uint32_t wait_ms) {
|
|
(void)wait_ms;
|
|
return begin(wifi_ssid, wifi_password);
|
|
}
|
|
|
|
// WebConfig and OTA pin the current route for the lifetime of their session.
|
|
virtual void lockSwitching() {}
|
|
virtual void unlockSwitching() {}
|
|
|
|
virtual bool isConnected() const = 0;
|
|
virtual IPAddress localIP() const = 0;
|
|
virtual int rssi() const = 0; // INT_MIN when the selected medium has no RSSI.
|
|
virtual bool resolveHost(const char* hostname, IPAddress& address) const = 0;
|
|
virtual void formatDiagnostics(char* reply, size_t reply_size) const = 0;
|
|
|
|
virtual unsigned long connectedAtMillis() const = 0;
|
|
virtual uint8_t lastDisconnectReason() const = 0;
|
|
virtual unsigned long lastDisconnectTime() const = 0;
|
|
virtual AlertFaultPolicy::OutageSnapshot outageSnapshot() const = 0;
|
|
|
|
// Fault reporting normally follows the selected interface. Automatic
|
|
// Ethernet-preferred builds instead keep reporting the primary Ethernet
|
|
// outage while healthy Wi-Fi carries traffic, so prolonged degradation is
|
|
// not hidden by a successful fallback.
|
|
virtual NetworkMedium alertMedium() const { return medium(); }
|
|
virtual AlertFaultPolicy::OutageSnapshot alertOutageSnapshot() const {
|
|
return outageSnapshot();
|
|
}
|
|
};
|
|
|
|
/** Build-selected singleton. Wi-Fi is the compatibility default. */
|
|
NetworkLink& activeNetworkLink();
|
|
|
|
#endif
|