SensESP 3.5.1-alpha
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
sensesp::WiFiProvisioner Class Reference

Manages the ESP's WiFi connection. More...

#include <sensesp/net/wifi_provisioner.h>

Inheritance diagram for sensesp::WiFiProvisioner:
[legend]

Public Member Functions

 WiFiProvisioner (const String &config_path, const String &client_ssid="", const String &client_password="", const String &ap_ssid="", const String &ap_password="")
 
 WiFiProvisioner (const String &config_path, const std::vector< ClientSSIDConfig > &client_configs, const String &ap_ssid="", const String &ap_password="")
 Construct with a preset list of client (STA) networks.
 
 ~WiFiProvisioner () override
 
void reset () override
 
bool to_json (JsonObject &doc) override
 
bool from_json (const JsonObject &config) override
 
IPAddress local_ip () const override
 Current local IPv4 address. Returns IPAddress() if no link.
 
IPAddress gateway_ip () const override
 Default gateway IPv4 address. Returns IPAddress() if no link.
 
String mac_address () const override
 Hardware MAC address of the active interface.
 
bool is_connected () const override
 True iff the network interface is usable.
 
ValueProducer< WiFiState > * get_wifi_state_producer ()
 
IPAddress soft_ap_ip () const
 
bool is_captive_portal_enabled () const
 
String ssid () const
 
int rssi () const
 
void start_wifi_scan ()
 
int16_t get_wifi_scan_results (std::vector< WiFiNetworkInfo > &ssid_list)
 
- Public Member Functions inherited from sensesp::FileSystemSaveable
 FileSystemSaveable (const String &config_path)
 
virtual bool load () override
 Load and populate the object from a persistent storage.
 
virtual bool save () override
 Save the object to a persistent storage.
 
virtual bool clear () override
 Delete the data from a persistent storage.
 
bool find_config_file (const String &config_path, String &filename)
 
- Public Member Functions inherited from sensesp::Saveable
 Saveable (const String &config_path)
 
virtual bool refresh ()
 Refresh the object. This may or may not access the persistent storage but is not expected to overwrite the object's state.
 
const String & get_config_path () const
 
- Public Member Functions inherited from sensesp::Resettable
 Resettable (int priority=0)
 
const int get_reset_priority () const
 
void set_reset_priority (int priority)
 
- Public Member Functions inherited from sensesp::NetworkProvisioner
virtual ~NetworkProvisioner ()=default
 
- Public Member Functions inherited from sensesp::ValueProducer< WiFiState >
 ValueProducer ()
 
 ValueProducer (const WiFiState &initial_value)
 
virtual const WiFiStateget () const
 
std::enable_if< std::is_base_of< ValueConsumer< typenameVConsumer::input_type >, VConsumer >::value &&std::is_convertible< WiFiState, typenameVConsumer::input_type >::value, std::shared_ptr< VConsumer > >::type connect_to (std::shared_ptr< VConsumer > consumer)
 Connect a producer to a transform with a different input type.
 
std::enable_if< std::is_base_of< ValueConsumer< typenameVConsumer::input_type >, VConsumer >::value &&std::is_convertible< WiFiState, typenameVConsumer::input_type >::value, VConsumer * >::type connect_to (VConsumer *consumer)
 
std::enable_if< std::is_base_of< ValueConsumer< typenameVConsumer::input_type >, VConsumer >::value &&std::is_convertible< WiFiState, typenameVConsumer::input_type >::value, VConsumer * >::type connect_to (VConsumer &consumer)
 
void emit (const WiFiState &new_value)
 
- Public Member Functions inherited from sensesp::Observable
 Observable ()
 
 Observable (Observable &&other)
 Move constructor.
 
void notify ()
 
int attach (std::function< void()> observer)
 Attach an observer callback.
 
void detach (int id)
 Remove a previously attached observer by its ID.
 

Protected Member Functions

void init_wifi ()
 Bring the WiFi interface up from the current ap_settings_ / client_settings_ state. Shared by both constructors: it pads the client list to kMaxNumClientConfigs, selects the STA/AP/AP+STA mode, and starts the access point, client autoconnect, and captive-portal DNS as needed.
 
void start_access_point ()
 
void start_client_autoconnect ()
 

Protected Attributes

AccessPointSettings ap_settings_
 
bool client_enabled_ = false
 
std::vector< ClientSSIDConfigclient_settings_
 
std::unique_ptr< DNSServer > dns_server_
 
- Protected Attributes inherited from sensesp::Saveable
const String config_path_
 
- Protected Attributes inherited from sensesp::ValueProducer< WiFiState >
WiFiState output_
 

Additional Inherited Members

- Static Public Member Functions inherited from sensesp::Resettable
static void reset_all ()
 

Detailed Description

Manages the ESP's WiFi connection.

Inherits from NetworkProvisioner so SensESPApp can hold any provisioner implementation through the same shared_ptr type. Adds WiFi-specific methods (scanning, soft-AP IP, captive portal flag) directly on the concrete class — code that needs them holds a typed pointer via SensESPApp::get_wifi_provisioner().

The legacy Networking class name is preserved as a typedef in networking.h for source-level backward compatibility.

Definition at line 170 of file wifi_provisioner.h.

Constructor & Destructor Documentation

◆ WiFiProvisioner() [1/2]

sensesp::WiFiProvisioner::WiFiProvisioner ( const String &  config_path,
const String &  client_ssid = "",
const String &  client_password = "",
const String &  ap_ssid = "",
const String &  ap_password = "" 
)

Definition at line 26 of file wifi_provisioner.cpp.

Here is the call graph for this function:

◆ WiFiProvisioner() [2/2]

sensesp::WiFiProvisioner::WiFiProvisioner ( const String &  config_path,
const std::vector< ClientSSIDConfig > &  client_configs,
const String &  ap_ssid = "",
const String &  ap_password = "" 
)

Construct with a preset list of client (STA) networks.

Seeds up to kMaxNumClientConfigs client configurations that are tried in order, failing over between them, when the device is not already associated. Use this instead of the single-SSID constructor to define more than one network in code (the same list the web UI edits).

Like the single-SSID constructor, the presets are applied only when no configuration has been saved to flash yet; a saved (e.g. web-UI-edited) list always wins and is never overwritten. Client entries with an empty SSID or password are ignored. Any entries beyond kMaxNumClientConfigs are dropped.

Parameters
config_pathflash config path (identifies the saved object)
client_configsordered list of client networks to try
ap_ssidsoft-AP SSID, or "" to leave the AP disabled
ap_passwordsoft-AP password

Definition at line 54 of file wifi_provisioner.cpp.

Here is the call graph for this function:

◆ ~WiFiProvisioner()

sensesp::WiFiProvisioner::~WiFiProvisioner ( )
override

Definition at line 144 of file wifi_provisioner.cpp.

Member Function Documentation

◆ from_json()

bool sensesp::WiFiProvisioner::from_json ( const JsonObject &  root)
overridevirtual

Deserializes the current object data from a JsonObject.

Reimplemented from sensesp::Serializable.

Definition at line 282 of file wifi_provisioner.cpp.

Here is the call graph for this function:

◆ gateway_ip()

IPAddress sensesp::WiFiProvisioner::gateway_ip ( ) const
inlineoverridevirtual

Default gateway IPv4 address. Returns IPAddress() if no link.

Implements sensesp::NetworkProvisioner.

Definition at line 213 of file wifi_provisioner.h.

◆ get_wifi_scan_results()

int16_t sensesp::WiFiProvisioner::get_wifi_scan_results ( std::vector< WiFiNetworkInfo > &  ssid_list)

Definition at line 357 of file wifi_provisioner.cpp.

◆ get_wifi_state_producer()

ValueProducer< WiFiState > * sensesp::WiFiProvisioner::get_wifi_state_producer ( )
inline
Deprecated:
Use SensESPApp::get_network_state_producer() or connect_to() on this WiFiProvisioner directly (it is now a ValueProducer<WiFiState>). Kept for source compatibility with code that called get_networking()->get_wifi_state_producer().

Definition at line 226 of file wifi_provisioner.h.

◆ init_wifi()

void sensesp::WiFiProvisioner::init_wifi ( )
protected

Bring the WiFi interface up from the current ap_settings_ / client_settings_ state. Shared by both constructors: it pads the client list to kMaxNumClientConfigs, selects the STA/AP/AP+STA mode, and starts the access point, client autoconnect, and captive-portal DNS as needed.

Definition at line 89 of file wifi_provisioner.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_captive_portal_enabled()

bool sensesp::WiFiProvisioner::is_captive_portal_enabled ( ) const
inline

Definition at line 230 of file wifi_provisioner.h.

◆ is_connected()

bool sensesp::WiFiProvisioner::is_connected ( ) const
inlineoverridevirtual

True iff the network interface is usable.

For STA/Ethernet this means link up + IP obtained. For WiFi in AP mode this also returns true — the device is network-reachable via the soft-AP even though it has no upstream connection. The Signal K websocket client uses this to gate connection attempts; the HTTP server uses it to know when the captive portal should be active.

Implements sensesp::NetworkProvisioner.

Definition at line 215 of file wifi_provisioner.h.

◆ local_ip()

IPAddress sensesp::WiFiProvisioner::local_ip ( ) const
inlineoverridevirtual

Current local IPv4 address. Returns IPAddress() if no link.

Implements sensesp::NetworkProvisioner.

Definition at line 212 of file wifi_provisioner.h.

◆ mac_address()

String sensesp::WiFiProvisioner::mac_address ( ) const
inlineoverridevirtual

Hardware MAC address of the active interface.

Format: "AA:BB:CC:DD:EE:FF". For multi-interface chips this returns the MAC of the interface SensESPApp is using to reach the network (e.g. the WiFi STA MAC, or the EMAC MAC).

Implements sensesp::NetworkProvisioner.

Definition at line 214 of file wifi_provisioner.h.

◆ reset()

void sensesp::WiFiProvisioner::reset ( )
overridevirtual

Reimplemented from sensesp::Resettable.

Definition at line 333 of file wifi_provisioner.cpp.

Here is the call graph for this function:

◆ rssi()

int sensesp::WiFiProvisioner::rssi ( ) const
inline

Definition at line 234 of file wifi_provisioner.h.

◆ soft_ap_ip()

IPAddress sensesp::WiFiProvisioner::soft_ap_ip ( ) const
inline

Definition at line 229 of file wifi_provisioner.h.

◆ ssid()

String sensesp::WiFiProvisioner::ssid ( ) const
inline

Definition at line 233 of file wifi_provisioner.h.

Here is the caller graph for this function:

◆ start_access_point()

void sensesp::WiFiProvisioner::start_access_point ( )
protected

Definition at line 153 of file wifi_provisioner.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ start_client_autoconnect()

void sensesp::WiFiProvisioner::start_client_autoconnect ( )
protected

Definition at line 170 of file wifi_provisioner.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ start_wifi_scan()

void sensesp::WiFiProvisioner::start_wifi_scan ( )

Definition at line 343 of file wifi_provisioner.cpp.

◆ to_json()

bool sensesp::WiFiProvisioner::to_json ( JsonObject &  root)
overridevirtual

Serializes the current object data into a JsonObject.

Reimplemented from sensesp::Serializable.

Definition at line 264 of file wifi_provisioner.cpp.

Here is the call graph for this function:

Member Data Documentation

◆ ap_settings_

AccessPointSettings sensesp::WiFiProvisioner::ap_settings_
protected

Definition at line 251 of file wifi_provisioner.h.

◆ client_enabled_

bool sensesp::WiFiProvisioner::client_enabled_ = false
protected

Definition at line 253 of file wifi_provisioner.h.

◆ client_settings_

std::vector<ClientSSIDConfig> sensesp::WiFiProvisioner::client_settings_
protected

Definition at line 254 of file wifi_provisioner.h.

◆ dns_server_

std::unique_ptr<DNSServer> sensesp::WiFiProvisioner::dns_server_
protected

Definition at line 256 of file wifi_provisioner.h.


The documentation for this class was generated from the following files: