ESP32をWiFiに繋げたので、スケッチを書いておく
ESP32-DevKitC 及び HiLetgo ESP-32s NodeMCU
ArduinoIDE 1.8.5
Arduino WiFi Library
https://www.arduino.cc/en/Reference/WiFi
WiFi.ino
#include <WiFi.h>
// 接続先のSSIDとパスワード
const char ssid[] = "########";
const char passwd[] = "########";
void setup() {
Serial.begin(115200);
// Connect WiFi
connectWiFi();
}
void loop() {
// Reconnect
if ( WiFi.status() == W_DISCONNECTED ) {
connectWiFi();
}
}
/**
* Connect WiFi
*/
void connectWiFi()
{
WiFi.begin(ssid, passwd);
Serial.print("WiFi connecting...");
while(WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(100);
}
Serial.print(" connected. ");
Serial.println(WiFi.localIP());
}