13#ifndef WIFI_CONFIG_PORTAL_TIMEOUT
14#define WIFI_CONFIG_PORTAL_TIMEOUT 180
43 if (default_hostname != preset_hostname) {
46 default_hostname = preset_hostname;
49 if (ap_ssid ==
"" && preset_ssid !=
"") {
51 ap_ssid = preset_ssid;
54 if (ap_password ==
"" && preset_password !=
"") {
56 ap_password = preset_password;
64 debugD(
"Enabling Networking object");
70 if (ap_ssid !=
"" && ap_password !=
"") {
71 debugI(
"Using SSID %s", ap_ssid.c_str());
74 wifi_manager_enabled_) {
75 debugI(
"Starting WiFiManager");
82 debugD(
"Activating WiFiManager");
95 if (ap_mode_ ==
false) {
99 debugI(
"Connecting to wifi SSID %s.", ap_ssid.c_str());
100 WiFi.begin(ap_ssid.c_str(), ap_password.c_str());
113 debugI(
"Setting up a WiFi access point...");
114 WiFi.softAP(ap_ssid.c_str(), ap_password.c_str());
131 wifi_manager->setBreakAfterConfig(
true);
135#ifdef SERIAL_DEBUG_DISABLED
136 wifi_manager->setDebugOutput(
false);
143 "ap_ssid",
"Custom Access Point SSID", ap_ssid.c_str(), 33);
147 "ap_password",
"Custom Access Point Password", ap_password.c_str(), 64);
150 wifi_manager->setTryConnectDuringConfigPortal(
false);
154 if (wifi_manager_ap_ssid_ !=
"") {
166 wifi_manager->startConfigPortal(
pconfig_ssid, wifi_manager_password_);
185 this->ap_ssid = wifi_manager->getConfiguredSTASSID();
186 this->ap_password = wifi_manager->getConfiguredSTAPassword();
189 if (this->ap_ssid !=
"" && this->ap_password !=
"") {
190 debugD(
"Attempting to connect to acquired SSID %s and password",
191 this->ap_ssid.c_str());
192 WiFi.begin(this->ap_ssid.c_str(),
this->ap_password.c_str());
193 for (
int i = 0;
i < 20;
i++) {
209 debugI(
"Got new SSID and password: %s", ap_ssid.c_str());
217 static const char kSchema[] = R
"###({
220 "hostname": { "title": "Device hostname", "type": "string" },
221 "ssid": { "title": "WiFi SSID", "type": "string" },
222 "password": { "title": "WiFi password", "type": "string", "format": "password" },
223 "ap_mode": { "type": "string", "format": "radio", "title": "WiFi mode", "enum": ["Client", "Access Point"] }
235 root[
"default_hostname"] = default_hostname;
236 root[
"ssid"] = ap_ssid;
237 root[
"password"] = ap_password;
238 root[
"ap_mode"] = ap_mode_ ?
"Access Point" :
"Client";
242 if (!
config.containsKey(
"hostname")) {
249 if (
config.containsKey(
"default_hostname")) {
250 default_hostname =
config[
"default_hostname"].as<
String>();
255 if (
config.containsKey(
"ap_mode")) {
268 debugI(
"Resetting WiFi SSID settings");
270 ap_ssid = preset_ssid;
271 ap_password = preset_password;
274 WiFi.disconnect(
true);
277 WiFi.begin(
"0",
"0");
An object that is capable of having configuration data that can be set remotely using a RESTful API,...
virtual void save_configuration()
virtual void load_configuration()
virtual void reset() override
virtual void get_configuration(JsonObject &doc) override final
void activate_wifi_manager()
void setup_wifi_manager()
Start WiFi using WiFi Manager.
virtual String get_config_schema() override
void setup_saved_ssid()
Start WiFi using preset SSID and password.
virtual bool set_configuration(const JsonObject &config) override final
virtual void start() override
Networking(String config_path, String ssid, String password, String hostname, const char *wifi_manager_password)
Automatic calling of the reset() method when the device needs to be reset.
static SensESPBaseApp * get()
Get the singleton instance of the SensESPBaseApp.
static String get_hostname()
Get the current hostname.
Automatic calling of the start() method at startup.
void connect_to(ValueConsumer< T > *consumer, uint8_t input_channel=0)
void emit(WiFiState new_value)
Provide information about the current WiFi state.
static WiFiStateProducer * instance_
static WiFiStateProducer * get_singleton()
Get the singleton instance of the WiFiStateProducer.
#define WIFI_CONFIG_PORTAL_TIMEOUT