Hello folks,
I tried to modify the WifiSSLClient example in order to receive data of the website : "api.checkwx.com".
Unfortunately I am not able to create a connection to the server. I have no clue what I should do in order that it works. I was reading already a lot in the internet about this issue, but to be honest, I have no clue any more of how to solve it. Here is the code. It is from the Arduino Example from the Arduino Uno Wifi R4:
#include <WiFiS3.h>
#include "arduino_secrets.h"
#include "WiFiSSLClient.h"
#include "IPAddress.h"
#define CA_CERT "-----BEGIN CERTIFICATE-----\n" \
"MIIHlDCCBXygAwIBAgIQCbVeEiNh4ua3avfR1si8yjANBgkqhkiG9w0BAQsFADBc\n" \
"MQswCQYDVQQGEwJVUzEXMBUGA1UEChMORGlnaUNlcnQsIEluYy4xNDAyBgNVBAMT\n" \
"K0dlb1RydXN0IEdsb2JhbCBUTFMgUlNBNDA5NiBTSEEyNTYgMjAyMiBDQTEwHhcN\n" \
"MjMxMDEzMDAwMDAwWhcNMjQwNDEzMjM1OTU5WjAeMRwwGgYDVQQDExNhdmlhdGlv\n" \
"bndlYXRoZXIuZ292MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtimG\n" \
"RP/KTzj9AFAj1yNaWLhtyWlya2afdflk/SrFczrsZ3idViBZMjjSB3+4mwVwr4NK\n" \
"ODvF0Y6wSaHolrnxFwvxzllB5PSWwFx7v6G/OFN6d0pkVG2QLdcJOPpNB7GypMxZ\n" \
"wZ7FnZtXQconanSQkUqxTRcMid+pFDBqc8fPAzCAkZoU1G8nix5UPpeidrJ44LJz\n" \
"5X6WGIblyyTomN7nfjZgkdM43uu/heMxI21VPD9qyOIwcXNGN4aW6M2XOqaS6akZ\n" \
"RvsXZYxbpTbPGLujEH+7DkrcKyNZsrToJiAjM8NSSigrvZ61I3uKfQQ16SD3DMLX\n" \
"FxAow1Ng6N3r3Os4gQIDAQABo4IDjjCCA4owHwYDVR0jBBgwFoAUpbTW6zbE52um\n" \
"38RkCwEqIAS4ZiMwHQYDVR0OBBYEFKkqd4D1acpBGTmJ87u44A8liW+vMB4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/az+1tiKfm8K7XGvocJFxbLtRhIU0vaQ9MEjX+6sAAAGLKlpUwAAABAMARjBE\n" \
"AiAV5NAAhcJFyhxckAnd27Pm2gUw3qfrqE0DScpsvHm5qQIgMzXP1uAKw2jQBugn\n" \
"a58rE8JTQx9SzUax3ONuYtWfrSMwDQYJKoZIhvcNAQELBQADggIBAFAeBj5P2C32\n" \
"Qf4U7a1nrWI5QT6GV5q1C9abB4MoVg9DVnwWTqnDrgszdPFQu3uo5dUabjB4g22P\n" \
"OoTpZoB8b3+8lx9A3sCq/nPL9oEsZCLRx37210yJwSMOlfdVW1yf9i+W/c44iG/D\n" \
"Z209y4xSSfRxnkTzqBGAbMEq5IyuYhQCLkuD2tXfttiitZw8/XKPfFu6ATSHBCKl\n" \
"Ajq0QOCXO1nI1HWQTjF23anX7dCY1bCLpNEMgkofzQcrEK/UOIo/ZopqKr9x5PHX\n" \
"2/FWTWP5f1lsIJT4nMsHswGU3AtoAg/LQKPiFlTK9WO3RaFU6BdPE4/8SsOODAaP\n" \
"SmXFIG8sHYb8fTZoOgDSDPtc6x5vDSe3057XAkymYPhZt/eu3ewXyg2D2J6ChE+m\n" \
"xfihTPhVY/zfHCVkbieHIgTCLzqSHV1aDCl1AdlINni6KvPkQrtSgPhpDPqM1dGp\n" \
"8F9QFGIVtnzBikq7jbnWrZKYv7a5iGByVNPs4BRQQgRuQqvCPSiWU/wOe4+Mlbbz\n" \
"dGwNSKXyX8zNQsDWTKNXtJQ30dS/N+D5OCVbKg1cJfCtHdjI1vCLZKn4gai3pv4k\n" \
"WA5QgNhEOySHAoh8pt0912RXGH9gzd7rdT+oTRgCF74sJdR/X4SxcGGOwXlKzb8T\n" \
"rkm5VhgmfyjvPETKiNTj/t+it5aLTBc1\n" \
"-----END CERTIFICATE-----\n"
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID; // your network SSID (name)
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
int status = WL_IDLE_STATUS;
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS)
char server[] = "https://api.checkwx.com"; // name address for Google (using DNS)
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
WiFiSSLClient client;
/* -------------------------------------------------------------------------- */
void setup() {
/* -------------------------------------------------------------------------- */
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// check for the WiFi module:
if (WiFi.status() == WL_NO_MODULE) {
Serial.println("Communication with WiFi module failed!");
// don't continue
while (true);
}
String fv = WiFi.firmwareVersion();
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
Serial.println("Please upgrade the firmware");
}
// attempt to connect to WiFi network:
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network.
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
}
printWifiStatus();
Serial.println("\nStarting connection to server...");
// if you get a connection, report back via serial:
client.setCACert(CA_CERT, strlen(CA_CERT)); //set CA cert
if (client.connect(server, 443)) {
Serial.println("connected to server");
// Make a HTTP request:
client.println("GET /metar/KJFK/decoded?x-api-key=" + apikey1);
client.println("Host: https://api.checkwx.com");
client.println("Connection: close");
client.println();
}
}
/* just wrap the received data up to 80 columns in the serial print*/
/* -------------------------------------------------------------------------- */
void read_response() {
/* -------------------------------------------------------------------------- */
uint32_t received_data_num = 0;
while (client.available()) {
/* actual data reception */
char c = client.read();
/* print data to serial port */
Serial.print(c);
/* wrap data to 80 columns*/
received_data_num++;
if(received_data_num % 80 == 0) {
Serial.println();
}
}
}
/* -------------------------------------------------------------------------- */
void loop() {
/* -------------------------------------------------------------------------- */
read_response();
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting from server.");
client.stop();
// do nothing forevermore:
while (true);
}
}
/* -------------------------------------------------------------------------- */
void printWifiStatus() {
/* -------------------------------------------------------------------------- */
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your board's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
I only receive the following:
signal strength (RSSI):-71 dBm
Starting connection to server...
disconnecting from server.
I use the Arduino IDE: 2.2.1
The following firmware is installed on the Arduino: 0.3.0
I tried to add the SSL Certificate via the funcitinallity in the IDE: Upload Roat SSL Certificate from website "api.checkwx.com"
But I also tried to add the certificate directly in the script... both is not working.
If you have an additional idea of how to solve this issue, I appreciate this a lot.
Yours,
Chris