sinricpro / esp8266-esp32-sdk

Library for https://sinric.pro - simple way to connect your device to Alexa, Google Home, SmartThings and cloud
https://sinric.pro
Other
234 stars 124 forks source link

SinricPro handler blocked by millis() function (or Blink Without Delay concept) in loop() #267

Closed mareskav closed 2 years ago

mareskav commented 2 years ago

Hi there!

Could I ask you for help please? I ran into a problem where I am not able to run SinricPro.handle() together with millis() and Blink Without Delay example (https://www.arduino.cc/en/Tutorial/BuiltInExamples/BlinkWithoutDelay). It looks like that millis() function is too much blocking SinricPro task in loop(), so it stops to response to my switch button ON / OFF clicks.

My goal is to keep running ESP 8266 for an hour (before ESP.deepSleep(fooTime) will be called) and enjoy SinricPro websocket communication with Google Home. I saw a few examples of non-blocking codes here in issues, but couldn´t find anything what could solve my problem. Is it maybe job for Cooperative Multitasking? 🤔

I went through a few code iterations, so not posting the code, but I can show an example if it would be helpfull of course. Basically, I just want:

Btw, thank you for the great work with SinricPro library! It´s amazing and soo easy to use! ❤️

sivar2311 commented 2 years ago

Hi @mareskav!

Neither millis() nor SinricPro.handle() block the sketch.

Basically, SinricPro.handle() is responsible for processing incoming requests and calling the corresponding callback functions of the devices. It is also responsible for sending the events of the devices to the SinricPro server.

I could only think of two scenarios that would lead to blocking:

In general, your project can be implemented without any problems.

mareskav commented 2 years ago

Thank you for quick response @sivar2311 ! And sorry for my slow one.

I tested several iterations of my code and I concluded that:

Thank you for hints! I guess I should take care of "Your sketch sends excessive events. In this case an artificial delay takes place to protect the SinricPro server from flooding. This is made visible with a corresponding serial output." in the future. Especially when I would decide to handle more devices at once and in short time.

mareskav commented 2 years ago

I guess I can close this. Thanks again!