我正在安装一个系统来监控一些传感器,并根据它们打开/关闭几盏灯。
为了进一步的数据分析,我们还想将该数据发送到中央服务器,因此我们添加了 Wifi 屏蔽。 请记住,如果没有网络,系统应该可以正常运行。所以我所做的是在 loop() 中监视网络状态,如果它出现故障则再次连接。
现在,问题是 Wifi.begin() 会阻止执行,直到连接或抛出错误。 这是 Not Acceptable ,因为在此期间系统将没有响应。
我研究过在 Arduino 中使用线程,例如 here ,但是这会出现在限制中:
One of the major potential problems with this library is the fact that a single Thread that gets hung will lock the entire system up, since the next Thread can’t be called until the current one finishes its loop() function.
那么,任何人都有任何指示、想法或经验吗?
谢谢,
胡安
最佳答案
您可以创建一个计时器中断,当超时时使用停滞的阻塞函数杀死线程。
实际上你可能想使用中断,例如 Timer1 library执行关键更新。这样您就无需担心在任何地方阻塞代码。
https://stackoverflow.com/questions/15293602/