Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By andre_teprom
#70045
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.
User avatar
By tele_player
#70059
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.
User avatar
By andre_teprom
#70067
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.