44 explicit TinyWifiDongleSetup(
const char* setupNetwork =
"TinyWifiDongle-Setup",
const char* setupPassword =
nullptr)
45 : portal_(setupNetwork, setupPassword) {}
55 bool known = store_.load();
57 TWD_LOGGER.info(
"setup: button pressed, forgetting the saved network");
58 if (!store_.forget())
TWD_LOGGER.error(
"setup: could not write the flash");
65 TWD_LOGGER.error(
"setup: could not write the flash, the network is only used until the next start");
68 startedAt_ = millis();
72 const char*
ssid()
const {
return store_.ssid(); }
75 const char*
password()
const {
return store_.password(); }
84 }
else if (!connected_ && joinTimeoutMs_ && millis() - startedAt_ > joinTimeoutMs_) {
85 TWD_LOGGER.warning(
"setup: could not join '%s' within %u ms, forgetting it and restarting",
ssid(),
86 (
unsigned)joinTimeoutMs_);
87 if (!store_.forget())
TWD_LOGGER.error(
"setup: could not write the flash");
96 uint32_t forgetWindowMs_ = 3000;
97 uint32_t joinTimeoutMs_ = 60000;
98 uint32_t startedAt_ = 0;
99 bool connected_ =
false;
Printf-style logging through the global TWD_LOGGER object.
static twd::LoggerClass TWD_LOGGER
The logger used by all components; configure it in the sketch with TWD_LOGGER.begin(Serial).
TinyWifiDongleSetup(const char *setupNetwork="TinyWifiDongle-Setup", const char *setupPassword=nullptr)
The setup network is called setupNetwork; setupPassword (at least 8 characters) protects it,...
void forget()
Removes the saved network; the next start opens the setup.
void setJoinTimeout(uint32_t ms)
How long a start may take to join the network before the saved network is forgotten and the setup ope...
void setForgetWindow(uint32_t ms)
How long, after a start, the BOOT button (ESP32) or BOOTSEL button (Pico) forgets the saved network; ...
void update(bool connected)
Call regularly with TinyWifiDongle::isWifiConnected(). If the board has not joined the network within...
void begin()
Loads the saved network, or opens the setup and blocks until the user has entered one.
const char * ssid() const
Name of the network to join; valid after begin().
const char * password() const
Password of the network to join, nullptr for an open network; valid after begin().
static bool buttonPressedWithin(uint32_t ms)
True if the BOOT button (ESP32) or the BOOTSEL button (Raspberry Pi Pico) is pressed at any time duri...
static void restart()
Restarts the board.
Keeps the name and password of one WiFi network in flash.
Captive portal in which the user picks a WiFi network and enters its password.