-->
Page 2 of 2

Re: How often is needed to check Wi-fi status ?

PostPosted: Sun Sep 17, 2017 4:10 am
by andre_teprom
eduperez wrote:Well, what happens to your application if it tries to send / receive some data, and the wifi is off?


The application would not detect any device, but this would just detect the problem, and I'm concerned on ESP8266's side. It is placed within a vending machine for which access is difficult.

Re: How often is needed to check Wi-fi status ?

PostPosted: Sun Sep 17, 2017 4:32 pm
by tele_player
andre_teprom wrote:
tele_player wrote:I don't know the answer, but it would only take a minute to write code to test the time spent in WiFi.status() .


I appreciate your kind help, but the suggested method based on pure experimentation instead of using a resource aware of its implications does not answer the raised question. I am not willing to deal with a situation that could work properly on an equipment (still at the limit of operability) and later the system does not work, and have to guess that I could have been overlooked this aspect; but again thanks for taking part in this debate.


Maybe I misunderstood your questions, and I didn't notice a debate.

Your question asked about the overhead of checking WiFi status in the main loop, this is easily determined experimentally. WiFi.status() takes about 1.5 seconds for 1000000 calls, when WiFi is connected. 1.5 microseconds is low enough to call it in Loop() without noticing the cost, unless your other code is operating at the limits of CPU capacity.

You have the source code for the libraries involved, if you care to look deeper into what is involved. At the lowest level, it might be in Espressif code for which source isn't published.

For the question in the subject, " How often is needed to check Wi-fi status ?", there really is no simple answer. Maybe your AP crashes a lot, or drops connections intermittently. Defensive programming would check the status before every attempt to use WiFi, and check the return codes of all WiFi calls. It's up to you to determine what is appropriate for your application.

Re: How often is needed to check Wi-fi status ?

PostPosted: Mon Sep 18, 2017 3:38 am
by andre_teprom
tele_player wrote:1.5 microseconds is low enough to call it in Loop()


I am very grateful for the measurement you made, sorry for my wrong assumption, but I thought that these values could lie within a much larger range e.g varying from some device to another, so I did not do it, and now your answer suggests that we can comfortably work with it.

As for the frequency to check this status, really as the cost of processing is low, I can actually do as you mentioned, whenever in the main loop I make access to the communication functions.

Thank you.