Hi guys, First of all, let me talk about the hardware I use. Arduino Uno and ESP8266 Module. I'm trying to set up a weather station. But I have a problem that I couldn't solve. I'll be happy if you can help me. First I want to share the code and then the error I get.
#include <SPI.h>
#include <ArduinoJson.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
const char *ssid = "net";
const char *password = "Pass";
unsigned long lastTime = 0;
unsigned long timerDelay = 10000;
void setup() {
Serial.begin(115200);
WiFi.begin(ssid,password);
WiFi.setAutoReconnect(true);
WiFi.persistent(true);
while(WiFi.status()!= WL_CONNECTED){
delay(500);
Serial.println("Waiting for connection..");
}
Serial.println("Connected");
WiFi.setAutoReconnect(true);
WiFi.persistent(true);
}
void loop() {
if ((millis() - lastTime) > timerDelay) {
if (WiFi.status() == WL_CONNECTED){
HTTPClient http;
WiFiClient wifiClient;
http.begin(wifiClient,"https://api.openweathermap.org/data/2.5/weather?q=****,**&appid=********");
int httpCode = http.GET();
if(httpCode > 0){
String payload = "{}";
payload = http.getString();
DynamicJsonDocument doc(512);
Serial.println(payload);
Serial.println((String)wifiClient.read());
DeserializationError error = deserializeJson(doc, payload);
if (error) {
Serial.print(F("deserializeJson() failed with code "));
Serial.println(error.f_str());
return;
}
float temp = doc["main"]["temp"]; // get temperature in °C
int humidity = doc["main"]["humidity"]; // get humidity in %
float pressure = doc["main"]["pressure"]; // get pressure in bar
float wind_speed = doc["wind"]["speed"]; // get wind speed in m/s
int wind_degree = doc["wind"]["deg"]; // get wind degree in °
Serial.printf("Temperature = %.2f°C\r\n", temp);
Serial.printf("Humidity = %d %%\r\n", humidity);
Serial.printf("Pressure = %.3f bar\r\n", pressure);
Serial.printf("Wind speed = %.1f m/s\r\n", wind_speed);
Serial.printf("Wind degree = %d°\r\n\r\n", wind_degree);
}
http.end();
}
lastTime = millis();
}
}
--------------- CUT HERE FOR EXCEPTION DECODER ---------------
ets Jan 8 2013,rst cause:2, boot mode:(3,6)
load 0x4010f000, len 3460, room 16
tail 4
chksum 0xcc
load 0x3fff20b8, len 40, room 4
tail 4
chksum 0xc9
csum 0xc9
v00047540
~ld
Waiting for connection..
Waiting for connection..
Waiting for connection..
Waiting for connection..
Waiting for connection..
Waiting for connection..
Waiting for connection..
Waiting for connection..
Connected
<html>
<head><title>400 The plain HTTP request was sent to HTTPS port</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<center>The plain HTTP request was sent to HTTPS port</center>
<hr><center>openresty</center>
</body>
</html>
-1
deserializeJson() failed with code InvalidInput
--------------- CUT HERE FOR EXCEPTION DECODER ---------------
Exception (9):
epc1=0x402135a8 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000226 depc=0x00000000
>>>stack>>>
ctx: cont
sp: 3ffffbe0 end: 3fffffc0 offset: 0190
3ffffd70: 00000000 00000000 4bc6a7f0 00000000
3ffffd80: 3ffeeb64 00000000 40100205 00000000
3ffffd90: 000027ca 3ffef628 00001a5e 00000000
3ffffda0: 00206564 00000002 3ffe8920 ffffffff
3ffffdb0: 000027ca 3fffff50 3ffef6e4 40202a10
3ffffdc0: 0000012c 3fffff30 3ffef624 3ffee7e0
3ffffdd0: 00000003 00000020 3ffef6e4 3ffee7e0
3ffffde0: 00000003 3fffff50 00000001 40202ea1
3ffffdf0: 00000203 00000203 3ffe85e8 40202ed5
3ffffe00: 00000003 3ffffe30 3ffee750 40202efc
3ffffe10: 00000003 3fffff20 3ffee750 402031f8
3ffffe20: 00000003 3fffff20 3ffee750 40201e80
3ffffe30: 3fffff50 3ffefa54 0016001f 80000000
3ffffe40: 3f0101bb 2c001388 3ffefc0c 0044004f
3ffffe50: 80000000 70747468 00000073 05000000
3ffffe60: 3ffefcd4 0000001f 80000000 3ffefa04
3ffffe70: 0011001f 80000000 00000000 3ffee6e8
3ffffe80: 00000000 00000000 00000000 00000190
3ffffe90: 000000fc 00000000 00000000 4010000a
3ffffea0: 00000000 00000000 00000000 00000000
3ffffeb0: 3ffefc64 3fffff28 0062006f 00000000
3ffffec0: 40205c44 00000001 3ffefcfd 3ffefdf8
3ffffed0: 0000013c 3fffff28 00000000 fffffffe
3ffffee0: ffffffff 3fffc6fc 00000001 3ffee7cc
3ffffef0: 00000000 3fffdad0 3ffee7e0 00000030
3fffff00: 00000000 3fffdad0 3ffee7e0 00000030
3fffff10: 40206c81 00000001 00000003 401008c8
3fffff20: 00000000 00000002 3fff0054 3fff0054
3fffff30: 3fff0254 3fff0254 0001c200 00000000
3fffff40: 007a1200 bcf5645e ffffff00 3ffee7e0
3fffff50: 40208d8c 00000000 00001388 000027b9
3fffff60: 00000000 00000000 3ffef6e4 00000000
3fffff70: 00000000 00fc00ff 00000000 40204664
3fffff80: 00000000 00000000 00000001 40100164
3fffff90: 3fffdad0 00000000 3ffee7cc 3ffee7e0
3fffffa0: 3fffdad0 00000000 3ffee7cc 40205c58
3fffffb0: feefeffe feefeffe 3ffe85e4 40100b51
<<<stack<<<
Solutions I tried; I changed the delay time and it didn't work. I measured the 3.3v output pin and the value came out correct. I connected a 100uF capacitor between esp8266's vin and gnd pin, it didn't work.