// 複数のアクセスポイント(AP)を同時に探索し、強いAPに接続する
#include <M5StickCPlus.h>
#include <WiFi.h>
#include <WiFiMulti.h>
WiFiMulti wifiMulti;
const char *ssid1 = "ics-ap"; // 2.4GHzのみ。5GHzはNG
const char *password1 = "jikkenics";
const char *ssid2 = "your_wifi";
const char *password2 = "xxxxx";
void setup()
{
M5.begin();
M5.Lcd.setRotation(3);
M5.Lcd.fillScreen(ORANGE);
M5.Lcd.setCursor(10, 50, 4);
// wifiMulti.addAP(ssid1, password1); // 上で設定した変数で設定
// wifiMulti.addAP(ssid2, password2);
wifiMulti.addAP("third_one", "xxxxx"); // 直接文字列で設定。どちらも同じ。
M5.Lcd.print("connecting...");
while (wifiMulti.run() != WL_CONNECTED) // 接続成功するまで時間がかかる
{ // 接続中...
M5.Beep.tone(2000);
delay(200);
M5.Beep.mute();
delay(300);
M5.Lcd.print(".");
}
// 接続完了!!
M5.Beep.tone(4000);
M5.Lcd.fillScreen(GREEN);
M5.Lcd.setCursor(0, 40, 4);
M5.Lcd.setTextColor(BLACK, GREEN);
M5.Lcd.print(" Wifi Connected!\n ");
String gotip = WiFi.localIP().toString(); // m5デバイスのIPアドレス
M5.Lcd.println(gotip);
delay(1500);
M5.Beep.mute();
}
void loop()
{
}