WifiClient is causing issue randomly

Hi team

I have been using WifiClient and WifiClientSecure to make HTTP get request for JSON file. I observed that WifiClient may crash the program occasionally while it is facing a timeout or connection error to web server. The same situation doesnt happen while calling WifiClientSecure, failure of http request can be handled properly without any system hanging or crash.

Any comment?

Hi @andyfai,

Can you confirm that you are running the latest WiFi libraries and also running the latest RTL8720 firmware (V2.1.1)?

Also, could you share your code here please?

Best Regards,
Lakshantha

Thank you. I think it is installed with v2.1.0. I will try 2.1.1
May I know if I can disable the CA cert check in WIFIClientSecure? ! have a couple of https url to call, hard-coding all of them with different CA Cert in my code is not sustainable

Hi @andyfai,

Please check with firmware v2.1.1

In the meantime, to answer your question, you can disable root CA cert check by deleting:

const char* test_root_ca = \
                            "-----BEGIN CERTIFICATE-----\n"
                            "xxxxxx
                            "xxxxxx

And also deleting this line:

client.setCACert(test_root_ca);

Best Regards,
Lakshantha

After upgrade from 2.1.0 to 2.1.1, I cannot connect to web server by the following code

WiFiClientSecure metalclient;
void loop(){
metalclient.setTimeout(10);
Serial.println(“Trying connect to Server”);
if (!metalclient.connect(“data-asg.goldprice.org”, 443)) {
Serial.println(“Connection failed!”);
…
}

I changed my code to get JSON via http client, everything looks ok however system hang/crash happen again after a failed URL call occasionally.
My program is very simple which allow Bluetooth Client to connect and provide WIFI SSID & pwd.
Then download data periodically from web server via wifi and disable in screen as a system monitor device… Unfortunately the network API is unstable

DynamicJsonDocument getJson(char* url)
{
HTTPClient client;
client.setTimeout(10);
client.begin(url);
int httpCode = client.GET();
String payload = “”;

if (httpCode > 0) {
// HTTP header has been send and Server response header has been handled
Serial.printf("[HTTP] GET… code: %d\n", httpCode);
// file found at server
if (httpCode == HTTP_CODE_OK) {
payload = client.getString();
Serial.println(payload);
}

client.end();

} else {
Serial.printf("[HTTP] GET… failed, error: %s\n", client.errorToString(httpCode).c_str());
client.end();

DynamicJsonDocument doc(1);
return doc;

}

const size_t capacity = JSON_OBJECT_SIZE(3) + 2000;
DynamicJsonDocument doc(capacity);
deserializeJson(doc, payload);

return doc;
}

1 Like

Hi @andyfai,

After upgrading to RTL8720 version 2.1.1, did you update rpcWiFi and rpcUnified as well?

Seeed_Arduino_rpcWiFi - v1.0.2
Seeed_Arduino_rpcUnified - v2.1.1

Best Regards,
Lakshantha

After upgraded these two library, it can keep running for few hours(originally less than 1 hour) but eventually the same issue happened.

My program is just keep calling Http client for every 30s and display the resource

1 Like