esp-idf/examples/protocols/http_request のプログラムを改造します。
M5Stack Core2 で動作確認をしました。
次のサイトにアクセスする例です。
プログラム
プログラムのコピー
cd ~/esp
cp -r esp-idf/examples/protocols/http_request .
http_request/sdkconfig を作成
idf.py build
変更する場所
http_request/sdkconfig
(省略)
CONFIG_EXAMPLE_WIFI_SSID="****"
CONFIG_EXAMPLE_WIFI_PASSWORD="****"
(省略)
http_request/main/http_request_example_main.c
(省略)
#define WEB_SERVER "httpbin.org"
#define WEB_PORT "80"
#define WEB_PATH "/get"
(省略)
コンパイル、実行
idf.py -p /dev/ttyUSB0 flash
実行結果
HTTP/1.1 200 OK
Date: Mon, 30 Jan 2023 07:44:44 GMT
Content-Type: application/json
Content-Length: 239
Connection: close
Server: gunicorn/19.9.0
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
{
"args": {},
"headers": {
"Host": "httpbin.org",
"User-Agent": "esp-idf/1.0 esp32",
"X-Amzn-Trace-Id": "Root=1-63d7756c-3c33c51147890fc74b272b72"
},
"origin": "219.126.136.17",
"url": "http://httpbin.org/get"
}
確認したバージョン
$ idf.py --version
ESP-IDF v5.4-dev-3201-g46acfdce96