Can someone please help me, i cant connect to Openweathermap
#include <WiFiClientSecureBearSSL.h>
#include <ArduinoJson.h>
#define BLYNK_TEMPLATE_ID "TMPL66Cczl1Kp"
#define BLYNK_TEMPLATE_NAME "ESP 8266"
#define BLYNK_FIRMWARE_VERSION "0.1.0"
#define BLYNK_PRINT Serial
#define APP_DEBUG
#include "BlynkEdgent.h"
// Replace with your own OpenWeatherMap API key
const char* apiKey = "10ea467a47af0c94d933380eec746a33";
// Replace with your city and country code
const char* city = "Davao";
const char* countryCode = "PH";
// Use HTTPS port 443 for secure communication
const int httpsPort = 443;
// Set up the client and SSL certificate
BearSSL::WiFiClientSecure client;
const char* rootCACertificate = \
"-----BEGIN CERTIFICATE-----\n" \
"MIIF1TCCA7WgAwIBAgIQcEypvxJjoGSHsFecTtT+zTANBgkqhkiG9w0BAQsFADCB\n" \
"...\n" \
"-----END CERTIFICATE-----\n";
X509List certList(rootCACertificate);
// Set up the Wi-Fi connection
void setupWifi() {
Serial.begin(9600);
delay(1000);
Serial.println();
Serial.print("Connecting to Wi-Fi...");
WiFi.mode(WIFI_STA);
BlynkEdgent.begin();
while (WiFi.status() != WL_CONNECTED) {
BlynkEdgent.run();
delay(1000);
Serial.print(".");
}
Serial.println();
Serial.println("Wi-Fi connected!");
}
// Set up the SSL certificate
void setupCertificate() {
client.setTrustAnchors(&certList);
client.setInsecure();
}
// Get weather description from OpenWeatherMap API
void getWeatherData() {
if (!client.connect("api.openweathermap.org", httpsPort)) {
Serial.println("Connection to OpenWeatherMap API failed!");
return;
}
Serial.println("Connected to OpenWeatherMap API!");
client.print(String("GET /data/2.5/weather?q=") + city + "," + countryCode + "&APPID=" + apiKey + "&units=metric\r\n");
client.print("Host: api.openweathermap.org\r\n");
client.print("User-Agent: ESP8266/1.0\r\n");
client.print("Connection: close\r\n\r\n");
while (client.connected()) {
String line = client.readStringUntil('\n');
if (line == "\r") {
break;
}
}
String response = client.readStringUntil('\n');
DynamicJsonDocument jsonBuffer(1024);
DeserializationError error = deserializeJson(jsonBuffer, response);
if (error) {
Serial.println("Parsing failed!");
return;
}
const char* weatherDescription = jsonBuffer["weather"][0]["description"];
Serial.print("Weather description: ");
Serial.println(weatherDescription);
// Send weather description to Blynk app
Blynk.virtualWrite(V0, weatherDescription);
}
// Set up the NodeMCU
void setup() {
setupWifi();
setupCertificate();
}
// Main program loop
void loop() {
BlynkEdgent.run();
getWeatherData();
delay(1000);
}