Hello, Im trying to upload this sketch to ESP8266. Get Json data, and print to LCD display but, it doesn
t work as the sketch. It just loop printing in serial monitor rst cause 2, boot mode (3,6)
The things I have tried
1, Tools> Erase flash> Erase all flash contents
2, Attempted uploading sketch not plugging any device.
3. Used different cable.
Actually, I could upload the sketch properly yesterday, but LCD didn`t work.
Do you have any solutions???
</>整形済みテキスト
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
#include <ArduinoJson.h>
#include <stdio.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 5, 4);
const char* ssid = "secret";
const char* password = "secret2";
const String endpoint = "http://api.openweathermap.org/data/2.5/weather?q=chiba,jp&APPID=";
const String key = "e8b6ba7b9f80d5870b70b44a9c08da2d";
void setup() {
Serial.begin(115200);
// Initiate the LCD:
lcd.begin(16, 2);
int cursorPosition = 0;
lcd.setCursor(0, 0);
lcd.print(" Connecting");
Serial.println("Connecting");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.println("Connecting to WiFi..");
lcd.setCursor(0, 2);
lcd.print(".");
cursorPosition++;
}
lcd.clear();
lcd.print(" Connected!");
Serial.println("Connected to the WiFi network");
delay(8000);
}
void loop() {
if ((WiFi.status() == WL_CONNECTED)) {
WiFiClient client;
HTTPClient http;
http.begin(client, endpoint + key); //URLを指定
int httpCode = http.GET(); //GETリクエストを送信
if (httpCode > 0) { //返答がある場合
String payload = http.getString(); //返答(JSON形式)を取得
Serial.println(httpCode);
Serial.println(payload);
const size_t capacity = JSON_ARRAY_SIZE(1) + JSON_OBJECT_SIZE(1) + JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(3) + JSON_OBJECT_SIZE(4) + JSON_OBJECT_SIZE(5) + JSON_OBJECT_SIZE(8) + JSON_OBJECT_SIZE(13) + 470;
DynamicJsonBuffer jsonBuffer(capacity);
String json = payload;
//jsonオブジェクトの作成
JsonObject& weatherdata = jsonBuffer.parseObject(json);
//パースが成功したかどうかを確認
if (!weatherdata.success()) {
Serial.println("parseObject() failed");
}
//各データを抜き出し
const char* weather = weatherdata["weather"][0]["main"];
const double temp = weatherdata["main"]["temp"];
//LCDに表示
//画面を消去
//天気を表示
lcd.setCursor(0, 0);
lcd.print(weather);
//気温を表示
lcd.setCursor(0, 1);
String temp_str = String(temp - 273.15) + "°C";
lcd.print(temp_str);
Serial.println(weather);
Serial.println(temp_str);
}
else {
Serial.println("Error on HTTP request");
}
http.end(); //Free the resources
}
delay(5000);
}
</>整形済みテキスト