-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WiFi Library does not always disconnect when signal is lost (when socket buffer of one client is full) #180
Comments
Unfortunately, this is a consequence of the WINC1500 interface. If there's any data pending, the WINC1500 will not send any command responses until the host reads it and on the Mega there is limited RAM resources to buffer this data.
I have mixed feels, if |
I know that the root cause of all these points is the WINC1500 interface. But as far as I understood the code, the WiFi Library could at least recognize this situation and tell the application that nothing can be done until data from socket x are read (or the whole WiFi is disconnected/ended). Even if tracing to Serial is questionable, returncodes would be very helpful to allow the application to react on this situation. I think that a major part of the stability problems could be related to this issue. Regards, |
BTW: With the changes described above (and the change from #182) my application is running without any problems since months :) |
Hi,
I use an Arduino Mega with a WiFi shield (bluefly from Watterott, Firmware version 19.5.2) to cyclically measure temperature and light and send these data to Microsoft Azure.
I had stability problems with the usage of the WiFi-Library 0.14.3 (the WiFi signal strength is far from perfect), and sometimes the communication to the router gets lost and is not reestablished again.
I added serial port logging to the WiFi Library and found out that the reason is that if a socket receives data which is not read by the client, almost every WiFi action is blocked. OK, this is documented, and most probably related to #32, but my problem is that I do not know how I can react in my sketch.
What happens:
From time to time, additional data is received later and the client gets available again, and the socket buffer of this client gets full. If I do something different with the WiFi in the meantime, e.g. transmit an NTP request and wait for the response, or sending something to another client via http, this fails (at least receiving), because in
m2m_wifi.c / m2m_wifi_handle_events
always returns M2M_ERR_FAIL, and consequentlywifi_cb
is not called:(as you can see, I added a log to the serial port - the number of the socket where the buffer is full is written).
In this situation, also a WiFi disconnection will not be recognized, because the method
wifi_cb
will never be called, and therefore_status
will stay atWL_CONNECTED
forever.What I did: When I do not receive an expected response from reading (e.g. no UDP answer received, no HTTP answer received, I call
WiFi.disconnect();
This does not help, becausem2m_wifi.c / m2m_wifi_handle_events
is still blocked.So in the end, I did this:
This helped, a disconnection is always recognized, and the reconnection works as well.
I also tried closing all sockets via
WiFi._client[i]->stop();
before callingWiFiClass::disconnect()
, but also in this case the disconnect did not work. I do not understand why - it looks like there is simply no interrupt fired (I log a '+' inm2m_hif.c / static void isr(void)
, and this does not show up on the serial port in this situation). Maybe this has something to do with trying to write to WiFi whenSOCKET_BUFFER_FLAG_FULL
is true. Only the WiFi.End() solved the problem.I produced a (hopefully self-explaining) logfile. Flag: 3 means, that SOCKET_BUFFER_FULL is set:
I see the following issues around this problem:
m2m_wifi.c / m2m_wifi_handle_events
is ignored all over the WiFi Library. Esp. long-lasting timeouts likedo not make sense if some
SOCKET_BUFFER_FLAG_FULL
is true. There should be a "big" warning written to the serial port when this situation happens.WiFiClass::disconnect()
should close all the sockets before trying to disconnect the WiFi. This is done in wifi_cb when a disconnected-event is received (but only for WiFiClient, not for UDP and not for server), but to avoid the problem above all sockets should be closed beforeSOCKET_BUFFER_FLAG_FULL
is set to false only if the buffer is empty. Shouldn't it be set to false already if the free buffer is larger than the MTU-size?WiFiClass::disconnect()
work, when all sockets are closed?I can do some more investigations (normally I can reproduce the problem in some minutes), but before I would like to get some feedback if I am on the right track and you are interested in a solution.
And can somebody help me with adding logs to m2m_*.c, esp. in the ISRs? Logging one character is more than nothing, but it does not work always (when you write too much, some characters are lost).
If somebody is interested, the WiFi-Library with additional logging is here.
My sketch is here, but I did not reduce it (yet), it is not sooo small.
ArduinoAzureIotTemperature.zip
Thanks for any help/comments,
Klaus
The text was updated successfully, but these errors were encountered: