前提・実現したいこと
OpenWeatherMapからJsonファイルを入手して、必要な情報だけ表示しようとしているのですが、
HTTPClient.hをincludeしているにもかかわらず、'HTTPClient' was not declared in this scope
というエラーが出てしまいます。
発生している問題・エラーメッセージ
> Executing task in folder M5stack: C:\Users\aki_f.platformio\penv\Scripts\pio.exe run < Processing m5stack-grey (platform: espressif32; board: m5stack-grey; framework: arduino) --------------------------------------------------------------------------------------------------------------------------------- Verbose mode can be enabled via `-v, --verbose` option CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/m5stack-grey.html PLATFORM: Espressif 32 (2.1.0) > M5Stack GREY ESP32 HARDWARE: ESP32 240MHz, 520KB RAM, 16MB Flash DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa) PACKAGES: - framework-arduinoespressif32 3.10004.201016 (1.0.4) - tool-esptoolpy 1.30000.201119 (3.0.0) - toolchain-xtensa32 2.50200.80 (5.2.0) LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf LDF Modes: Finder ~ chain, Compatibility ~ soft Found 30 compatible libraries Scanning dependencies... Dependency Graph |-- <M5Stack> 0.3.1 | |-- <FS> 1.0 | |-- <SPIFFS> 1.0 | | |-- <FS> 1.0 | |-- <SPI> 1.0 | |-- <ArduinoHttpClient> 0.4.0 | |-- <Wire> 1.0.1 | |-- <SD(esp32)> 1.0.5 | | |-- <FS> 1.0 | | |-- <SPI> 1.0 |-- <ArduinoHttpClient> 0.4.0 |-- <ArduinoJson> 5.13.4 |-- <HttpClient> 2.2.0 |-- <WiFi> 1.0 Building in release mode Compiling .pio\build\m5stack-grey\src\main.cpp.o Compiling .pio\build\m5stack-grey\lib3fb\M5Stack\M5Display.cpp.o Compiling .pio\build\m5stack-grey\lib3fb\M5Stack\utility\In_eSPI.cpp.o Compiling .pio\build\m5stack-grey\lib3fb\M5Stack\utility\M5Timer.cpp.o Compiling .pio\build\m5stack-grey\lib3fb\M5Stack\utility\MPU6886.cpp.o Compiling .pio\build\m5stack-grey\lib3fb\M5Stack\utility\MPU9250.cpp.o Compiling .pio\build\m5stack-grey\lib3fb\M5Stack\utility\MahonyAHRS.cpp.o Compiling .pio\build\m5stack-grey\lib3fb\M5Stack\utility\Power.cpp.o src\main.cpp: In function 'void loop()': src\main.cpp:36:16: error: no matching function for call to 'HttpClient::HttpClient()' HttpClient http; ^ Exception in thread Thread-3: Traceback (most recent call last): File "C:\Users\aki_f.platformio\python3\lib\threading.py", line 926, in _bootstrap_inner self.run() File "C:\Users\aki_f.platformio\python3\lib\threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "c:\users\aki_f.platformio\penv\lib\site-packages\platformio\proc.py", line 47, in run self.do_reading() File "c:\users\aki_f.platformio\penv\lib\site-packages\platformio\proc.py", line 70, in do_reading for byte in iter(lambda: self._pipe_reader.read(1), ""): File "c:\users\aki_f.platformio\penv\lib\site-packages\platformio\proc.py", line 70, in <lambda> for byte in iter(lambda: self._pipe_reader.read(1), ""): UnicodeDecodeError: 'cp932' codec can't decode byte 0x9a in position 921: illegal multibyte sequence ================================================== [FAILED] Took 13.53 seconds ==================================================
該当のソースコード
Arduino
1#include <ArduinoJson.h> 2#include <M5stack.h> 3#include <ArduinoJson.h> 4#include <HTTPClient.h> 5#include <WiFi.h> 6 7const char* ssid = "ssid "; 8const char* password = "password "; 9 10const String endpoint = "http://api.openweathermap.org/data/2.5/weather?q=Ibaraki,jp&units=metric&APPID="; 11const String key = "key"; 12 13void setup() { 14 M5Stack M5; 15 M5.begin(); 16 M5.Lcd.begin(); 17 M5.Lcd.setBrightness(200); 18 Serial.begin(115200); 19 M5.Lcd.print("Start!"); 20 delay(10000); 21 WiFi.begin(ssid, password); 22 23 while (WiFi.status() != WL_CONNECTED) { 24 delay(1000); 25 Serial.println("Connecting to WiFi.."); 26 } 27 28 Serial.println("Connected to the WiFi network"); 29 M5.Lcd.print("Connected!"); 30} 31 32void loop() { 33 34 if ((WiFi.status() == WL_CONNECTED)) { 35 36 HttpClient http; 37 38 http.begin(endpoint + key); //URLを指定 39 int httpCode = http.GET(); //GETリクエストを送信 40 41 if (httpCode > 0) { //返答がある場合 42 43 String payload = http.getString(); //返答(JSON形式)を取得 44 Serial.println(httpCode); 45 Serial.println(payload); 46 47 //jsonオブジェクトの作成 48 DynamicJsonBuffer jsonBuffer; 49 String json = payload; 50 JsonObject& weatherdata = jsonBuffer.parseObject(json); 51 52 //パースが成功したかどうかを確認 53 if(!weatherdata.success()){ 54 Serial.println("parseObject() failed"); 55 } 56 57 //各データを抜き出し 58 const char* weather = weatherdata["weather"][0]["main"].as<char*>(); 59 const double temp = weatherdata["main"]["temp"].as<double>(); 60 Serial.print("weather:"); 61 Serial.println(weather); 62 Serial.print("temperature:"); 63 Serial.println(temp-273.15); 64 } 65 66 else { 67 Serial.println("Error on HTTP request"); 68 } 69 70 http.end(); //リソースを解放 71 } 72 73 delay(30000); //30秒おきに更新 74 75}
試したこと
こちらなどを参考にコードをいじってみましたが、変化はなく、エラーが起こるだけでした。
補足情報(FW/ツールのバージョンなど)
VScode1.52.1
Windows10
PlatformIO IDE2.2.1
Processing m5stack-grey (platform: espressif32; board: m5stack-grey; framework: arduino
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。