WiFiMultiというクラスがありましたとさ。
wifimulti.cpp
#include <Arduino.h>
#include <M5StickC.h>
#include <WiFi.h>
#include <WiFiMulti.h>
WiFiMulti wifiMulti;
#include "secret.h"
void setup() {
M5.begin();
wifiMulti.addAP(SSID1, PASSPHRASE1);
wifiMulti.addAP(SSID2, PASSPHRASE2);
}
void loop() {
M5.Lcd.setRotation(1);
M5.Lcd.fillScreen(BLACK);
M5.Lcd.setCursor(0, 0);
M5.Lcd.setTextColor(WHITE);
M5.Lcd.setTextSize(1);
printf("WiFiMulti connecting...\n");
M5.Lcd.printf("WiFiMulti connecting...\n");
if(wifiMulti.run() == WL_CONNECTED) {
printf("CONNECTED: ssid=%s localIP=%s\n", WiFi.SSID().c_str(), WiFi.localIP().toString().c_str());
M5.Lcd.printf("ssid=%s\n", WiFi.SSID().c_str());
M5.Lcd.printf("localIP=%s\n", WiFi.localIP().toString().c_str());
}else{
printf("failed\n");
M5.Lcd.printf("failed\n");
}
WiFi.disconnect();
printf("disconnected.\n");
M5.Lcd.printf("disconnected.\n");
delay(1000);
}