Git Product home page Git Product logo

cameraevents's Introduction

Hi there ๐Ÿ‘‹

cameraevents's People

Contributors

kanhub02 avatar mcdamo avatar psyciknz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cameraevents's Issues

Question: Names of the IVS configurations

Hi,

very cool script. It runs very stable for me in a docker container and sends the events from my Dahua IPC cameras to HomeAssistant. Is it possible to get the names for the configured lines and regions through MQTT? I would like to know, from which configured region or line the detected events come.

image

[enhancement] Patch to add auth support for MQTT

This should add support for broker authentication. Make sure 'user' and 'password' are present in the right section for the config.ini file.

No error checking added, err=5 or so when auth fails. Quick hack that works for me.

diff --git a/CameraEvents.py b/CameraEvents.py
index f5f632e..21adc39 100644
--- a/CameraEvents.py
+++ b/CameraEvents.py
@@ -312,6 +312,7 @@ class DahuaEventThread(threading.Thread):
         self.basetopic = mqtt["basetopic"]
 
         self.client = paho.Client("CameraEvents-" + socket.gethostname(), clean_session=True)
+        self.client.username_pw_set(mqtt["user"], mqtt["password"])
         self.client.on_connect = self.mqtt_on_connect
         self.client.on_disconnect = self.mqtt_on_disconnect
         self.client.message_callback_add(self.basetopic +"/+/picture",self.mqtt_on_picture_message)
@@ -529,6 +530,8 @@ if __name__ == '__main__':
         mqtt["IP"] = cp.get("MQTT Broker","IP")
         mqtt["port"] = cp.get("MQTT Broker","port")
         mqtt["basetopic"] = cp.get("MQTT Broker","BaseTopic")
+        mqtt["user"] = cp.get("MQTT Broker","user")
+        mqtt["password"] = cp.get("MQTT Broker","password")
         dahua_event = DahuaEventThread(mqtt,cameras)
 
         dahua_event.start()

Invalid authority

I have this working correctly for my dahua cameras - https://github.com/psyciknz/CameraEvents
It is working and publishing to mqtt, however it doesn't work with my amcrest camera.

Config.ini

[MQTT Broker]
IP: 192.168.1.99
Port: 1883
BaseTopic = dahua

[Cameras]
camera1=babycam

[babycam]
host=192.168.1.90
protocol=http
name=babycam
port=80
isNVR=False
user=admin
pass=xxx
auth=basic
events=VideoMotion,CrossLineDetection,CrossRegionDetection,LeftDetection,SceneChange,TakenAwayDetection,FaceDetection,RioterDetection,MoveDetection,WanderDetection,CrossFenceDetection,ParkingDetection,NumberStat,RetrogradeDetection,TrafficJunction,VideoBlind,AudioAnomaly,AudioMutation,VideoAbnormalDetection,SceneChange,LoginFailure

Error log:

2020-07-02 12:02:28,496 - __main__ - DEBUG - [babycam] OnDisconnect(Success)
2020-07-02 12:02:33,658 - __main__ - DEBUG - [babycam] OnDisconnect(Success)
2020-07-02 12:02:38,921 - __main__ - DEBUG - [babycam]: Error
Invalid Authority!

Note: I have https set to disabled in the amcrest setup and I added the server as a trusted IP.

IP Camera unreachable after a while

Hello,
First, thank you very much for CameraEvents, this is very useful for my home system.

I have a strange problem - and this might not be related to CameraEvents strictly.

I just purchased a Dahua IPC-HDW1320S camera. It works fine with CameraEvents.

First I tested event recording etc. with an FTP server on Windows, and I also watched the rtsp stream, or the live webview in the browser all day long.
From time to time, the camera became unreachable from the Windows computer only (I could reach it from other computers). Changing the computer's ip address did help.

Now I am trying to have alerts sent to phone, etc. So I set up an ubuntu server, mosquitto, CameraEvents running on it. Also, the FTP server is now on the ubuntu server.

The same problem happened: CameraEvents shows via mqtt that the camera is offline. I could not ping it from the server, but it was fully reachable and working from other machines. Rebooting the camera did not help. So I rebooted the ubuntu server, and that helped.

The only similarity between the Windows and the Ubuntu server situation is that the camera writes to a ftp server, and there are many(?) cgi reqests toward the camera.

Sorry for posting such an offtopic issue, I have no idea where to turn with this!

Configure Home Assistant to receive image

Do anybody know, how I have to configure home assistant to receive the image, which is sent by CameraEvents?

My Payload looks like documented:

{"message": "IVS: Dahua3: CrossRegionDetection", "imagebase64": "/9j/4AAQSkZJRgA..."}

My configuration:

camera:
  - platform: mqtt
    topic: CameraEvents/Dahua3/Image
    name: my mqtt camera image

When the image is sent by CameraEvents, the sensor in home assistant shows idle the whole time and nothing is logged. I think, I have to reference the imagebase64 attribute. But I don`t know how. Anybody have success with a camera mqtt sensor in home assistant?

"alerts" config parameter ignored

The script reads the alerts parameter in line 100:
self.alerts = device_cfg.get("alerts")

but then overwrites this in line 563:
self.alerts = True

I set alerts to False because I don't want this process to pull a snapshot image and publish large images as MQTT messages. There is also a known issue with the Dahua snapshot functionality that at times returns an internal server error after a long wait causing the event messages to be delayed. Thanks for sharing your work, it makes my cameras excellent motion detectors!

Supporting additional audio events

Was hoping to add support for audio events for my amcrest camera

[MQTT Broker]
IP: 192.168.1.99
Port: 1883
BaseTopic = dahua

[Cameras]
camera1=babycam

[babycam]
host=192.168.1.90
protocol=http
name=babycam
port=80
isNVR=False
user=admin
pass=xxx
auth=basic
events=VideoMotion,CrossLineDetection,CrossRegionDetection,LeftDetection,SceneChange,TakenAwayDetection,FaceDetection,RioterDetection,MoveDetection,WanderDetection,CrossFenceDetection,ParkingDetection,NumberStat,RetrogradeDetection,TrafficJunction,VideoBlind,AudioAnomaly,AudioMutation,VideoAbnormalDetection,SceneChange,LoginFailure

amcrest01

amcrest02

2020-07-02 12:17:30,651 - __main__ - INFO - Loading config
2020-07-02 12:17:30,652 - __main__ - DEBUG - Device babycam Getting channel ids: http://192.168.1.90:80/cgi-bin/configManager.cgi?action=getConfig&name=ChannelTitle
2020-07-02 12:17:30,741 - __main__ - INFO - Created Data Device: babycam
2020-07-02 12:17:30,741 - __main__ - DEBUG - Added Dahua device at: http://192.168.1.90:80/cgi-bin/eventManager.cgi?action=attach&codes=%5BVideoMotion,CrossLineDetection,CrossRegionDetection,LeftDetection,SceneChange,TakenAwayDetection,FaceDetection,RioterDetection,MoveDetection,WanderDetection,CrossFenceDetection,ParkingDetection,NumberStat,RetrogradeDetection,TrafficJunction,VideoBlind,AudioAnomaly,AudioMutation,VideoAbnormalDetection,SceneChange,LoginFailure%5D
2020-07-02 12:17:30,741 - __main__ - DEBUG - Connecting to MQTT Broker
2020-07-02 12:17:30,742 - __main__ - DEBUG - Starting MQTT Loop
2020-07-02 12:17:30,742 - __main__ - INFO - Connected to MQTT OK Returned code=0
2020-07-02 12:18:20,857 - __main__ - DEBUG - Heartbeat: 2020-07-02 12:18:20.857747
2020-07-02 12:19:10,970 - __main__ - DEBUG - Heartbeat: 2020-07-02 12:19:10.970026

2020-07-02 12:40:27,102 - __main__ - INFO - Snapshot Url: http://192.168.1.90:80/cgi-bin/snapshot.cgi?channel=0
2020-07-02 12:40:35,270 - __main__ - DEBUG - [babycam]: --myboundary
Content-Type: text/plain
Content-Length:78
Code=VideoMotion;action=Stop;index=0;data={
   "RegionName" : [ "Region1" ]
}
2020-07-02 12:40:35,271 - __main__ - INFO - Video Motion received: babycam Index: 0 Code: VideoMotion

Add Dahua VTO support

Is it possible to add support for VTO. It is necessary to open the door and track the click of a button.

small bug fixes

First, thanks for this great piece of work! It is exactly what I was looking for.
Here are two small points that I noticed when I wanted to install it on my Openhabian:

1.) Missing encoding at the beginning:
As your file is UTF-8 and there is no declaration at the beginning, others might get errors. Adding the following line to the top of the file fixes this:
# -*- coding: utf-8 -*-

2.) ConfigParser for python2.7 does not understand "fallback":
That means the current version is not compatible with python 2.7.

Cannot connect to Amcrest NVR

I have a newer NV4216E-AI NVR and cannot connect with message "Invalid Authority"
The API seems identical to previous models, and I can also use /cgi-bin/eventManager.cgi?action=attach&codes=[VideoMotion] and get the expected Code=VideoMotion,Start/Stop etc when using in browser.. it seems it is not authenticating properly as I get this message:
`INFO:main:Connected to MQTT OK Returned code=0
2020-09-10 16:03:59,284 - main - INFO - Connected to MQTT OK Returned code=0
INFO:main:Connected to MQTT OK Returned code=0
2020-09-10 16:04:01,179 - main - DEBUG - [NVR]: Error
Invalid Authority!

DEBUG:main:[NVR]: Error
Invalid Authority!

2020-09-10 16:04:01,180 - main - DEBUG - [NVR] OnDisconnect(Success)
DEBUG:main:[NVR] OnDisconnect(Success)
`
I'm hoping you could tell me what I could do to troubleshoot the issue. I read in a zoneminder forum about issues with PTZ commands needing to be sent twice as it would fail for authentication the first time then work on the second. I really don't know where to start..

No snapshot published to MQTT

This issue might be cause by my lack of understanding of some technicals.

I run couple of Dahua cams. All are standalone with no NVR and no SD card in it as of now.

My config looks like this

[MQTT Broker]
IP=X.X.X.X
Port=1883
User=user
Password=pass
BaseTopic=CameraEvents
PostImagesToMQTT=True

All works fine except no snapshot published to MQTT. The log looks ok to me.

2021-01-28T09:39:36.722272118Z 2021-01-28 10:39:36,721 - __main__ - INFO - Snapshot Url: http://X.X.X.X:80/cgi-bin/snapshot.cgi?channel=1
2021-01-28T09:39:39.040760549Z 2021-01-28 10:39:39,040 - __main__ - DEBUG - [CarDriveway]: --myboundary
2021-01-28T09:39:39.040814667Z Content-Type: text/plain
2021-01-28T09:39:39.040829252Z Content-Length:958

URL for snapshot is correct. If I paste it to the browser I get the snapshot. But nothing on MQTT topic.

AlarmLocal on NVR

Ok, I just tried and it works but not as I like.
I'm trying the NVR with one camera only and CameraEvents connects to it and to my mqtt broker.
But when I tryed a input alarm on the NVR I saw these command on mqtt:
CameraEvents/CAM-05/NVR = AlarmLocal
Now two things that I don't know:

  1. why the NVR is listed under the camera name?
  2. the alarm doesn't turn off when I close the alarm connected to the NVR input (but I see in the NVR log that alarm goes off)
    This becomes useless because my domotic hub knows when an alarm starts but not when it ends.

Can you help me?

My config reflects your example: I haven't listed the camera channels and I don't add the snapshotoffset

Originally posted by @valepe in #4 (comment)

Can not find config file when executet from another directory

It seems, when executed from another directory, the script can not find the config file. I run it from crontab with absolute path to the script. At the moment I first have to change into the directory where CameraEvents.py is located and then I can start it.

Another finding is, that I can not stop the running script with CTRL+C. I have to kill it from the shell.

The script is quite useful. Thanks for creating it.

Missing IVS events

I added support for broker authentication, and then tested on my local setup.

It seems the IVS events are missed for the most part.

We tested multiple times and while the email alerts triggered consistently for the IVS tripwires and such, CameraEvents failed to acknowledge the events except for one time only.

Travis Build failing for armv6/7 arm64 images

error: failed to solve: rpc error: code = Unknown desc = executor failed running [/dev/.buildkit_qemu_emulator /bin/sh -c pip install -r /opt/cameraevents/requirements.txt]: exit code: 2
The command "./.travis/deploy.sh" exited with 1.

Only happens in arm32v6/7 and arm64. AMD 64 builds quite happily.
First seen in :#22

No issue: Learn Python; how does this script actually work?

Hello psyciknz,

I am newbie to Python and try to read and understand your script (especially the connection part) for learning purpose.
Can you explain me how it is coded and what is does?

Looking at:

while 1:

Does this script make a HTTP request (by Pycurl) every second (polling) to the Dahua NVR connected to the Dahua eventhandler service and translates the JSON output of the HTPP request (if responsecode = 200) to MQTT events?

If yes, doesn't this frequent traffic request stresses out the NVR cpu?

Invalid Syntax on Raspbian

I've HA working on Raspbian. I've copied your folder in the custom_components, created the config file, then installed the requirements from the virtual environment but...when I try to execute the py file that error happens:
python CameraEvents.py File "CameraEvents.py", line 282 except Exception,ivsExcept: ^ SyntaxError: invalid syntax

I seen that at line 282 there's a debug line but I can't understand the error. What could be wrong? Could you help me?
Thank you very much!

Configuration: channels index range

In your configuration example you refer to a channel list if the nvr can't retrieve that.

Is this list 0 based even if the first camera is indexed as 1 on nvr?
Example of a camera routed by the nvr:
mjpeg_url: "http://IP_NUMBER/cgi-bin/mjpg/video.cgi?channel=1&subtype=1"

This implementation is working fine but the channel list are starting at 1 not 0.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.