0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ESP32: HTTP クライアント (Get)

Last updated at Posted at 2022-11-19

こちらのプログラムを ESP32 に書き換えました。
M5Stack Core2: HTTP クライアント (Get)
Ubuntu 24.04 上の Arduino IDE 2.3.2 を使いました。
ボードは ESP32 Dev Module です。

image.png

http_get.ino
// ---------------------------------------------------------------
/*
	http_get.ino

					Jul/25/2023
*/
// ---------------------------------------------------------------
#include <Arduino.h>

#include <WiFiMulti.h>
#include <HTTPClient.h>

WiFiMulti wifiMulti;
HTTPClient http;

const char *ssid = "rs500m-e1eaf5-1";
const char *password = "7f7a63e07b1c6";

int count = 0;

// ---------------------------------------------------------------
void setup()
{
	Serial.begin(115200);
	wifiMulti.addAP(ssid, password);

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

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

// ---------------------------------------------------------------
void loop()
{
	Serial.println("*** loop *** " + String(count));
	delay(5000);
	String url_target = "https://httpbin.org/get";
	http_get_proc(url_target);
	delay(5000);
	count++;
}

// ---------------------------------------------------------------
void http_get_proc(String url_target)
{
	if((wifiMulti.run() == 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");
		}
}

// ---------------------------------------------------------------

ターミナルプログラム

cu -s 115200 -l /dev/ttyUSB0
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?