arduino-libraries / ArduinoHttpClient

Arduino HTTP Client library
287 stars 172 forks source link

HTTP Client fails when instantiated locally rather than globally #156

Open tigoe opened 1 year ago

tigoe commented 1 year ago

When you put the instantiation of the ArduinoHttpClient in the loop or in any function, the client often fails to finish the request. It will make the HTTP call, and the server will acknowledge it, but then nothing happens until timeout.

Tested on Nano RP2040 (for WiFiNINA) and Uno R4 WiFi.

It fails for both HTTP and HTTPS, using the steps below:

To reproduce this, using Examples -> SimpleGet:

  1. change line 12 to #include the correct library for your board (WiFiNINA.h, WiFiS3.h, etc)
  2. change serverAddress (line 21) to "www.arduino.cc" or any test server
  3. change port (line 22) to 80
  4. Enter SECRET_SSID and SECRET_PASS in arduino_secrets.h for your network
  5. Move line 25, HttpClient client = etc. to the first line of the loop() function (line 49)
  6. Upload and watch the results. It will fail at line 50, "Making GET request". It will succeed about 25% of the time, but it will fail in a significant number of cases.

To test HTTPS, change WiFiClient instantiation on line 24 to WiFiSSLClient, and change port to 443.