1#ifndef SENSESP_NET_NETWORKING_H_
2#define SENSESP_NET_NETWORKING_H_
53 [
this](WiFiEvent_t event, WiFiEventInfo_t info) {
56 WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_GOT_IP);
58 WiFi.onEvent([
this](WiFiEvent_t event,
60 WiFiEvent_t::ARDUINO_EVENT_WIFI_AP_START);
62 [
this](WiFiEvent_t event, WiFiEventInfo_t info) {
65 WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_DISCONNECTED);
67 [
this](WiFiEvent_t event, WiFiEventInfo_t info) {
70 WiFiEvent_t::ARDUINO_EVENT_WIFI_AP_STOP);
81 ESP_LOGI(__FILENAME__,
"Connected to wifi, SSID: %s (signal: %d)",
82 WiFi.SSID().c_str(), WiFi.RSSI());
83 ESP_LOGI(__FILENAME__,
"IP address of Device: %s",
84 WiFi.localIP().toString().c_str());
85 ESP_LOGI(__FILENAME__,
"Default route: %s",
86 WiFi.gatewayIP().toString().c_str());
87 ESP_LOGI(__FILENAME__,
"DNS server: %s", WiFi.dnsIP().toString().c_str());
92 ESP_LOGI(__FILENAME__,
"WiFi Access Point enabled, SSID: %s",
93 WiFi.softAPSSID().c_str());
94 ESP_LOGI(__FILENAME__,
"IP address of Device: %s",
95 WiFi.softAPIP().toString().c_str());
105 ESP_LOGI(__FILENAME__,
"Disconnected from wifi.");
117 String password =
"",
int channel = 9,
118 bool hidden =
false,
bool captive_portal_enabled =
true)
140 settings.
enabled_ = json[
"enabled"] |
false;
141 settings.
ssid_ = json[
"name"] |
"";
142 settings.
password_ = json[
"password"] |
"";
143 settings.
channel_ = json[
"channel"] | 1;
144 settings.
hidden_ = json[
"hidden"] |
false;
166 IPAddress ip = IPAddress(169, 254, 0, 1),
167 IPAddress netmask = IPAddress(255, 255, 255, 0),
168 IPAddress gateway = IPAddress(192, 168, 0, 1),
169 IPAddress dns_server = IPAddress(8, 8, 8, 8))
188 config.
ssid_ = json[
"name"] |
"";
189 config.
password_ = json[
"password"] |
"";
190 config.
use_dhcp_ = json[
"useDHCP"] |
true;
191 config.
ip_.fromString(json[
"ipAddress"] |
"169.254.0.1");
192 config.
netmask_.fromString(json[
"netmask"] |
"255.255.255.0");
193 config.
gateway_.fromString(json[
"gateway"] |
"192.168.0.1");
194 config.
dns_server_.fromString(json[
"dnsServer"] |
"8.8.8.8");
202 doc[
"ipAddress"] =
ip_.toString();
203 doc[
"netmask"] =
netmask_.toString();
204 doc[
"gateway"] =
gateway_.toString();
235 doc[
"bssid"] = String(
bssid_[0], HEX) +
":" + String(
bssid_[1], HEX) +
":" +
236 String(
bssid_[2], HEX) +
":" + String(
bssid_[3], HEX) +
":" +
248 Networking(
const String& config_path,
const String& client_ssid =
"",
249 const String& client_password =
"",
const String& ap_ssid =
"",
250 const String& ap_password =
"");
253 virtual void reset()
override;
255 virtual bool to_json(JsonObject& doc)
override;
256 virtual bool from_json(
const JsonObject& config)
override;
281 std::make_shared<WiFiStateProducer>();
Storage object for WiFi access point settings.
static AccessPointSettings from_json(const JsonObject &json)
AccessPointSettings(bool enabled=true, String ssid="", String password="", int channel=9, bool hidden=false, bool captive_portal_enabled=true)
void as_json(JsonObject &doc)
bool captive_portal_enabled_
Storage object for WiFi client settings.
static ClientSSIDConfig from_json(const JsonObject &json)
void as_json(JsonObject &doc)
ClientSSIDConfig(String ssid="", String password="", bool use_dhcp=true, IPAddress ip=IPAddress(169, 254, 0, 1), IPAddress netmask=IPAddress(255, 255, 255, 0), IPAddress gateway=IPAddress(192, 168, 0, 1), IPAddress dns_server=IPAddress(8, 8, 8, 8))
Manages the ESP's connection to the Wifi network.
virtual void reset() override
std::unique_ptr< DNSServer > dns_server_
void start_client_autoconnect()
Start WiFi using preset SSID and password.
virtual bool from_json(const JsonObject &config) override
void start_access_point()
Start an access point.
int16_t get_wifi_scan_results(std::vector< WiFiNetworkInfo > &ssid_list)
Networking(const String &config_path, const String &client_ssid="", const String &client_password="", const String &ap_ssid="", const String &ap_password="")
const std::shared_ptr< WiFiStateProducer > & get_wifi_state_producer()
virtual bool to_json(JsonObject &doc) override
Serialize the current configuration to a JSON document.
std::shared_ptr< LambdaConsumer< WiFiState > > wifi_state_emitter_
std::vector< ClientSSIDConfig > client_settings_
AccessPointSettings ap_settings_
bool is_captive_portal_enabled()
std::shared_ptr< WiFiStateProducer > wifi_state_producer_
Automatic calling of the reset() method when the device needs to be reset.
static String get_hostname()
Get the current hostname.
A base class for any sensor or piece of code that outputs a value for consumption elsewhere.
void emit(const WiFiState &new_value)
WiFi Network Information storage class.
WiFiNetworkInfo(String ssid, int32_t rssi, uint8_t encryption, uint8_t *bssid, int32_t channel)
void as_json(JsonObject &doc)
Provide information about the current WiFi state.
void setup_wifi_callbacks()
wifi_event_id_t wifi_sta_got_ip_event_id_
void wifi_station_connected()
wifi_event_id_t wifi_ap_start_event_id_
void operator=(const WiFiStateProducer &)=delete
wifi_event_id_t wifi_sta_disconnected_event_id_
wifi_event_id_t wifi_ap_stop_event_id_
void remove_wifi_callbacks()
WiFiStateProducer(WiFiStateProducer &other)=delete
const String ConfigSchema(const SmartSwitchController &obj)
std::shared_ptr< reactesp::EventLoop > event_loop()
constexpr int kMaxNumClientConfigs
bool ConfigRequiresRestart(const HTTPServer &obj)