No connection to Server HTTPS UNO R4 Wifi

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"  \
"38RkCwEqIAS4ZiMwHQYD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S7x5U0Iv4Phpfd63Z1+0NZDcZC8Y1eGpDlN5AHUA\n"  \
"2ra/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

Get wireshark, debug your WiFi connection.

I will do :slight_smile:
Only one information I forgot to mention.

The connection via WIFIClient to another website is working fine. So I think it somehow is related to the WIFISSLClient.

I downloaded wireshark but to be honest, I do not really know what to do now.
If you could tell me what you would require would be great.

One info about my setup:
My computer is connected via LAN to the Router.
My arduino is connected via USB to my computer AND is connected to to the Router via WLAN-connection.

If you are lucky:

  • just start wireshark and let it listen on eth0
    if you are unlucky:
  • disable client separation on the router, try again.
  • connect your pc to wifi, try again
  • dive into network configuration of your router and network (but that's out the scope here)

Hey again,
I was having a look.
As I am really no IT-specialist I dont know what I should look up.

Hi @ercnr1 ,
I have the exact same problem with another website. Have you found a solution?

I also tried previous firmware versions, and different ways to write the domain (www.sitename.com, sitename.com, https://sitename.com), but none of them work. A note from my side: when I try a connection to "www.google.com", as the original script proposes, the script works. Is it then maybe possible that the problem is in the website?

1 Like

Note that Arduino boards only connect to a 2.4Ghz wifi and also you should not use SSID or password that has special characters or is too long.

1 Like

It is nice that I am not the only one :smiley:

I tried GOOGLE again...
The google website is working!
There I am able to get a connection. The result of what I receive is I think not worth it to share.

I have the feeling that it is somehow related to the SSL certificate of the other websites... the question is how to solve it.

Thank you for your support. As mentioned in my answer above, I am able to connect to my WIFI.
Do you have any other ideas how it is possible to solve this problem?

Hello @ercnr1,

Please, try using the following sketch:

/*
  TLS WiFi Web client

  Remeber to update the CA certificates using CertificateUploader sketch
  before using this sketch.

  Find the full UNO R4 WiFi Network documentation here:
  https://docs.arduino.cc/tutorials/uno-r4-wifi/wifi-examples#wi-fi-web-client-ssl
*/

#include "WiFiS3.h"
#include "WiFiSSLClient.h"
#include "IPAddress.h"

#include "arduino_secrets.h" 

///////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[] = "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(115200);
  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:
  
  if (client.connect(server, 443)) {
    Serial.println("connected to server");
    // Make a HTTP request:
    client.println("GET / HTTP/1.1");
    client.println("Host: www.google.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");
}

Replacing SECTRET_SSID and SECRET_PASS with your credentials and let me know the result.

Thank you,

J. Trujillo

Hello,

when using your sketch, i get this in the serial monitor:
�����怞�����怘�枆������������������昘���������怀������%�

wrong baudrate?

1 Like

Hi, as mentioned by @zwieblum it seems that you are selecting a different baud rate on the Serial monitor. Please note that in the sketch I shared the Serial is being initialized on 115200, so you need to change it in the serial:

1 Like

thank you for trying to find a solution with me @jorgetrujilloroman and @zwieblum

This is the result:

Does anybody of you are somebody else have any idea how to get the code running?

Where is your problem? It does exacly what it should do according to your code.

Hey. No it is not connecting to the server. It tries to but fails.

As you see in the serial monitor:
"Starting connection to the server"

"Disconnecting from Server"

Normally there should be the "Connected to the server" and also the http request should have been performed extracting the information I need.

Therefore the problem is unfortunately still not solved :frowning:
I was reading in the the forum about similar problems in the past which were solved and I also tried everything which was written there without success.

Hello @ercnr1,

Is your board's connectivity module firmware updated to the last version? if isn't you can do that by following this guide. Please try it and let me know if it helps.

Thank you!

Here is how you solve it -

1 Like