WIFI

使用前にライブラリを読み込む必要があります #include <WiFi.h>

WiFi.softAP()

機能です:

AP モードを開啓し、成功時 true を返します

原型関数です:

bool softAP(const char* ssid, const char* passphrase = NULL, int channel = 1, int ssid_hidden = 0, int max_connection = 4)

パラメータです 記述します タイプです
ssid AP 名称(0~32 バイト) const char*
passphrase パスワード(8~63 バイト)または NULL const char*
channel チャンネル int
ssid_hidden SSID を隠す(1:隠す 0:非隠す) int
max_conncetion 最大接続数(1~4) int

使用例です:

#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);
}

WiFi.softAPConfig()

機能です:

AP の IP アドレスを設定

原型関数です:

bool softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress subnet)

パラメータです 記述します タイプです
local_ip デフォルトのローカル IP(例:192.168.4.1) IPAddress
gateway デフォルトのゲートウェイ(例:192.168.4.1) IPAddress
subnet デフォルトのサブネットマスク(例:255.255.255.0) IPAddress

使用例です:

#include <M5Stack.h>
#include <WIFI.h>

IPAddress local_IP(192, 168, 4,22);  // Manually set the ip address of the open network. 手动设置的开启的网络的ip地址
IPAddress gateway(192, 168, 4,9);  // Manually set gateway IP address. 手动设置的网关IP地址
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);
}

WiFi.softAPdisconnect()

機能です:

現在の AP を切断し、wifioff が true の場合はネットワーク設定をリセット

原型関数です:

bool softAPdisconnect(bool wifioff = false)

パラメータです 記述します タイプです
wifioff 切断 AP 後、WiFi を OFF にするか否か bool

使用例です:

#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()) {  //Turn off the current AP and restore the network settings.  关闭当前AP,并还原网络设置
            M5.Lcd.println("WiFi AP is closed");
            delay(5000);
        }
    } else {
        M5.Lcd.println("WiFi AP is down");
    }
    delay(1000);
}

WiFi.softAPgetStationNum()

機能です:

AP に接続中のクライアントの数を返します

原型関数です:

uint8_t softAPgetStationNum()

使用例です:

#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);
}

WiFi.softAPIP()

機能です:

AP の現在の IP アドレスを返します

原型関数です:

IPAddress softAPIP()

使用例です:

#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);
}

WiFi.softAPsetHostname()

機能です:

AP の IP アドレスを設定

原型関数です:

bool softAPsetHostname(const char * hostname)

パラメータです 記述します タイプです
hostname ホスト名 const char*

使用例です:

#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);
}

WiFi.softAPgetHostname()

機能です:

AP のホスト名を取得します

原型関数です:

const char * softAPgetHostname()

使用例です:

#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", WiFi.softAPgetHostname());
    } else {
        M5.Lcd.println("WiFi AP is down");
    }
    delay(1000);
}

WiFi.softAPmacAddress()

機能です:

AP の MAC アドレスを取得します

原型関数です:

String softAPmacAddress(void)

使用例です:

#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);
}

WiFi.begin()

機能です:

指定のネットワークに接続します(connect パラメータが true の場合は、接続を確立します;false の場合は、設定を保存し、wifi の状態を返します)

原型関数です:

wl_status_t begin(const char* ssid, const char *passphrase = NULL, int32_t channel = 0, const uint8_t* bssid = NULL, bool connect = true)

パラメータです 記述します タイプです
ssid ホットスポットの名前です const char*
passphrase パスワード(オプション)です const char*
channel ホットパス番号(オプション)です int32_t
bssid ホットスポットの mac アドレス(任意)です const uint8_t*
connect コネクションの確立(オプション)です bool

使用例です:

#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() {}

WiFi.config()

機能です:

ネットワークのアドレスを設定します

原型関数です:

bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = (uint32_t)0x00000000, IPAddress dns2 = (uint32_t)0x00000000)

パラメータです 記述します タイプです
local_ip IP を設定します IPAddress
gateway ゲートウェイを設置します IPAddress
subnet サブネットマスクを設定します IPAddress
dns1 DNS1 をセットします IPAddress
dns2 DNS2 をセットします IPAddress

WiFi.disconnect()

機能です:

ネットワーク接続を切断します。wifioff が true の場合は、ネットワークの設定もリセットします。eraseap が true の場合は、flash に保存されているネットワークパラメータをクリアします

原型関数です:

bool disconnect(bool wifioff = false, bool eraseap = false)

パラメータです 記述します タイプです
wifioff 設定をリセットする bool
eraseap flash の AP 設定をクリアする bool

使用例です:

#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() {}

WiFi.isConnected()

機能です:

ネットワークの接続状態を返します

原型関数です:

bool isConnected()

使用例です:

#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() {}

urNetwork"; const char *password = "'secretPassword";

void setup() { M5.begin(); M5.Power.begin(); M5.Lcd.setTextSize(2); if(WiFi.setAutoReconnect(true)) { M5.Lcd.println("Wh## WiFi.setAutoReconnect()

機能です:

自動再接続を設定しま.

原型関数です:

bool setAutoReconnect(bool autoReconnect)

使用例です:

#include <M5Stack.h>
#include <WIFI.h>

// Fill in the hotspot name and password you are connected to.
// 填写你所连接的热点名称和密码
const char *ssid     = "yoether 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() {}

WiFi.getAutoReconnect()

機能です:

自動再接続の状態を取得します

原型関数です:

bool getAutoReconnect()

WiFi.localIP()

機能です:

ローカル IP アドレスを取得します

原型関数です:

IPAddress localIP()

使用例です:

#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() {}

WiFi.subnetMask()

機能です:

サブネットマスクを返します

原型関数です:

IPAddress subnetMask()

使用例です:

#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() {}

WiFi.gatewayIP()

機能です:

ゲートウェイの IP アドレスを返します

原型関数です:

IPAddress gatewayIP()

使用例です:

#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() {}

WiFi.dnsIP()

機能です:

DNS アドレスを返します

原型関数です:

IPAddress dnsIP(uint8_t dns_no = 0)

使用例です:

#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() {}

WiFi.macAddress()

機能です:

mac アドレスに戻ります

原型関数です:

String macAddress()

使用例です:

#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() {}

WiFi.getHostname()

機能です:

ホスト名です

原型関数です:

const char * getHostname()

使用例です:

#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() {}

WiFi.status()

機能です:

WiFi 状態を返す

原型関数です:

wl_status_t status()

返回值

記述します
255 WL_NO_SHIELD WiFi Shield の検査
0 WL_IDLE_STATUS WiFi の作業モードの切替中
1 WL_SCAN_COMPLETED スキャン完了
2 WL_CONNECTED 接続成功
3 WL_CONNECT_FAILED 接続失敗
4 WL_CONNECT_FAILED 连接失败
5 WL_CONNECTION_LOST 接続を失った
6 WL_DISCONNECTED 接続を解除

使用例です:

#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() {}

WiFi.scanNetworks()

機能です:

WiFi ネットワークをスキャン(デフォルトはブロッキングモード)

原型関数です:

int16_t scanNetworks(bool async = false, bool show_hidden = false, bool passive = false, uint32_t max_ms_per_chan = 300)

パラメータです タイプです 記述します
async bool 非同期スキャン Wifi の数(非ブロッキング), true のとき開始动
show_hidden bool 隠しネットワークをスキャンするかどうか络
passive bool 速やかなスキャン
max_ms_per_chan uint32_t チャンネルのスキャン時間

使用例です:

#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() {}

WiFi.scanComplete()

機能です:

非同期モードでスキャンしたネットワークを取得. -1 を返すときはスキャン未完成.-2 を返すときはスキャン失敗.

原型関数です:

int16_t scanComplete()

使用例です:

#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() {}

WiFi.SSID()

機能です:

スキャンしたネットワークを返す..

原型関数です:

String SSID(uint8_t networkItem)

パラメータです タイプです 記述します
networkItem uint8_t SSID 名称

使用例です:

#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() {}

WiFi.scanDelete()

機能です:

メモリからスキャン結果を削除

原型関数です:

void scanDelete()

使用例です:

#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() {}

WiFi.encryptionType()

機能です:

暗号化されたネットワークをスキャンして返す

原型関数です:

wifi_auth_mode_t encryptionType(uint8_t networkItem)

関数の引数です タイプです 記述します
networkItem uint8_t SSID 名称

使用例です:

#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() {}

WiFi.RSSI()

機能です:

スキャンした RSSI 強度に戻ります

原型関数です:

int32_t RSSI(uint8_t networkItem)

パラメータです タイプです 記述します
networkItem uint8_t RSSI item

使用例です:

#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() {}

WiFi.channel()

機能です:

検出したネットワークのチャンネル番号を返却

原型関数です:

int32_t channel(uint8_t networkItem)

パラメータです タイプです 記述します
networkItem uint8_t channel item

使用例です:

#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() {}
On This Page