Triggering cameras from the command line using Python
Posted: Tue Mar 08, 2022 12:49 am
I spent several hours this evening trying to work out how to trigger a camera in Blue Iris from the command line without:
- reducing security for web access authentication
- sending passwords in URLs
- hard-coding any passwords in clear text in scripts
The only method I could find which met all 3 above requirements is using DDE. However there's not exactly a lot of documentation for how to do it. So after lots of trial and error, I came up with the following Python script which I can use to trigger one of my cameras.
Please feel free to comment on this - eg is there a better way. And please feel free to share it (if it's any good!).
- reducing security for web access authentication
- sending passwords in URLs
- hard-coding any passwords in clear text in scripts
The only method I could find which met all 3 above requirements is using DDE. However there's not exactly a lot of documentation for how to do it. So after lots of trial and error, I came up with the following Python script which I can use to trigger one of my cameras.
Please feel free to comment on this - eg is there a better way. And please feel free to share it (if it's any good!).
Code: Select all
# BEWARE: This needs to be executed as administrator - eg from a command window run as administrator
# or via a shortcut which runs as administrator, or invoked from an elevated program.
#
# I ran this from a 64-bit Python install. I don't know whether 32-bit will work or not given
# Blue Iris 5 is a 64-bit executable.
#
# From page 242 of the Blue Iris V5 manual...
# DDE INTERFACE
# A technology that is largely deprecated, yet a part of Blue Iris. A DDE service name BlueIris
# is created to listen for commands:
#
# topic item data function
# global signal 0, 1, or 2 set the shield icon to red, green, or yellow
# camera (shortname) ptzpreset=x move to PTZ preset position x
# trigger trigger the camera
# snapshot single snapshot to the database
# record toggle manual recording
# recstart start manual recording
# recstop stop manual recording
# reset reset camera
# enable enable camera
# disable disable camera
# schedule=1 or 0 enable or disable camera schedule override
# profile=x temporarily set camera override profile
# macro 1-999 (text) set macro number to specified text
# To instal win32ui and dde:
# pip install -U pypiwin32
import win32ui
import dde
import warnings
# Disable warning about: DeprecationWarning: PY_SSIZE_T_CLEAN will be required for '#' formats
warnings.filterwarnings("ignore", category=DeprecationWarning)
# We're running as a client, but we still create a server object.
# This is a PyDDEServer: http://timgolden.me.uk/pywin32-docs/PyDDEServer.html
server = dde.CreateServer()
# I don't think the name matters.
server.Create("BlueIrisClient")
# This is a PyDDEConv: http://timgolden.me.uk/pywin32-docs/PyDDEConv.html
conversation = dde.CreateConversation(server)
# As documented above:
# "BlueIris" is the service name.
# "camera" is the topic we need to trigger a camera.
conversation.ConnectTo("BlueIris", "camera")
if not conversation.Connected() == 1:
print("Connection failed")
sys.exit(1)
print("Connection established")
# The camera name is the short name from its settings
camera = "Porch" # or "Driveway" or "Garden"
# Send the "trigger" command to the camera.
conversation.Poke(camera, "trigger")
print("Trigger command executed")
# Not sure whether these are needed, but probably best to be safe.
server.Shutdown()
server.Destroy()
print("Done.")