Please load the library #include <WiFi.h>
before use.
Description:
Enable AP mode, returns true if successful.
Function Prototype:
bool softAP(const char* ssid, const char* passphrase = NULL, int channel = 1, int ssid_hidden = 0, int max_connection = 4)
Parameter | Description | Type |
---|---|---|
ssid | AP name (0~32 bytes) | const char* |
passphrase | Password (8~63 bytes) or NULL | const char* |
channel | Channel | int |
ssid_hidden | Whether to hide SSID (1: hidden, 0: not hidden) | int |
max_connection | Maximum number of connections (1~4) | int |
Usage Example:
#include <M5Stack.h>
#include <WIFI.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.setTextSize(2);
}
void loop() {
if (WiFi.softAP("M5Stack_AP", "12345678", 1, 0, 4)) {
M5.Lcd.println("WiFi AP is set up");
M5.Lcd.println(WiFi.softAPIP());
} else {
M5.Lcd.println("WiFi AP is down");
}
delay(1000);
}
Description:
Set the IP address of the AP.
Function Prototype:
bool softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress subnet)
Parameter | Description | Type |
---|---|---|
local_ip | Default local IP (192.168.4.1) | IPAddress |
gateway | Default gateway (192.168.4.1) | IPAddress |
subnet | Default subnet mask (255.255.255.0) | IPAddress |
Usage Example:
#include <M5Stack.h>
#include <WIFI.h>
IPAddress local_IP(192, 168, 4,22); // Manually set the IP address of the open network.
IPAddress gateway(192, 168, 4,9); // Manually set gateway IP address.
IPAddress subnet(255, 255, 255,0); // Manually set subnet mask.
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.setTextSize(2);
}
void loop() {
if (WiFi.softAP("M5Stack_AP", "12345678", 1, 0, 4)) {
M5.Lcd.println("WiFi AP is set up");
M5.Lcd.println(WiFi.softAPIP());
delay(300);
WiFi.softAPConfig(local_IP, gateway, subnet);
} else {
M5.Lcd.println("WiFi AP is down");
}
delay(1000);
}
Description:
Close the current AP, if wifioff is true, restore network settings.
Function Prototype:
bool softAPdisconnect(bool wifioff = false)
Parameter | Description | Type |
---|---|---|
wifioff | Restore settings | bool |
Usage Example:
#include <M5Stack.h>
#include <WIFI.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.setTextSize(2);
}
void loop() {
if (WiFi.softAP("M5Stack_AP", "12345678", 1, 0, 4)) {
M5.Lcd.println("WiFi AP is set up");
M5.Lcd.println(WiFi.softAPIP());
delay(1000);
if (WiFi.softAPdisconnect()) {
M5.Lcd.println("WiFi AP is closed");
delay(5000);
}
} else {
M5.Lcd.println("WiFi AP is down");
}
delay(1000);
}
Description:
Returns the number of clients connected to the AP.
Function Prototype:
uint8_t softAPgetStationNum()
Usage Example:
#include <M5Stack.h>
#include <WIFI.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.setTextSize(2);
}
void loop() {
if (WiFi.softAP("M5Stack_AP", "12345678", 1, 0, 4)) {
M5.Lcd.println("WiFi AP is set up");
M5.Lcd.printf("Number of AP connections:%d",WiFi.softAPgetStationNum());
} else {
M5.Lcd.println("WiFi AP is down");
}
delay(1000);
}
Description:
Returns the IP address of the current AP.
Function Prototype:
IPAddress softAPIP()
Usage Example:
#include <M5Stack.h>
#include <WIFI.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.setTextSize(2);
}
void loop() {
if (WiFi.softAP("M5Stack_AP", "12345678", 1, 0, 4)) {
M5.Lcd.println("WiFi AP is set up");
M5.Lcd.println(WiFi.softAPIP());
} else {
M5.Lcd.println("WiFi AP is down");
}
delay(1000);
}
Description:
Set the hostname, returns true if successful.
Function Prototype:
bool softAPsetHostname(const char * hostname)
Parameter | Description | Type |
---|---|---|
hostname | Hostname | const char* |
Usage Example:
#include <M5Stack.h>
#include <WIFI.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.setTextSize(2);
}
void loop() {
if (WiFi.softAP("M5Stack_AP", "12345678", 1, 0, 4)) {
M5.Lcd.println("WiFi AP is set up");
M5.Lcd.printf("Host name:%s\n", WiFi.softAPgetHostname());
delay(1000);
WiFi.softAPsetHostname("M5_AP");
M5.Lcd.printf("After Host name:%s\n", WiFi.softAPgetHostname());
} else {
M5.Lcd.println("WiFi AP is down");
}
delay(1000);
}
Description:
Get the hostname.
Function Prototype:
const char * softAPgetHostname()
Usage Example:
#include <M5Stack.h>
#include <WIFI.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.setTextSize
(2);
}
void loop() {
if (WiFi.softAP("M5Stack_AP", "12345678", 1, 0, 4)) {
M5.Lcd.println("WiFi AP is set up");
M5.Lcd.printf("Host name:%s\n", WiFi.softAPgetHostname());
} else {
M5.Lcd.println("WiFi AP is down");
}
delay(1000);
}
Description:
Returns the MAC address of the host.
Function Prototype:
String softAPmacAddress(void)
Usage Example:
#include <M5Stack.h>
#include <WIFI.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.setTextSize(2);
}
void loop() {
if (WiFi.softAP("M5Stack_AP", "12345678", 1, 0, 4)) {
M5.Lcd.println("WiFi AP is set up");
M5.Lcd.print("MAC:");
M5.Lcd.println(WiFi.softAPmacAddress());
} else {
M5.Lcd.println("WiFi AP is down");
}
delay(1000);
}
Description:
Connects to the specified network (if the connect parameter is true) or just saves the settings if false, returning the WiFi status.
Function Prototype:
wl_status_t begin(const char* ssid, const char *passphrase = NULL, int32_t channel = 0, const uint8_t* bssid = NULL, bool connect = true)
Parameter | Description | Type |
---|---|---|
ssid | Network hotspot name | const char* |
passphrase | Password (optional) | const char* |
channel | Hotspot channel number (optional) | int32_t |
bssid | Hotspot MAC address (optional) | const uint8_t* |
connect | Establish connection (optional) | bool |
Usage Example:
#include <M5Stack.h>
#include <WIFI.h>
// Fill in the hotspot name and password you are connected to.
const char *ssid = "yourNetwork";
const char *password = "'secretPassword";
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.setTextSize(2);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
M5.Lcd.print(".");
}
M5.Lcd.println("\nWiFi connected");
}
void loop() {}
Description:
Configures network address.
Function Prototype:
bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = (uint32_t)0x00000000, IPAddress dns2 = (uint32_t)0x00000000)
Parameter | Description | Type |
---|---|---|
local_ip | Set IP address | IPAddress |
gateway | Set gateway | IPAddress |
subnet | Set subnet mask | IPAddress |
dns1 | Set DNS1 address | IPAddress |
dns2 | Set DNS2 address | IPAddress |
Description:
Disconnects from the network, optionally restoring settings and erasing saved AP settings from flash memory.
Function Prototype:
bool disconnect(bool wifioff = false, bool eraseap = false)
Parameter | Description | Type |
---|---|---|
wifioff | Restore settings | bool |
eraseap | Clear AP settings from flash memory | bool |
Usage Example:
#include <M5Stack.h>
#include <WIFI.h>
// Fill in the hotspot name and password you are connected to.
const char *ssid = "yourNetwork";
const char *password = "'secretPassword";
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.setTextSize(2);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
M5.Lcd.print(".");
}
M5.Lcd.println("\nWiFi connected");
if(WiFi.disconnect(true, true)) {
M5.Lcd.println("WiFi disconnected");
}
}
void loop() {}
Description:
Returns the network connection status.
Function Prototype:
bool isConnected()
Usage Example:
#include <M5Stack.h>
#include <WIFI.h>
// Fill in the hotspot name and password you are connected to.
const char *ssid = "yourNetwork";
const char *password = "'secretPassword";
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.setTextSize(2);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
M5.Lcd.print(".");
}
M5.Lcd.println("\nWiFi connected");
M5.Lcd.print(WiFi.isConnected());
}
void loop() {}
Description:
Sets automatic reconnection.
Function Prototype:
bool setAutoReconnect(bool autoReconnect)
Usage Example:
#include <M5Stack.h>
#include <WIFI.h>
// Fill in the hotspot name and password you are connected to.
const char *ssid = "yourNetwork";
const char *password = "'secretPassword";
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.setTextSize(2);
if(WiFi.setAutoReconnect(true)) {
M5.Lcd.println("Whether it has been set successfully to automatically reconnect");
}
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
M5.Lcd.print(".");
}
M5.Lcd.println("\nWiFi connected");
}
void loop() {}
Description:
Returns whether to reconnect automatically.
Function Prototype:
bool getAutoReconnect()
Description:
Returns the local IP address.
Function Prototype:
IPAddress localIP()
Usage Example:
#include <M5Stack.h>
#include <WIFI.h>
// Fill in the hotspot name and password you are connected to.
const char *ssid = "yourNetwork";
const char *password = "'secretPassword";
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.setTextSize(2);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
M5.Lcd.print(".");
}
M5.Lcd.println("\nWiFi connected");
M5.Lcd.print("IP:");
M5.Lcd.print(WiFi.localIP());
}
void loop() {}
Description:
Returns the subnet mask.
Function Prototype:
IPAddress subnetMask()
Usage Example:
#include <M5Stack.h>
#include <WIFI.h>
// Fill in the hotspot name and password you are connected to.
const char *ssid = "yourNetwork";
const char *password = "'secretPassword";
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.setTextSize(2);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
M5.Lcd.print(".");
}
M5.Lcd.println("\nWiFi connected");
M5.Lcd.print("subnetMask:");
M5.Lcd.print(WiFi.subnetMask());
}
void loop() {}
Description:
Returns the gateway address.
Function Prototype:
IPAddress gatewayIP()
Usage Example:
#include <M5Stack.h>
#include <WIFI.h>
// Fill in the hotspot name and password you are connected to.
const char *ssid = "yourNetwork";
const char *password = "'secretPassword";
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.setTextSize(2);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
M5.Lcd.print(".");
}
M5.Lcd.println("\nWiFi connected");
M5.Lcd.print("gatewayIP:");
M5.Lcd.print(WiFi.gatewayIP());
}
void loop() {}
Description:
Returns the DNS address.
Function Prototype:
IPAddress dnsIP(uint8_t dns_no = 0)
Usage Example:
#include <M5Stack.h>
#include <WIFI.h>
// Fill in the hotspot name and password you are connected to.
const char *ssid = "yourNetwork";
const char *password = "'secretPassword";
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.setTextSize(2);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
M5.Lcd.print(".");
}
M5.Lcd.println("\nWiFi connected");
M5.Lcd.print("dnsIP:");
M5.Lcd.print(WiFi.dnsIP());
}
void loop() {}
Description:
Returns the MAC address.
Function Prototype:
String macAddress()
Usage Example:
#include <M5Stack.h>
#include <WIFI.h>
// Fill in the hotspot name and password you are connected to.
const char *ssid = "yourNetwork";
const char *password = "'secretPassword";
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.setTextSize(2);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
M5.Lcd.print(".");
}
M5.Lcd.println("\nWiFi connected");
M5.Lcd.print("macAddress:");
M5.Lcd.print(WiFi.macAddress());
}
void loop() {}
Description:
Returns the host name.
Function Prototype:
const char * getHostname()
Usage Example:
#include <M5Stack.h>
#include <WIFI.h>
// Fill in the hotspot name and password you are connected to.
const char *ssid = "yourNetwork";
const char *password = "'secretPassword";
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.setTextSize(2);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
M5.Lcd.print(".");
}
M5.Lcd.println("\nWiFi connected");
M5.Lcd.print("getHostname:");
M5.Lcd.print(WiFi.getHostname());
}
void loop() {}
Description:
Returns the WiFi status.
Function Prototype:
wl_status_t status()
Return Values
Value | Description |
---|---|
255 | WL_NO_SHIELD Check WiFi Shield |
0 | WL_IDLE_STATUS Switching between WiFi modes |
1 | WL_NO_SSID_AVAIL Unable to access the set SSID network |
2 | WL_SCAN_COMPLETED Scan completed |
3 | WL_CONNECTED Connection successful |
4 | WL_CONNECT_FAILED Connection failed |
5 | WL_CONNECTION_LOST Connection lost |
6 | WL_DISCONNECTED Disconnected |
Usage Example:
#include <M5Stack.h>
#include <WIFI.h>
// Fill in the hotspot name and password you are connected to.
const char *ssid = "yourNetwork";
const char *password = "'secretPassword";
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.setTextSize(2);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
M5.Lcd.print(".");
}
M5.Lcd.println("\nWiFi connected");
}
void loop() {}
Description:
Scans for WiFi networks (by default in blocking mode).
Function Prototype:
int16_t scanNetworks(bool async = false, bool show_hidden = false, bool passive = false, uint32_t max_ms_per_chan = 300)
Parameter | Type | Description |
---|---|---|
async | bool | Asynchronous scan WiFi numbers (non-blocking), start with true |
show_hidden | bool | Whether to scan hidden networks |
passive | bool | Quick scan |
max_ms_per_chan | uint32_t | Channel scan time |
Usage Example:
#include <M5Stack.h>
#include <WIFI.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.setTextSize(2);
M5.Lcd.println("Scanning...");
WiFi.scanNetworks();
M5.Lcd.printf("wifi number:%d\n", WiFi.scanComplete());
}
void loop() {}
Description:
In asynchronous mode, retrieves the scanned networks. Returns -1 if the scan is incomplete, and -2 if the scan fails.
Function Prototype:
int16_t scanComplete()
Usage Example:
#include <M5Stack.h>
#include <WIFI.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.setTextSize(2);
WiFi.scanNetworks(true);
M5.Lcd.printf("Scanning...");
while (WiFi.scanComplete() == WIFI_SCAN_RUNNING ||
WiFi.scanComplete() == WIFI_SCAN_FAILED) {
M5.Lcd.printf(".");
delay(500);
}
M5.Lcd.printf("\nWiFi number:%d\n", WiFi.scanComplete());
}
void loop() {}
Description:
Returns the scanned network SSID.
Function Prototype:
String SSID(uint8_t networkItem)
Parameter | Type | Description |
---|---|---|
networkItem | uint8_t | SSID name |
Usage Example:
#include <M5Stack.h>
#include <WIFI.h
>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.setTextSize(2);
M5.Lcd.println("Scanning...");
WiFi.scanNetworks();
M5.Lcd.printf("wifi number:%d\n", WiFi.scanComplete());
for (int i = 1; i < WiFi.scanComplete(); i++) {
M5.Lcd.printf("%d:%s\n", i, WiFi.SSID(i).c_str());
}
}
void loop() {}
Description:
Deletes the scan result from memory.
Function Prototype:
void scanDelete()
Usage Example:
#include <M5Stack.h>
#include <WIFI.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.setTextSize(2);
M5.Lcd.println("Scanning...");
WiFi.scanNetworks();
M5.Lcd.println("Scan complete");
WiFi.scanDelete();
M5.Lcd.println("Scan result deleted from memory");
}
void loop() {}
Description:
Returns the scanned encrypted network.
Function Prototype:
wifi_auth_mode_t encryptionType(uint8_t networkItem)
Function Parameter | Type | Description |
---|---|---|
networkItem | uint8_t | SSID name |
Usage Example:
#include <M5Stack.h>
#include <WIFI.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.setTextSize(2);
M5.Lcd.println("Scanning...");
WiFi.scanNetworks();
M5.Lcd.printf("wifi number:%d\n", WiFi.scanComplete());
for (int i = 1; i < WiFi.scanComplete(); i++) {
M5.Lcd.printf("%d:", i);
M5.Lcd.print(WiFi.SSID(i));
M5.Lcd.print(",\t");
M5.Lcd.println(
(WiFi.encryptionType(i) == WIFI_AUTH_OPEN) ? "open" : "encryption");
delay(10);
}
}
void loop() {}
Description:
Returns the RSSI strength of the scanned networks.
Function Prototype:
int32_t RSSI(uint8_t networkItem)
Parameter | Type | Description |
---|---|---|
networkItem | uint8_t | RSSI item |
Usage Example:
#include <M5Stack.h>
#include <WIFI.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.setTextSize(2);
M5.Lcd.println("Scanning...");
WiFi.scanNetworks();
M5.Lcd.printf("wifi number:%d\n", WiFi.scanComplete());
for (int i = 1; i < WiFi.scanComplete(); i++) {
M5.Lcd.printf("%d:%s", i, WiFi.SSID(i).c_str());
M5.Lcd.printf(" , %d\n", WiFi.RSSI(i));
}
}
void loop() {}
Description:
Returns the channel number of the scanned networks.
Function Prototype:
int32_t channel(uint8_t networkItem)
Parameter | Type | Description |
---|---|---|
networkItem | uint8_t | Channel item |
Usage Example:
#include <M5Stack.h>
#include <WIFI.h>
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.setTextSize(2);
M5.Lcd.println("Scanning...");
WiFi.scanNetworks();
M5.Lcd.printf("wifi number:%d\n", WiFi.scanComplete());
for (int i = 1; i < WiFi.scanComplete(); i++) {
M5.Lcd.printf("%d:%s", i, WiFi.SSID(i).c_str());
M5.Lcd.printf(" , %d\n", WiFi.channel(i));
}
}
void loop() {}