ESP32: WiFiManager の使い方

こちらのプログラムを WiFiManager に書き換えました。
[ESP32: HTTP クライアント (Get)](https://qiita.com/ekzemplaro/items/a37e6be5e7eb898c647f)

WiFiManager では、SSID とパスワードは、EEPROM に保存されます。

## プログラム

```text:http_get.ino
// ---------------------------------------------------------------
/*
	http_get.ino

					Mar/28/2025
*/
// ---------------------------------------------------------------
#include <WiFiManager.h>
#include <HTTPClient.h>

HTTPClient http;

WiFiManager wm;
String APNAME=wm.getDefaultAPName();
String CPID=APNAME.substring(6);

int count = 0;

// ---------------------------------------------------------------
void setup()
{
	Serial.begin(115200);
	delay(1000);
	Serial.println("*** setup *** start ***");

	 if (wm.autoConnect()) {
		Serial.println("autoConnect() success!");
	} else {
		Serial.println("autoConnect() failed!");
	}

	Serial.println(WiFi.localIP());
	delay(2000);

	Serial.println("*** setup *** end ***");
}

// ---------------------------------------------------------------
void loop()
{
	Serial.println("*** loop *** " + String(count));
	delay(2000);
	if ( WiFi.status() == WL_DISCONNECTED ) {
		if (wm.autoConnect()) {
			Serial.println("autoConnect() success!");
		} else {
			Serial.println("autoConnect() failed!");
		}

		delay(3000);
		}

	if (WiFi.status() == WL_CONNECTED ) {
		String url_target = "https://httpbin.org/get";
		http_get_proc(url_target);
		delay(2000);
		Serial.println("APNAME = " + APNAME);
		Serial.println("CPID = " + CPID);
		delay(2000);
		}

	delay(1000);
	count++;
}

// ---------------------------------------------------------------
void http_get_proc(String url_target)
{
	if ( WiFi.status() == WL_CONNECTED ) {
		Serial.print("[HTTP] begin...\n");
		http.begin(url_target);
		Serial.print("[HTTP] GET...\n");
		int httpCode = http.GET();
		if(httpCode > 0) {
			Serial.printf("[HTTP] GET... code: %d\n", httpCode);

			if(httpCode == HTTP_CODE_OK) {
				String payload = http.getString();
				Serial.println(payload);
				}
			}else {
			Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
			}
		http.end();
	}
	else
		{
		Serial.print("connect failed");
		}
}

// ---------------------------------------------------------------
```

## 保存された SSID と パスワードを消去するプログラム

```text:ssid_clean.ino
// ---------------------------------------------------------------------
/*
	ssid_clean.ino
						Mar/28/2025
*/
// -------------------------------------------------------------------
#include <WiFiManager.h>

WiFiManager wm;
String APNAME=wm.getDefaultAPName();
String CPID=APNAME.substring(6);

int icount = 0;

// -------------------------------------------------------------------
void setup() {
	Serial.begin(115200);

	delay(1000);
	Serial.println("*** setup *** start ***");

	Serial.println("APNAME = " + APNAME);
	Serial.println("CPID = " + CPID);

	Serial.println("Wi-Fi 設定を消去中...");
	wm.resetSettings();
	delay(1000);

	Serial.println("*** setup *** eee ***");
}

// -------------------------------------------------------------------
void loop() {
	Serial.println("*** loop *** " + String(icount));
	Serial.println("APNAME = " + APNAME);
	Serial.println("CPID = " + CPID);
	delay(4000);
	icount++;
}

// -------------------------------------------------------------------
```