I need your help with my "WeMos D1 Wireless UNO ESP8266"

Hi, I need your help. I try to receive weather data from openweathermap.org with my "WeMos D1 Wireless UNO ESP8266". I have the following code:

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

HTTPClient sender;
WiFiClientSecure wifiClient;

#include <ArduinoJson.h>

// WLAN-Daten
const char* ssid = "YOUR-SSID";          //your-ssid
const char* password = "YOUR-PASSWORD";  //your-password
void setup() {
  Serial.begin(115200);
  Serial.println("INIT");
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(200);
    Serial.print(".");
  }

  Serial.println("Connected to wifi!");
  Serial.println();

  wifiClient.setInsecure();
  delay(500);
  // put your setup code here, to run once:
  Serial.println("START REQUEST for forecast");
  if (sender.begin(wifiClient, "https://api.openweathermap.org/data/2.5/forecast?q=61440&appid=b045804ab93431828b3e101e2be26dc1")) {  //This Api-Key isn't from me it is from https://www.grepper.com/tpc/open+weather+api+key#527978
    int httpCode = sender.GET();
    Serial.println(httpCode);
    if (httpCode > 0) {
      if (httpCode == 200) {
        String payload = sender.getString();
        Serial.print("PAYLOAD: \"");
        Serial.println(payload + "\"");
      } else {
        Serial.print("HTTP-Error: " + String(httpCode));
      }
    }
  }
  sender.end();
  Serial.println("DONE");
}


void loop() {
  // put your main code here, to run repeatedly:
}

But I get no payload back. If I request other api-points such as https://api.openweathermap.org/data/2.5/weather?q=61440&appid=b045804ab93431828b3e101e2be26dc1 I get a payload. Does anyone know what's going on?

I use the Bodmer openweather library with his jsondecoder.

screenshot_17645

Thanks, that sounds good:)
I think I'll use this library for my project

But do you know why my request doesn't work?

If I run you're URL, I don't see the httpCode 200

Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET, POST
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 16172
Content-Type: application/json; charset=utf-8
Date: Wed, 25 Jan 2023 10:26:48 GMT
Server: openresty
X-Cache-Key: /data/2.5/forecast?q=61440

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,/;q=0.8
Accept-Encoding: gzip, deflate, br
Accept-Language: nl,en-US;q=0.7,en;q=0.3
Connection: keep-alive
Host: api.openweathermap.org
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: none
Sec-Fetch-User: ?1
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/109.0

In RAW JSON there is

{"cod":"200","message":0,"cnt":40,"list":

How did you get this information?

If you open the link in your browser, you should get all data.
How??

And thanks for your time :slight_smile:

I use FireFox. I post the apistring without "". Then I become this screen as decoded JSON and more.

If I choose "Onbewerkte gegevens" = RAW I become this.

And this are the Headers.

Yeah, I'm using Firefox too and see all that values, but I also can see in the header

Content-Length 16173

And there seems to be some data which Firefox receives, why the Arduino can't?

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