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

Doorbell mystery #294

Closed sim404 closed 1 year ago

sim404 commented 1 year ago

Hi, I've been using the doorbell example for more than a year and 99.999% of the time it works just fine, thank you. However, after approx 2months of perfect running it stops responding to a door press (both my physical bell press, and, if I tap 'press' in the sinricpro app). This has happened several times and I estimate once every 1 to 2 months. Its no big deal but it is an irritating mystery. Once in the uncooperative state the only solution is a hard reset.

After the first occasion and because I couldn't find a cause I put some Telegram messaging around the button press code and from that I know for sure that its running through the standard example code: [SinricProDoorbell& myDoorbell = SinricPro[DOORBELL_ID]; // get doorbell device back. myDoorbell.sendDoorbellEvent(); // send doorbell event]

I also know that wifi and sinric are connected because I have leds around both and my other separate but same location esp32 sinric stuff is working fine during).

The only clue I have is that when I look on the app it says the device is online but when I tap 'press' it says "Device did not handle setPowerState". The question that's driving me nuts is why is it not handling it. I've had a rummage through the doorbell related include files but couldn't find a suspect. Anyway, quite frankly the code is way out of my league.

I would welcome your comments on what the cause of the mystery might be. Thanks for reading. Regards, Steve

sivar2311 commented 1 year ago

Hello @sim404

Thank you for the detailed report! It is indeed a bit puzzling. Are the intervals different or are they always the same?

sivar2311 commented 1 year ago

I have a guess as to what it might be related to.

Please check the Activity Log in the SinricPro Dashboard for error messages.

sim404 commented 1 year ago

Sivar, Thanks for quick response. I'm not sure if its the same duration. I had been recording the device boots on telegram messages but the messages got deleted (another story). It is however always a few weeks. I initially thought the problem might be a millis() rollover arithmetic problem somewhere but I don't use millis() except in the button press code. Do you mean the Activity Log in the App?? Attached a screen shot but it doesn't say much so wondering if you mean a different log?

IMG_2743

sivar2311 commented 1 year ago

I actually meant the log on the website (https://portal.sinric.pro/dashboard) which will probably be the same log. It would be interesting to see the log entries when the doorbell stops working.

It will probably be a roll-over problem (millis is used internally in the SDK). The doorbell device (and all devices that only send events) are a "special case" that I became aware of through your problem.

Background: The ESP must send a Unix timestamp to the server when sending events. The initial time is sent from the server to the ESP when connecting to the Sinric server. The ESP stores this "initial" timestamp and calculates subsequent timestamps using millis(). (Unfortunately, the ESP does not have an RTC). When the ESP receives a request from the server (e.g. PowerState, PowerLevel etc.) the initial time stamp is updated. However, these requests never occur with a doorbell. The "Initial" timestamp is therefore never updated. At some point, millis() overflows and the ESP and the server are no longer synchronised. For this reason, the server will not accept the event from the ESP.

I will work on a solution for this.

sim404 commented 1 year ago

Ok I looked on the dashboard but as you will know it only shows last 3days or 200activities. The last issue was way before that. My math says normal millis() rollover is approx 49days so that would be about right for what is happening. Thanks for the synopsis of the issue/cause and for taking the time to investigate. Really impressive that you figured it out so quickly! Thanks again.

sivar2311 commented 1 year ago

Hi @sim404!

b40d271 should fix the problem. I have just released version 2.10.1. Please update to 2.10.1 when you get a chance.

(It may take a few hours until this version is available via the Arduino Library Manager / PlatformIO Libraries).

sim404 commented 1 year ago

Sivar, many thanks. I’ll update tomorrow. Regards, Steve

sivar2311 commented 1 year ago

Hi @sim404 ! It turned out that there was still a bug in version 2.10.1 concerning the timestamp. This bug has been fixed in version 2.10.2 which should be available in the Library Manager in a few hours.

sim404 commented 1 year ago

Sivar, Thanks for letting me know. I’ll use 2.10.2 when cooked.