WiFi driver. More...
#include <WiFi.h>
Public Member Functions | |
WiFi () | |
Creates and uses a default event handler. | |
~WiFi () | |
Deletes the event handler that was used by the class. | |
void | addDNSServer (const std::string &ip) |
Add a reference to a DNS server. More... | |
void | addDNSServer (const char *ip) |
void | addDNSServer (ip_addr_t ip) |
void | setDNSServer (int numdns, const std::string &ip) |
Set a reference to a DNS server. More... | |
void | setDNSServer (int numdns, const char *ip) |
void | setDNSServer (int numdns, ip_addr_t ip) |
struct in_addr | getHostByName (const std::string &hostName) |
Lookup an IP address by host name. More... | |
struct in_addr | getHostByName (const char *hostName) |
uint8_t | connectAP (const std::string &ssid, const std::string &password, bool waitForConnection=true, wifi_mode_t mode=WIFI_MODE_STA) |
Connect to an external access point. More... | |
void | dump () |
Dump diagnostics to the log. | |
bool | isConnectedToAP () |
Returns whether wifi is connected to an access point. | |
std::vector< WiFiAPRecord > | scan () |
Perform a WiFi scan looking for access points. More... | |
void | startAP (const std::string &ssid, const std::string &passwd, wifi_auth_mode_t auth=WIFI_AUTH_OPEN) |
Start being an access point. More... | |
void | startAP (const std::string &ssid, const std::string &passwd, wifi_auth_mode_t auth, uint8_t channel, bool ssid_hidden, uint8_t max_connection) |
Start being an access point. More... | |
void | setIPInfo (const std::string &ip, const std::string &gw, const std::string &netmask) |
Set the IP info and enable DHCP if ip != 0. If called with ip == 0 then DHCP is enabled. If called with bad values it will do nothing. More... | |
void | setIPInfo (const char *ip, const char *gw, const char *netmask) |
void | setIPInfo (uint32_t ip, uint32_t gw, uint32_t netmask) |
Set the IP Info based on the IP address, gateway and netmask. More... | |
void | setWifiEventHandler (WiFiEventHandler *wifiEventHandler) |
Set the event handler to use to process detected events. More... | |
Static Public Member Functions | |
static std::string | getApMac () |
Get the MAC address of the AP interface. More... | |
static tcpip_adapter_ip_info_t | getApIpInfo () |
Get the AP IP Info. More... | |
static std::string | getApSSID () |
Get the AP SSID. More... | |
static std::string | getApIp () |
Get the current ESP32 IP form AP. More... | |
static std::string | getApNetmask () |
Get the current AP netmask. More... | |
static std::string | getApGateway () |
Get the current AP Gateway IP. More... | |
static std::string | getMode () |
Get the WiFi Mode. More... | |
static tcpip_adapter_ip_info_t | getStaIpInfo () |
Get the STA IP Info. More... | |
static std::string | getStaMac () |
Get the MAC address of the STA interface. More... | |
static std::string | getStaSSID () |
Get the STA SSID. More... | |
static std::string | getStaIp () |
Get the current ESP32 IP form STA. More... | |
static std::string | getStaNetmask () |
Get the current STA netmask. More... | |
static std::string | getStaGateway () |
Get the current STA Gateway IP. More... | |
WiFi driver.
Encapsulate control of WiFi functions.
Here is an example fragment that illustrates connecting to an access point.
void WiFi::addDNSServer | ( | const std::string & | ip | ) |
Add a reference to a DNS server.
Here we define a server that will act as a DNS server. We can add two DNS servers in total. The first will be the primary, the second will be the backup. The public Google DNS servers are "8.8.8.8" and "8.8.4.4".
For example:
[in] | ip | The IP address of the DNS Server. |
uint8_t WiFi::connectAP | ( | const std::string & | ssid, |
const std::string & | password, | ||
bool | waitForConnection = true , |
||
wifi_mode_t | mode = WIFI_MODE_STA |
||
) |
Connect to an external access point.
The event handler will be called back with the outcome of the connection.
[in] | ssid | The network SSID of the access point to which we wish to connect. |
[in] | password | The password of the access point to which we wish to connect. |
[in] | waitForConnection | Block until the connection has an outcome. |
[in] | mode | WIFI_MODE_AP for normal or WIFI_MODE_APSTA if you want to keep an Access Point running while you connect |
|
static |
Get the current AP Gateway IP.
|
static |
Get the current ESP32 IP form AP.
|
static |
Get the AP IP Info.
|
static |
Get the MAC address of the AP interface.
|
static |
Get the current AP netmask.
|
static |
Get the AP SSID.
struct in_addr WiFi::getHostByName | ( | const std::string & | hostName | ) |
Lookup an IP address by host name.
[in] | hostName | The hostname to resolve. |
|
static |
Get the current STA Gateway IP.
|
static |
Get the current ESP32 IP form STA.
|
static |
Get the STA IP Info.
|
static |
Get the MAC address of the STA interface.
|
static |
Get the current STA netmask.
|
static |
Get the STA SSID.
std::vector< WiFiAPRecord > WiFi::scan | ( | ) |
Perform a WiFi scan looking for access points.
An access point scan is performed and a vector of WiFi access point records is built and returned with one record per found scan instance. The scan is performed in a blocking fashion and will not return until the set of scanned access points has been built.
void WiFi::setDNSServer | ( | int | numdns, |
const std::string & | ip | ||
) |
Set a reference to a DNS server.
Here we define a server that will act as a DNS server. We use numdns to specify which DNS server to set
For example:
[in] | numdns | The DNS number we wish to set |
[in] | ip | The IP address of the DNS Server. |
void WiFi::setIPInfo | ( | const std::string & | ip, |
const std::string & | gw, | ||
const std::string & | netmask | ||
) |
Set the IP info and enable DHCP if ip != 0. If called with ip == 0 then DHCP is enabled. If called with bad values it will do nothing.
Do not call this method if we are being an access point ourselves.
For example, prior to calling connectAP()
we could invoke:
[in] | ip | IP address value. |
[in] | gw | Gateway value. |
[in] | netmask | Netmask value. |
void WiFi::setIPInfo | ( | uint32_t | ip, |
uint32_t | gw, | ||
uint32_t | netmask | ||
) |
Set the IP Info based on the IP address, gateway and netmask.
[in] | ip | The IP address of our ESP32. |
[in] | gw | The gateway we should use. |
[in] | netmask | Our TCP/IP netmask value. |
void WiFi::setWifiEventHandler | ( | WiFiEventHandler * | wifiEventHandler | ) |
Set the event handler to use to process detected events.
[in] | wifiEventHandler | The class that will be used to process events. |
void WiFi::startAP | ( | const std::string & | ssid, |
const std::string & | password, | ||
wifi_auth_mode_t | auth = WIFI_AUTH_OPEN |
||
) |
Start being an access point.
[in] | ssid | The SSID to use to advertize for stations. |
[in] | password | The password to use for station connections. |
[in] | auth | The authorization mode for access to this access point. Options are:
|
void WiFi::startAP | ( | const std::string & | ssid, |
const std::string & | password, | ||
wifi_auth_mode_t | auth, | ||
uint8_t | channel, | ||
bool | ssid_hidden, | ||
uint8_t | max_connection | ||
) |
Start being an access point.
[in] | ssid | The SSID to use to advertize for stations. |
[in] | password | The password to use for station connections. |
[in] | auth | The authorization mode for access to this access point. Options are:
|
[in] | channel | from the access point. |
[in] | is | the ssid hidden, ore not. |
[in] | limiting | number of clients. |