Created
April 30, 2016 05:55
-
-
Save stenius/1821a2baa498fc7ef4974cf075f45080 to your computer and use it in GitHub Desktop.
connect to zoneminder and enable or disable the monitor and toggle the LED on an Axis camera
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
camera_ip = '127.0.0.1' | |
camera_password = '' | |
camera_username = 'root' | |
camera_url = 'http://%s:%s@%s/axis-cgi/param.cgi' % (camera_username, camera_pa> | |
zoneminder_ip = '127.0.0.1' | |
#get current camera status | |
url = 'http://%s/zm/api/monitors/1.json' % (zoneminder_ip,) | |
requ = requests.get(url) | |
monitor_info = requ.json().get('monitor', {}) | |
monitor_info = monitor_info.get('Monitor', {}) | |
monitor_status = monitor_info.get('Enabled', '0') | |
if '1' in monitor_status and 'Modect' == monitor_info['Function']: | |
camera_currently_enabled = True | |
else: | |
camera_currently_enabled = False | |
if camera_currently_enabled: | |
# turn off the camera in zoneminder and turn off the led on the camera | |
url = 'http://%s/zm/api/monitors/1.json' % (zoneminder_ip,) | |
data = {'Monitor[Function]': 'None'} | |
requ = requests.post(url, data) | |
camera_led_off_data = { | |
'action': 'update', | |
'root.StatusLED.Usage': 'off', | |
} | |
requ = requests.post(camera_url, data=camera_led_off_data) | |
else: | |
# turn on the camera in zoneminder and turn on the led on the camera | |
url = 'http://%s/zm/api/monitors/1.json' % (zoneminder_ip,) | |
data = {'Monitor[Function]': 'Modect'} | |
requ = requests.post(url, data) | |
camera_led_off_data = { | |
'action': 'update', | |
'root.StatusLED.Usage': 'on', | |
} | |
requ = requests.post(camera_url, data=camera_led_off_data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment