RBE1001Lib
Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes
WifiManager Class Reference

#include <WifiManager.h>

Collaboration diagram for WifiManager:
Collaboration graph
[legend]

Public Member Functions

 WifiManager ()
 
virtual ~WifiManager ()
 
void loop ()
 
void setup ()
 
void setupAP ()
 
void setupScan ()
 
void printState ()
 
enum connectionState getState ()
 
void WiFiEvent (WiFiEvent_t event)
 
bool isApMode ()
 
void erase ()
 
void disconnect ()
 
int updateApList ()
 

Static Public Attributes

static WifiManagerstaticRef = NULL
 

Private Member Functions

void connectToWiFi (const char *ssid, const char *pwd)
 
void startAP ()
 
void rescan ()
 
void runSerialLoop ()
 
void setPassword (String ssid, String pass)
 
String getPassword (String ssid, String defaultPass="none")
 
String getPasswordKey (String ssid)
 

Private Attributes

bool APMode =false
 
long timeOfLastDisconnect = 0
 
long timeOfLastConnect = 0
 
String networkNameServer
 
String networkPswdServer
 
String apNameServer
 
String apPswdServer
 
int connectionAttempts =0
 
Preferences preferences
 
long timeSinceAPPrint =0
 
long timeSinceAPStart =0
 
enum connectionState state =firstStart
 
enum connectionState whatToDoAfterScanning =reconnect
 
bool setupDone = false
 

Detailed Description

Definition at line 30 of file WifiManager.h.

Constructor & Destructor Documentation

◆ WifiManager()

WifiManager::WifiManager ( )

WifiManager is a class to manage the WIFI connections and reconnections THis manager will also take over the Serial object and use it to set connection To connect to an AP, type the AP into the arduino serial moniter and hit enter When the password prompt comes up, type the password and and hit enter. if the password is correct, the AP will be stored for a fast connect next time.

To change the AP name, use ap:MyNewAPName instead of the ap to which you want to connect the password will be stored as the AP name

Definition at line 17 of file WifiManager.cpp.

◆ ~WifiManager()

WifiManager::~WifiManager ( )
virtual

Definition at line 20 of file WifiManager.cpp.

Member Function Documentation

◆ connectToWiFi()

void WifiManager::connectToWiFi ( const char *  ssid,
const char *  pwd 
)
private

Definition at line 124 of file WifiManager.cpp.

References Disconnected, rescanIncrement, state, timeOfLastConnect, and timeOfLastDisconnect.

Referenced by loop().

◆ disconnect()

void WifiManager::disconnect ( )

disconnect Force a disconnection and rescan of the system

Definition at line 394 of file WifiManager.cpp.

References APMode, connectionAttempts, Disconnected, networkNameServer, printState(), rescanIncrement, state, timeOfLastConnect, timeOfLastDisconnect, and timeoutTime.

Referenced by loop(), runSerialLoop(), setupScan(), and WiFiEvent().

Here is the call graph for this function:

◆ erase()

void WifiManager::erase ( )

erase() Erase all stored passwords and AP mode settings

Definition at line 531 of file WifiManager.cpp.

References preferences.

Referenced by runSerialLoop().

◆ getPassword()

String WifiManager::getPassword ( String  ssid,
String  defaultPass = "none" 
)
private

Definition at line 286 of file WifiManager.cpp.

References getPasswordKey(), and preferences.

Referenced by loop(), rescan(), setup(), and startAP().

Here is the call graph for this function:

◆ getPasswordKey()

String WifiManager::getPasswordKey ( String  ssid)
private

Definition at line 277 of file WifiManager.cpp.

References PASS_LEN_KEY.

Referenced by getPassword(), and setPassword().

◆ getState()

enum connectionState WifiManager::getState ( )

Get the state of the wifi manager

Definition at line 23 of file WifiManager.cpp.

References state.

Referenced by loop(), and setup().

◆ isApMode()

bool WifiManager::isApMode ( )

Check to see if the device is already in AP mode.

Definition at line 523 of file WifiManager.cpp.

References APMode.

◆ loop()

void WifiManager::loop ( )

◆ printState()

void WifiManager::printState ( )

A formated print statement of the current state

Definition at line 26 of file WifiManager.cpp.

References APWaitingForSTA, Connected, Disconnected, firstStart, HaveSSIDSerial, InitialConnect, reconnect, and state.

Referenced by disconnect(), loop(), and WiFiEvent().

◆ rescan()

void WifiManager::rescan ( )
private

Definition at line 164 of file WifiManager.cpp.

References APMode, getPassword(), networkNameServer, networkPswdServer, preferences, reconnect, and state.

Referenced by loop().

Here is the call graph for this function:

◆ runSerialLoop()

void WifiManager::runSerialLoop ( )
private

Definition at line 234 of file WifiManager.cpp.

References APMode, apNameServer, disconnect(), erase(), HaveSSIDSerial, networkNameServer, reconnect, and state.

Referenced by loop().

Here is the call graph for this function:

◆ setPassword()

void WifiManager::setPassword ( String  ssid,
String  pass 
)
private

Definition at line 283 of file WifiManager.cpp.

References getPasswordKey(), and preferences.

Referenced by loop(), and startAP().

Here is the call graph for this function:

◆ setup()

void WifiManager::setup ( )

Perfoem a normal setup This will attempt to connect to a stored network. If the stored network is not found, it will re-scan and connect to a remembered network, if no remembered network is found, it will start AP mode

Definition at line 68 of file WifiManager.cpp.

References apNameServer, apPswdServer, connectionAttempts, getPassword(), networkNameServer, networkPswdServer, preferences, reconnect, setupDone, state, staticRef, and WiFiEventWifiManager().

Referenced by setup(), setupAP(), and setupScan().

Here is the call graph for this function:

◆ setupAP()

void WifiManager::setupAP ( )

Start the manager with AP mode started by default

Definition at line 53 of file WifiManager.cpp.

References APMode, reconnect, setup(), and state.

Referenced by setup().

Here is the call graph for this function:

◆ setupScan()

void WifiManager::setupScan ( )

Start the manager but re-scan the environment first

Definition at line 64 of file WifiManager.cpp.

References disconnect(), and setup().

Referenced by setup().

Here is the call graph for this function:

◆ startAP()

void WifiManager::startAP ( )
private

Definition at line 95 of file WifiManager.cpp.

References apNameServer, apPswdServer, getPassword(), preferences, rescanIncrement, setPassword(), timeOfLastConnect, timeOfLastDisconnect, and timeSinceAPStart.

Referenced by loop().

Here is the call graph for this function:

◆ updateApList()

int WifiManager::updateApList ( )

Update AP list

This function will update the AP list, then reconnect

Returns
the current number of availible AP's this will take a few seconds and is BLOCKING during that time

Definition at line 151 of file WifiManager.cpp.

References reconnect, scanRunning, state, and whatToDoAfterScanning.

Referenced by loop().

◆ WiFiEvent()

void WifiManager::WiFiEvent ( WiFiEvent_t  event)

Internal function to process wifi events This is only public to allow the static wifi event to call it

< ESP32 station got IP from connected AP

< ESP32 station disconnected from AP

< ESP32 WiFi ready

< ESP32 finish scanning AP

< ESP32 station start

< ESP32 station stop

< ESP32 station connected to AP

< the auth mode of AP connected by ESP32 station changed

< ESP32 station lost IP and the IP is reset to 0

< ESP32 station wps succeeds in enrollee mode

< ESP32 station wps fails in enrollee mode

< ESP32 station wps timeout in enrollee mode

< ESP32 station wps pin code in enrollee mode

< ESP32 soft-AP start

< ESP32 soft-AP stop

< a station connected to ESP32 soft-AP

< a station disconnected from ESP32 soft-AP

< Receive probe request packet in soft-AP interface

< ESP32 station or ap interface v6IP addr is preferred

< ESP32 ethernet start

< ESP32 ethernet stop

< ESP32 ethernet phy link up

< ESP32 ethernet phy link down

< ESP32 ethernet got IP from connected AP

Definition at line 406 of file WifiManager.cpp.

References apconnected, APMode, APWaitingForSTA, Connected, connectionAttempts, disconnect(), Disconnected, HaveSSIDSerial, InitialConnect, printState(), rescanIncrement, state, timeOfLastConnect, and timeOfLastDisconnect.

Referenced by WiFiEventWifiManager().

Here is the call graph for this function:

Field Documentation

◆ APMode

bool WifiManager::APMode =false
private

Definition at line 34 of file WifiManager.h.

Referenced by disconnect(), isApMode(), loop(), rescan(), runSerialLoop(), setupAP(), and WiFiEvent().

◆ apNameServer

String WifiManager::apNameServer
private

Definition at line 40 of file WifiManager.h.

Referenced by runSerialLoop(), setup(), and startAP().

◆ apPswdServer

String WifiManager::apPswdServer
private

Definition at line 41 of file WifiManager.h.

Referenced by loop(), setup(), and startAP().

◆ connectionAttempts

int WifiManager::connectionAttempts =0
private

Definition at line 42 of file WifiManager.h.

Referenced by disconnect(), loop(), setup(), and WiFiEvent().

◆ networkNameServer

String WifiManager::networkNameServer
private

Definition at line 38 of file WifiManager.h.

Referenced by disconnect(), loop(), rescan(), runSerialLoop(), and setup().

◆ networkPswdServer

String WifiManager::networkPswdServer
private

Definition at line 39 of file WifiManager.h.

Referenced by loop(), rescan(), and setup().

◆ preferences

Preferences WifiManager::preferences
private

Definition at line 43 of file WifiManager.h.

Referenced by erase(), getPassword(), loop(), rescan(), setPassword(), setup(), and startAP().

◆ setupDone

bool WifiManager::setupDone = false
private

Definition at line 49 of file WifiManager.h.

Referenced by setup().

◆ state

enum connectionState WifiManager::state =firstStart
private

◆ staticRef

WifiManager * WifiManager::staticRef = NULL
static

Static reference used by the wifi event to pass the event from the static context to the object context.

Definition at line 58 of file WifiManager.h.

Referenced by setup().

◆ timeOfLastConnect

long WifiManager::timeOfLastConnect = 0
private

Definition at line 37 of file WifiManager.h.

Referenced by connectToWiFi(), disconnect(), loop(), startAP(), and WiFiEvent().

◆ timeOfLastDisconnect

long WifiManager::timeOfLastDisconnect = 0
private

Definition at line 36 of file WifiManager.h.

Referenced by connectToWiFi(), disconnect(), loop(), startAP(), and WiFiEvent().

◆ timeSinceAPPrint

long WifiManager::timeSinceAPPrint =0
private

Definition at line 45 of file WifiManager.h.

Referenced by loop().

◆ timeSinceAPStart

long WifiManager::timeSinceAPStart =0
private

Definition at line 46 of file WifiManager.h.

Referenced by loop(), and startAP().

◆ whatToDoAfterScanning

enum connectionState WifiManager::whatToDoAfterScanning =reconnect
private

Definition at line 48 of file WifiManager.h.

Referenced by loop(), and updateApList().


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