Go Down

Topic: ScanNetworks seems to disconnect established TCP connections ? (Read 3177 times) previous topic - next topic

Aybert

Hi there

I recently ported a well working project from Arduino Uno to the Arduino Uno Wifi. So far so good.
The Arduino connects well to my Wifi AP and establishes properly a TCP socket to my server. Data exchange performs well both ways.
Then in the suite of events I happen to perform a ScanNetworks; which terminates well (I can see the expected output on the serial line)
But then I cannot write anymore to the TCP socket, which seems disconnected.
Any clue ?
Thanks

Aybert

I manage to isolate the interesting part of the code (full project available on github - see link from my profile)


in setup :

WiFiClient WiClient;

...

WiFi.begin(ssid[CurrentAP].c_str(), pass[CurrentAP].c_str());
WiClient.connect (host, port);

// all is fine, i can read, write as necessary

...

ecran.print (WiClient.status()); // output shows 4
numSsid = WiFi.scanNetworks();
ecran.print (WiClient.status()); // output shows 0

I do not know where to find the return value meanings for the status method, but I bet 0 means something like disconnected. The fact that the status changes is itself not good sign...
Any WiClient.write I perform later returns 0.

Someone knows how to scan without disconnecting established connections ? I remember playing with an ESP8266 directly, I could switch from Data to Command mode back and forth without such issue...

Aybert

Solved

Actually, ScanNetworks does disconnects the WIFI from the Access Point.

So in order to have everything work fine I close the socket first, perform the scan, reconnect to the AP and then the socket itself :

WiClient.stop();
...
numSsid = WiFi.scanNetworks();
...
WifiStatus = WiFi.begin(ssid, pass);
...
WiClient.connect (host, port);


On the other side, I also closed the socket properly, then perform an accept to wait for the arduino to reconnect.

This behaviour of ScanNetwork is different here than other WIFI chips I had tested, and is not documented. Once you know it...

Go Up