ESP8266 Stuck problem

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.

Should you not be using WiFiClientSecure instead of WiFiClient if you want to use HTTPS?

Maybe you can try the following example first:

The server tells you what's wrong: "400 The plain HTTP request was sent to HTTPS port"

It seems that the server expects something additional. As you don't want to share your API code (which I probably wouldn't do also) we are unable to check that without registering to that service ourselves.

I suggest to check that manually. Install OpenSSL and then connect to the service:

openssl s_client -connect api.openweathermap.org:443

Then follow the HTTP protocol:

GET /data/2.5/weather?q=&appid=* HTTP/1.1
Host: api.openweathermap.org
Connection: close
Accept: /

If you insert your data, that probably should return successfully.

Exception (9) is an unaligned load or store. The Esp8266 is a 32 bit processor so 32 bit operations must be 32 bit aligned (address must be a multiple of 4 bytes). Also 16 bit operations must be 16 bit aligned.

Given a chance the compiler will insure that this happens. Use of pointers that are set wrong or packed data structures that force misalignment are the the common ways of defeating the compiler.

Fixing the problems noted above may be sufficient. If not you will need to figure out where the bogus address is coming from.

Thank you for your comment. I've been trying to solve this problem for hours, I tried many things but it didn't work. I solved it thanks to your comment.

This is the working code

#include <WiFiClientSecure.h>
#include <ArduinoJson.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
const char* ssid     = "****";     // your network SSID (name of wifi network)
const char* password = "*****"; // your network password

unsigned long lastTime = 0;
unsigned long timerDelay = 10000;

void setup() {
  Serial.begin(115200);
  delay(100);
  Serial.print("Attempting to connect to SSID: ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(1000);
  }
  Serial.print("Connected");
}

void loop() {
 if ((millis() - lastTime) > timerDelay) {
    if (WiFi.status() == WL_CONNECTED){
      HTTPClient http;
      WiFiClientSecure client;
      client.setInsecure();
      http.begin(client,"https://api.openweathermap.org/data/2.5/weather?q=****,**&APPID=*******");
      int httpCode = http.GET();
         if(httpCode > 0){
         String payload = http.getString();
         DynamicJsonDocument doc(1024);
         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();
 }
}

sss11

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.