-->
Page 1 of 3

Code for non-blocking tasks and shaky WiFi

PostPosted: Mon Oct 02, 2017 1:29 am
by UrsEppenberger
Hello

I do home automation with ESP8266 devices, some bought from sonoff, some homebuilt stuff based on ESP-201. I use MQTT as the communication relay between the node-red based backend and the devices.

For some applications I have the requirement that the device should always do its main tasks independently if WiFi or even MQTT are up and running. For this I wrote some code as a framework to be reused in the various devices I have. I'd like to share this code. It might be useful for someone else, but hopefully I get some feedback to improve it.

Kind regards,

Urs.

Re: Code for non-blocking tasks and shaky WiFi

PostPosted: Mon Oct 02, 2017 8:52 am
by mrburnette
Just a reminder that user code in the section:

// start section for main tasks
// ...
// end of section for main tasts

MUST execute quickly such that the loop section as a whole runs less than 30mS *. non-OS needs to feed the native ESP8266 regularly to keep the RF section happy. Of course, you can alternately use delay() or yield() to force the non-OS task switcher to give some time to the native code task.

https://github.com/esp8266/Arduino/issues/2021
https://learn.sparkfun.com/tutorials/es ... uino-addon
https://github.com/esp8266/Arduino/issues/3042
https://github.com/esp8266/Arduino/issues/1410

Notes:
* I have seen numbers on the Internet ranging from 15mS to 50mS ... the 50mS coming from this reference:
http://esp8266.github.io/Arduino/versio ... rence.html


Ray

Re: Code for non-blocking tasks and shaky WiFi

PostPosted: Mon Oct 02, 2017 9:10 am
by UrsEppenberger
excellent feedback, many thanks. Exactly what I have been looking for.
Kind regards,
Urs.

Re: Code for non-blocking tasks and shakey WiFi

PostPosted: Wed Oct 04, 2017 8:14 am
by UrsEppenberger
I made an update of the code based on received comments.
I'm not a professional programmer. I do frankensteining code together, but only code I do understand. And I try to add some more thinking.

Feedback is welcome.

Kind regards,

Urs.