Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validation of downloaded snapshots #11

Open
scholzmichael opened this issue Aug 31, 2023 · 13 comments
Open

validation of downloaded snapshots #11

scholzmichael opened this issue Aug 31, 2023 · 13 comments
Assignees
Labels
Reviewing Item is being reviewed

Comments

@scholzmichael
Copy link

scholzmichael commented Aug 31, 2023

It often happens to me that the downloaded snapshots are not valid or corrupted, which has nothing to do with the tool I guess.

It would be great to actually check the downloaded files automatically and if corrupted get a fresh download. Don't know if this is possible but would be great.
What am I using the tool for: Downloading snapshots of my 4 devices every 5 minutes, copy the latest ones on my NAS so I can fetch the with my light manager and make them visible on the Cloud WebIF. Automatically delete all old jpeg except the latest one by using shellscripts and crontab.
I used iobroker before with the ring adapter, but every couple of days it stopped working, and I had to reboot the machine. All running on a raspi 4 with bullseye image.

By the way: fantastic work you delivered here!!!!!!!!!!!!!!!

@scholzmichael scholzmichael added the Reviewing Item is being reviewed label Aug 31, 2023
@KoenZomers
Copy link
Owner

Haven't encountered this myself yet @scholzmichael, but I have looked into adding such a thing and am testing a code change now that would add a feature to validate the downloaded image.

@KoenZomers
Copy link
Owner

KoenZomers commented Sep 2, 2023

Version 2.0.0.0 has a new -validateimage option. Can you give it a try and let me know if this works for you?

@scholzmichael
Copy link
Author

Hi @KoenZomers , thanx a lot, sure will try. Do I just need to exchange the files, or do I need to run it to get a new token?

@KoenZomers
Copy link
Owner

You should be able to just replace the executable. In rare scenarios I've seen it go haywire with the settings file. If that happens, just delete the settings file, run it again, go through the authentication process with multi factor authentication and you're all set for future runs.

@scholzmichael
Copy link
Author

Just started again with version 2.0.0.0 was forced to do 2 factor again, but ran without a problem, now check this:
Validating image... Failed: image content not recognized, retrying (1/3)
OK
Validating image... OK
OK
Validating image... OK
Done
seems to work like a charme, thanx a lot....great work!!!!

@KoenZomers
Copy link
Owner

Weird that it never happens to me. I also need to look at why it states to validate the image twice. Is this the exact output it gave you?

@scholzmichael
Copy link
Author

Yes, thats exactly what I got, copied from console when running my get_snapshots.sh:

#!/bin/bash
cd /opt/iobroker/iobroker-data/files/ring.0
./RingSnapshotDownload -username user -password PW -deviceid XXXXXXXX -forceupdate -validateimage -out cocoa_XXXXXXXX
./RingSnapshotDownload -username user -password PW -deviceid XXXXXXXX -forceupdate -validateimage -out cocoa_XXXXXXXX
./RingSnapshotDownload -username user -password PW -deviceid XXXXXXXX -forceupdate -validateimage -out doorbell_XXXXXXXX
./RingSnapshotDownload -username user -password PW -deviceid XXXXXXXX -forceupdate -validateimage -out doorbell_XXXXXXXX
exit
could be that one of the cameras is taking a video at the time of the corrupted download, surely has nothing to do with your code, rather with the api, since the iobroker ring adapter had the same problem spradicly...

@scholzmichael
Copy link
Author

by the way, running the .sh every 5 minutes via crontab, if you have longer times in between you migt not recognise the issue...

@scholzmichael
Copy link
Author

scholzmichael commented Sep 3, 2023

New problem, it seems that with every run a 2f authentikation is requested, getting new security codes from ring via sms every time...
Using settings from /opt/iobroker/iobroker-data/files/ring.0/Settings.json
Connecting to Ring services

Authenticating using provided username and password
Two factor authentication enabled on this account, please enter the Ring token from the e-mail, text message or authenticator app:

just happened again, need to stop I guess before ring throws me out...

went back to 1.3

@KoenZomers
Copy link
Owner

Weird. Did some testing here both on Windows as well as on Linux and I cannot reproduce. Also didn't change anything in that area in the last releases. Here it works consistently well. Even if I let it loop with 5 seconds pauses in between, no problems, no corruptions, no MFA tokens requested. Could it be that the user you run the script with doesn't have write permissions to the directory or the Settings.json file? After a run where you authenticate with MFA, do you see that Settings.json gets updated and shows a base64 encoded value for RingRefreshToken which starts with ey? If that's not the case, the tool cannot write to the file. Check your chmod permissions. If it does update the Settings.json file, on a next run, the tool should report Authenticating using refresh token from previous session and take that refresh token to authenticate. You can also examine that refresh token using jwt.ms. If you paste it in there, it should show you that its a Ring refresh token.

@scholzmichael
Copy link
Author

scholzmichael commented Sep 5, 2023 via email

@scholzmichael
Copy link
Author

scholzmichael commented Sep 6, 2023

OK, getting in again, testing your version 2.1.0.0 manually so that I don't get thrown out again :)
I will comment here if the tool does another 2FA again, now I found the following:

If the jpg is validated as corrupt it downloads it twice according to log, but does not save it to the specified folder:

Using settings from /opt/iobroker/iobroker-data/files/ring.0/Settings.json
Connecting to Ring services
Authenticating using refresh token from previous session
Requesting Ring device to capture a new snapshot
Downloading snapshot from Ring device with ID XXXXXXXX... OK
Validating image... Failed: image content not recognized, retrying (1/3)
Downloading snapshot from Ring device with ID XXXXXXXX... OK
Validating image... OK
Downloading snapshot from Ring device with ID XXXXXXXX... OK
Validating image... OK
Done

what it shoud do at the end is:

Requesting Ring device to capture a new snapshot
Downloading snapshot from Ring device with ID XXXXXXXX... OK
Validating image... OK
Saving image to cocoa_XXXXXXXX/XXXXXXXX - 2023-09-06 08-01-03.jpg... OK
Done

according the .sh I created:

nload -username [email protected] -password password -deviceid XXXXXXXX -forceupdate -validateimage -out cocoa_XXXXXXXX

So it saves it only to the specified folder if the first validation was ok...

@scholzmichael
Copy link
Author

scholzmichael commented Sep 6, 2023

so, I could now reproduce the 2FA problem, seems to start after 1-2 hours running with no problem. When requesting a simple "-list" manually I get this:

Using settings from /opt/iobroker/iobroker-data/files/ring.0/Settings.json
Connecting to Ring services
Authenticating using provided username and password
Two factor authentication enabled on this account, please enter the Ring token from the e-mail, text message or authenticator app:
XXXXXX
Retrieving all devices... 4 found

So something def. changed from 1.3.0.0 to 2.0.0.0 (2.1.0.0), settings.json suddenly shows "RingRefreshToken":null"

Is perhaps the case that a new token is needed, but not pulled? Could also be that it only uses user and pw, not the token when moving on...

Seems to happen after time, shortly after doing the above I did a "-list" again and received the following output:

Using settings from /opt/iobroker/iobroker-data/files/ring.0/Settings.json
Connecting to Ring services
Authenticating using refresh token from previous session
Retrieving all devices... 4 found

very strange, I'll wait now for 2 hours and try again....

07.09.2023

Ok, comming closer, started automatic download at 8:50h via crontab, 8 refresh Jpgs were downloaded from each ring device, and everything worked till 9:35h, then I received SMS from Ring with 2FA code, checked settings.json, entry here suddenly shows: "RingRefreshToken":null", every other data such as username and password are still in there.

So somehow without me touching, the token was deleted from settings.json, which ended up in requesting new 2FA code.

Stopped again before account gets locked again.

I guess something must be different from V1.3.0.0, please check for deleting token in your code...

By the way, the settings.json showed last modification and last permission change also at 9:35, but since I did set it to 777 before start I could not find a change in permissions

Went back to 1.3.0.0 running fine and stable now for approx. 7 hours

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Reviewing Item is being reviewed
Projects
None yet
Development

No branches or pull requests

2 participants