Python server/script to receive alerts from IPCAM branded camera (hichip) and others supporting "alert server"

If you've made a patch to quick fix a bug or to add a new feature not yet in the main tree then post it here so others can try it out.
Post Reply
User6677
Posts: 20
Joined: Sat Dec 24, 2022 9:32 am

Python server/script to receive alerts from IPCAM branded camera (hichip) and others supporting "alert server"

Post by User6677 »

I wrote this python3 script to test how good (or bad) my camer's "Smart AI" person detection is. Long story short, it is pretty bad (better than non AI motion detection in ZM, but still not as good as GPU based AI detection).

The script runs a server on port 8080. It listens for HTTP GET connections from cameras on on any url. The cameras send a HTTP GET and a couple of variables, username and userpwd. These are checked against the config as minimum kind of "auth" (its not very secure as this is sent in cleartext, but its acceptable on an isolated VLAN).

So the script listens for connections (it supports many connections at the same time), when it receives one it triggers ZM alert using zmtrigger's telnet server. If in a defined amount of time (90s/75s in my case) it doesn't get another alert from the camera it cancels the ZM alert. otherwise it extends the time.

How does it know which monitor to trigger? There is a config file that matches monitor names, ids and ip addresses.

The config file looks like this:

Code: Select all

user: "exampleUser"
password: "examplePassword"
zmtriggerhost: "127.0.0.1"
zmtriggerport: 6802
logpath: "/var/log/zm/trigserver.txt"
log_file_size_limit: 2048576  # Example size in bytes
max_threads: 20
monitors:
  Entrance:
    ip: '192.168.1.108'
    id: 3
    expiry: 90
    note: "This is a note for monitor3."
  Exit:
    ip: '192.168.1.109'
    id: 4
    expiry: 70
    note: "This is a note for monitor4."
    
The config values are hopefully self explanatory.

All my cameras either have an option to configure "alert server" via their interface, or they support cgi config, where one can send a request to the camera (after authenticating) to this address:
http://192.168.1.108/cgi-bin/hi3510/par ... &-as_info=

and then to enable it:
http://192.168.1.119/cgi-bin/hi3510/par ... -switch=on

To disable it:
http://192.168.1.119/cgi-bin/hi3510/par ... switch=off

These are hichip A series IPCAM branded cameras, but I believe a lot of other cameras that support hi3510 cgi interface should work the same. The python script is attached. You only need to install pyyaml for it to work. It expectrs to find its config in /etc/zm/trigserv.yaml

Sadly, despite "person AI detection" it still triggers for, fo rexample snow in the night". If the sensitivity is set low enough not to trigger on snow or bugs in the night, it then doesn;t reliably trigger on peolpe during the day, but still I'm posting this in hope it is useful to someone. Perhaps with better cameras.
Attachments
trigserv.zip
(2.78 KiB) Downloaded 118 times
Post Reply