tchellomello / python-amcrest

A Python 2.7/3.x module for Amcrest and Dahua Cameras using the SDK HTTP API.
GNU General Public License v2.0
212 stars 76 forks source link

Restore config from backup #147

Open maximvelichko opened 4 years ago

maximvelichko commented 4 years ago

I can see that there is a config_backup() function that calls /cgi-bin/config.backup?action=all - which, in turn, retrieves a JSON with lots of settings.

I could not find how to import it back. The only thing that resembles import in https://s3.amazonaws.com/amcrest-files/Amcrest+HTTP+API+3.2017.pdf is configManager.cgi?action=restore - however it only accepts the list of names (and not JSON), and when I tried to run it (configManager.cgi?action=restore&names[0]=MobilePushNotification) I saw zero effect.

Do you know how is it supposed to work?

pnbruckner commented 4 years ago

@maximvelichko do you have a need to do backups and restores programmatically? Or would a UI manual operation suffice? I generally use the camera's web interface to save/restore configurations. Just open a browser using the camera's URL, log in, then go to Setup -> System -> Import/Export. Amcrest also makes "IP Config Software" (for Windows & MacOS) which I assume could do this (but I haven't tried it.) You can find it here: https://support.amcrest.com/hc/en-us/categories/201939038-All-Downloads

maximvelichko commented 4 years ago

@pnbruckner , yes, I need a programmatic method. (Something in the software Amcrest makes randomly disables motion detection for my camera. I need to detect it (I know how to do it) and revert it back (which I don't know how))

pnbruckner commented 4 years ago

Have you looked at the is_motion_detector_on() method and motion_detection setter in motion_detection.py? The former will return a bool indicating if motion detection is enabled. The latter takes a str of true or false (case insenstive) and enables motion detection accordingly.

maximvelichko commented 4 years ago

@pnbruckner , thanks for looking into it!

Yes, I am aware of is_motion_detector_on(), however it returns True when disabled and enabled. Probably, it is not called "motion detection". In the Android app it is under Push Notifications => Configuration. When enabled (like at the screenshot), it records video/jpegs when motion is detected, and an event is sent to the subscribers. When disabled, it does not record anything (no media records, no log events, no push notifications). The problem is that something resets it from time to time, and I have nothing to blame but Amcrest soft :-). And the problem is that I could not find any API to read/change it. When I save the backup, the settings are stored under MobilePushNotification - which is nowhere documented. But it is the only thing that changes in the config when these settings are updated

In the backup payload it is saved as the below, I have no idea whom this User information belong to, I guess it is service2service connection for Amcrest...

"MobilePushNotification" : { "Default" : null, " redacted " : { "AuthServerAddr" : "https:\/\/www.google.com\/accounts\/ClientLogin", "AuthServerPort" : 443, "Certificate" : "", "DevID" : " redacted uuid ", "DevName" : "amcrest1", "PeriodOfValidity" : 500654080, "PushServerAddr" : "https:\/\/fcmcellphonepush.ecosightsecurity.com\/fcm\/send", "PushServerMain" : { "Address" : "https:\/\/fcmcellphonepush.ecosightsecurity.com\/fcm\/send", "Port" : 443 }, "PushServerPort" : 443, "SecretKey" : "", "ServerType" : "Android", "Subscribes" : [ { "Code" : "FaceDetection", "Indexs" : [ 0 ] }, { "Code" : "VideoMotion", "Indexs" : [ 0 ] } ], "User" : " redacted " } },

image

pnbruckner commented 4 years ago

@maximvelichko

Yes, I am aware of is_motion_detector_on(), however it returns True when disabled and enabled.

This method is used in Home Assistant's integration, and I know it works.

Probably, it is not called "motion detection". In the Android app it is under Push Notifications => Configuration.

Yes, it seems you're talking about something else.

In the Android app it is under Push Notifications => Configuration.

I assume you mean Amcrest View Pro. I've used that app, but I've never gone under the Push Notifications menu.

I ran the backup command, and found this in my file:

   "MobilePushNotification" : {
      "Default" : null
   },

which makes sense since I have nothing set up there.

Do you know exactly what changes? Is it the whole MobilePushNotification dictionary, or just one item (or a few items) within it? And is it consistent? If so, you might be able to use

http://<server>/cgi-bin/configManager.cgi?action=setConfig&MobilePushNotification.blah.blah=<value>