Ring: Motion Detection and new Ding Detection still not always working

Created on 26 Jan 2020  路  11Comments  路  Source: dgreif/ring

Bug Report

Describe the Bug

I'm still experiencing issue with the onMotionDetected and onNewDing events. I've using the same code for weeks now and it worked yesterday for a few hours, but today it is not working at all. I'm using the latest version of this API.

To Reproduce

Steps to reproduce the behavior:

  • subscribe to one of those events
  • check if it gets triggered or not

Expected behavior

It should just trigger the event when the camera detects a trigger.

Screenshots/Logs

I can add some if needed.

Additional context

None

Environment

  • OS: Windows Server 2019
  • Node.js: 11.14.0
  • NPM: 6.13.6
  • ring-client-api: 6.1.1
bug

All 11 comments

Update: I changed the pooling interval to 2 seconds instead of 1 and it seems to work for now. I will leave this open for now and test it for a week. I will update you guys if anything stops working again.

@ZerGo0 I was just going to ask what you had the polling interval set to, so thanks for commenting! I had looked into this a few weeks ago, and basically what I found is that the sessions will sometimes get unsubscribed from motion or ding events. To check if you are subscribed, you can look at camera.data.subcribed and camera.data.subscribed_motions. Those will stay up-to-date if you set a cameraStatusPollingSeconds value in your config. If either of them ever goes false, you can call camera.subscribeToDingEvents() and camera.subscribeToMotionEvents(). I do this automatically when the code first starts (https://github.com/dgreif/ring/blob/cde672d236becf7e3982a9cdb75b93ad0bc98583/api/ring-camera.ts#L134-L150), but if you have your process running for a long time, then your session could somehow unsubscribe from one or both of those. I'll think about adding code to keep an eye on those values and resubscribe if they _ever_ go false.

Regarding switching from 1 second to 2 seconds on polling, I am not sure if that would really make a difference. More likely, just stopping and restarting your code caused the re-subscribe calls to get sent which fixed things.

@ZerGo0 I was just going to ask what you had the polling interval set to, so thanks for commenting! I had looked into this a few weeks ago, and basically what I found is that the sessions will sometimes get unsubscribed from motion or ding events. To check if you are subscribed, you can look at camera.data.subcribed and camera.data.subscribed_motions. Those will stay up-to-date if you set a cameraStatusPollingSeconds value in your config. If either of them ever goes false, you can call camera.subscribeToDingEvents() and camera.subscribeToMotionEvents(). I do this automatically when the code first starts (

https://github.com/dgreif/ring/blob/cde672d236becf7e3982a9cdb75b93ad0bc98583/api/ring-camera.ts#L134-L150

), but if you have your process running for a long time, then your session could somehow unsubscribe from one or both of those. I'll think about adding code to keep an eye on those values and resubscribe if they _ever_ go false.
Regarding switching from 1 second to 2 seconds on polling, I am not sure if that would really make a difference. More likely, just stopping and restarting your code caused the re-subscribe calls to get sent which fixed things.

Ah okay, makes sense, I will probably just check those values periodically and resubscribe to the events if they change to false to see if that fixes it. Not 100% sure if that is the cause tho, I restarted my program a few times yesterday (I changed it from onMotionDetected to onNewDing) and it didn't even work after the restart. I will post my code latery but it's like 20 lines of code max I believe. There is not much room for error to be honest and like I said it works sometimes.

I'd suggest you add some code to monitor the subscribed and subscribed_motions values just to see if they are actually going false. I'm really not sure why that would happen, but it could be an oddity on Ring's end. Make sure you set cameraStatusPollingSeconds to something like 30 for every 30 seconds. If they are staying true, then this might just be a Ring bug causing those dings to not come through.

One other thought - Are you running multiple copies of the code side-by-side on the same computer? The way that Ring does the dings, it's a single queue of messages that can be picked up for a given device (in this case, whichever computer you are running the code on). If you have multiple copies of the same code polling for dings, only one of the threads will be able to grab any given motion/ding event. Is that possibly what's happening for you?

I'd suggest you add some code to monitor the subscribed and subscribed_motions values just to see if they are actually going false. I'm really not sure why that would happen, but it could be an oddity on Ring's end. Make sure you set cameraStatusPollingSeconds to something like 30 for every 30 seconds. If they are staying true, then this might just be a Ring bug causing those dings to not come through.

Sadly I don't have time during the week and I will have to add that this weekend. I will tell you how it goes.

Quick update on the situation: It doesn't seems to work today, I just test it a few minutes ago and nothing triggered. It has been inactive for quite a while (22 hours), could it be that Ring just disconnects you after some time?

EDIT: Actually the polling interval should send a heartbeat which means that it should theoretically not get disconnected for being inactive, right?

One other thought - Are you running multiple copies of the code side-by-side on the same computer? The way that Ring does the dings, it's a single queue of messages that can be picked up for a given device (in this case, whichever computer you are running the code on). If you have multiple copies of the same code polling for dings, only one of the threads will be able to grab any given motion/ding event. Is that possibly what's happening for you?

I'm only running one instance of my code. It runs on a server which automatically reboots every 24 hours, I'm not exactly sure how Ring handles that, but it disconnects for about a minute and then runs a new instance of my code after the reboot. I doubt that this is causing the issue tho.

@ZerGo0 for motion/ding events, there is no "connection" to keep alive. It makes an http request every cameraDingsPollingSeconds seconds. As long as you have that set to something in the range of 1-10, you should get results every time there is a motion/ding event.

@ZerGo0 I'm inclined to say that this is really an issue with your implementation. Likely a situation where there are multiple api clients being created on the same computer, causing a race condition where they are fighting to pick up the ding events and stealing them from each other. @marc2016 apparently ran into a similar situation in the ring ioBroker (which uses this package), and came to the conclusion that it had a bug where it created multiple clients, which caused the same issue you are seeing. If you can provide me with a concrete reproduction of the issue, I'm happy to take a look. Otherwise, I think this issue should be closed.

@ZerGo0 I'm inclined to say that this is really an issue with your implementation. Likely a situation where there are multiple api clients being created on the same computer, causing a race condition where they are fighting to pick up the ding events and stealing them from each other. @marc2016 apparently ran into a similar situation in the ring ioBroker (which uses this package), and came to the conclusion that it had a bug where it created multiple clients, which caused the same issue you are seeing. If you can provide me with a concrete reproduction of the issue, I'm happy to take a look. Otherwise, I think this issue should be closed.

I highly doubt that it is related to that, simply because I only ever run one instance of the code. I didn't have time to test it last week weekend, so I will close this for now and re-open it when I have more information.

@dgreif I had some time to test it and it seems like even after restarting the code it doesn't subscribe. I made it output the values that you mentioned and the following was outputted:
Preview

This is the code: https://pastebin.com/1zwD3JdE

EDIT: Actually which value do I need to check camera.initialData.subscribed or camera.data.subscribed?

EDIT2: After some more testing it seems like both values don't get updated unless you authenticate again and even onData doesn't get triggered when those values change. I tested it by calling camera.unsubscribeFromMotionEvents(); and subscribing to onData before that. I might be understanding something wrong, but I think this is is the cause of the issue. If those values change in runtime for whatever reason you couldn't even really check them unless you periodically log into your account and check the values of the desired camera. I'm not sure if Ring is okay with that...

If you set cameraStatusPollingSeconds, then camera.onData should fire events periodically with the most up-to-date value for those. camera.initialData.subscribed will never change, but camera.data.subscribed should always give you the latest value that came through onData. I'm sorry you are still having issues with this. I'm not sure why Ring would set those subscribed values to false after they get set true when this client starts up....

@ZerGo0 any updates? I'm at a loss for how to make this any better for you since I can't recreate the issue. If you figure something out, please open a PR

Was this page helpful?
0 / 5 - 0 ratings

Related issues

LordZork picture LordZork  路  5Comments

Lui5Jacint0 picture Lui5Jacint0  路  3Comments

ryanleesmith picture ryanleesmith  路  4Comments

donavanbecker picture donavanbecker  路  5Comments

steets250 picture steets250  路  5Comments