ArduinoCore-mbed icon indicating copy to clipboard operation
ArduinoCore-mbed copied to clipboard

WiFi library - os crash on Giga R1 when WiFiClient global

Open megacct opened this issue 2 years ago • 8 comments

As per the thread below, os crashes on Giga R1 when WiFiClient is declared as global.

https://forum.arduino.cc/t/call-to-server-available-fails-if-client-is-a-global-variable/1137604

megacct avatar Nov 07 '23 12:11 megacct

This seems to be caused by the way the assignment operator of WiFiClient is implemented:

https://github.com/arduino/ArduinoCore-mbed/blob/fee275d4c151ac16289b636944169c5a8e773a9b/libraries/SocketWrapper/src/MbedClient.h#L41-L62

When doing client = server.available() as in the linked example from the forum, stop() is called on the newly returned client object.

alranel avatar Nov 07 '23 17:11 alranel

@facchinm if I understand correctly the logic that this helper method implements, why don't we use shared_ptr instead?

alranel avatar Nov 07 '23 17:11 alranel

@facchinm @alranel guys, any update regarding this issue? This functionality is essential for me and a blocker to my GIGA migration. Thanks for all the work

megacct avatar Nov 13 '23 15:11 megacct

We are working on it, don't worry

facchinm avatar Nov 13 '23 15:11 facchinm

The root problem described is solved in https://github.com/arduino/ArduinoCore-mbed/issues/766, but there are more: status() is not returning WL_CONNECTED when it is connected. It's returning '1' which per wl_definitions.h is WL_NO_SSID_AVAIL. It did connect to a known SSID so this cannot be correct.

rickclemenzi avatar Dec 12 '23 16:12 rickclemenzi

@rickclemenzi client.status() doesn't return WL_ constants. it should return TCP states https://github.com/JAndrassy/Arduino-Networking-API/blob/main/ArduinoNetAPIDev.md#status-optional

JAndrassy avatar Dec 12 '23 16:12 JAndrassy

@JAndrassy Thanks and I hear you, but there is a significant disconnect here that needs clearing up. WiFi.status() per the online manual is clearly WL_... based, and WiFi.cpp from the mbed_giga library is WL_.. based as well (my address C:\Users\RC2\AppData\Local\Arduino15\packages\arduino\hardware\mbed_giga\4.0.10\libraries\WiFi). It seems there are two half separate library threads involved, but I don't see how the WiFi.cpp is not the one setting status in for WiFiClient. Sorry to be thick, but I don't see how all these facts fit together and would appreciate clarification. The documentation was 100% correct for my earlier ports to the Uno Wifi Rev 2.

Looking again I see there are actually 2 status() definitions at the link you gave -- one your link and https://github.com/JAndrassy/Arduino-Networking-API/blob/main/ArduinoNetAPIDev.md#status

rickclemenzi avatar Dec 12 '23 18:12 rickclemenzi

@rickclemenzi this issue is about the WiFiClient and the PR you linked is about Client and Server. why would you mention WiFi.status here?

JAndrassy avatar Dec 12 '23 18:12 JAndrassy