psyciknz / CameraEvents

Dahua NVR/Camera Alerting to MQTT. Fairly specific to my needs, but also an attempt at starting to use travis.
Eclipse Public License 2.0
58 stars 19 forks source link

No snapshot published to MQTT #24

Open krakers09 opened 3 years ago

krakers09 commented 3 years ago

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.

psyciknz commented 3 years ago

What event is being triggered? Cameraevents on posts a snapshot upon an event (videomotion, ivs etc)

Is it a videomotion on cardriveway?

I need to check that send images to mqtt setting

krakers09 commented 3 years ago

events=CrossLineDetection,CrossRegionDetection,ParkingDetection,AlarmLocal,VideoLoss,VideoBlind,FaceDetection I've also hade VideoMotion, but turned it off. Still getting IVS messages on MQTT.

Example message: CrossLineDetection With Human in LeftToRight direction for Tripwire region

psyciknz commented 3 years ago

So i justpulled the latest for image for mine. And set that SendImagesToMQTT option you had as well.

Heres the MQTT Output CameraEvents/#:

CameraEvents/$online True
CameraEvents/$version 0.2.3
CameraEvents/NVR/alerts/state ON
CameraEvents/$heartbeat 2021-01-29 08:18:06.185433
CameraEvents/VideoMotion/NVR:5 ON
CameraEvents/NVR:5/event ON
CameraEvents/NVR:5/Image {"message": "Motion Detected: NVR:5", "imagebase64": <binary data here>
CameraEvents/VideoMotion/NVR:5 OFF
CameraEvents/NVR:5/event OFF

I mean there's not much in my logging

2021-01-29 08:18:56,329 - __main__ - DEBUG - Heartbeat: 2021-01-29 08:18:56.329489
2021-01-29 08:18:56,630 - __main__ - DEBUG - [NVR]: --myboundary
Content-Type: text/plain
Content-Length:37

Code=VideoMotion;action=Start;index=5

2021-01-29 08:18:56,631 - __main__ - INFO - Video Motion received: NVR Index: NVR:5 Code: VideoMotion
2021-01-29 08:18:56,631 - __main__ - INFO - Snapshot Url: http://<url>:80/cgi-bin/snapshot.cgi?channel=6
2021-01-29 08:19:07,060 - __main__ - DEBUG - [NVR]: --myboundary
Content-Type: text/plain
Content-Length:36

Code=VideoMotion;action=Stop;index=5

2021-01-29 08:19:07,060 - __main__ - INFO - Video Motion received: NVR Index: NVR:5 Code: VideoMotion
2021-01-29 08:19:46,461 - __main__ - DEBUG - Heartbeat: 2021-01-29 08:19:46.461175

For your entry, right before the url is posted is the event, can yo post that, to make sure it's being picked up....it looks like it is if it's firing a snapshot....and some of the cameras can be picky. What is the auth mode for your camera? Basic or digest?

krakers09 commented 3 years ago
2021-01-28T09:39:36.721337864Z 2021-01-28 10:39:36,721 - __main__ - INFO - CrossLineDetection received: {
2021-01-28T09:39:36.721361144Z    "Class" : "Normal",
2021-01-28T09:39:36.721370587Z    "CountInGroup" : 1,
2021-01-28T09:39:36.721378739Z    "DetectLine" : [
2021-01-28T09:39:36.721386505Z       [ 455, 7924 ],
2021-01-28T09:39:36.721394336Z       [ 7263, 8053 ],
2021-01-28T09:39:36.721401720Z       [ 8118, 2668 ],
2021-01-28T09:39:36.721409120Z       [ 4150, 24 ],
2021-01-28T09:39:36.721416545Z       [ 1092, 540 ]
2021-01-28T09:39:36.721423992Z    ],
2021-01-28T09:39:36.721431611Z    "Direction" : "RightToLeft",
2021-01-28T09:39:36.721439241Z    "EventID" : 10253,
2021-01-28T09:39:36.721446657Z    "GroupID" : 88,
2021-01-28T09:39:36.721454045Z    "Name" : "Tripwire",
2021-01-28T09:39:36.721461530Z    "Object" : {
2021-01-28T09:39:36.721468993Z       "Action" : "Appear",
2021-01-28T09:39:36.721476615Z       "BoundingBox" : [ 4096, 0, 4544, 416 ],
2021-01-28T09:39:36.721484421Z       "BrandYear" : 0,
2021-01-28T09:39:36.721491848Z       "CarLogoIndex" : 0,
2021-01-28T09:39:36.721499083Z       "CarWindow" : {
2021-01-28T09:39:36.721506692Z          "BoundingBox" : [ 0, 0, 0, 0 ]
2021-01-28T09:39:36.721514303Z       },
2021-01-28T09:39:36.721521539Z       "Category" : "Unknown",
2021-01-28T09:39:36.721529102Z       "Center" : [ 4320, 208 ],
2021-01-28T09:39:36.721536994Z       "Confidence" : 0,
2021-01-28T09:39:36.721544646Z       "MainColor" : [ 0, 0, 0, 0 ],
2021-01-28T09:39:36.721552268Z       "ObjectID" : 8855,
2021-01-28T09:39:36.721559793Z       "ObjectType" : "Vehicle",
2021-01-28T09:39:36.721567314Z       "RelativeID" : 0,
2021-01-28T09:39:36.721575727Z       "Speed" : 0,
2021-01-28T09:39:36.721584198Z       "SubBrand" : 0,
2021-01-28T09:39:36.721589484Z       "Text" : "Unknown",
2021-01-28T09:39:36.721597014Z       "carLenMode" : 0,
2021-01-28T09:39:36.721604383Z       "carLength" : 0
2021-01-28T09:39:36.721611823Z    },
2021-01-28T09:39:36.721618949Z    "PTS" : 43329609620.0,
2021-01-28T09:39:36.721627590Z    "RuleID" : 5,
2021-01-28T09:39:36.721649720Z    "Track" : [],
2021-01-28T09:39:36.721659008Z    "UTC" : 1611830378,
2021-01-28T09:39:36.721663289Z    "UTCMS" : 620
2021-01-28T09:39:36.721670018Z }
2021-01-28T09:39:36.721677316Z
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

auth basic.

psyciknz commented 3 years ago

What type of camera? I didn't think any where using auto basic for a long time. Maybe try digest.

krakers09 commented 3 years ago

You could be right. Basic was my first guess and it works with detection event. I'll try tomorrow with digest. The other thing I've found is that my camera were set to make snapshot in 8MP or 4MP resolution. It might be just too big. I've changed one to digest and 720p and will try tomorrow.

krakers09 commented 3 years ago

Seems digest partially solved issue. Partially, because I can see now image topic being published, but when I take base64 and decode it I get only like 5% of top of picture and rest is just grey.

Can you please tell me what would be send if in line 211 I would replace msgpayload with image? So instead of self.client.publish(self.basetopic +"/{0}/Image".format(channelName),msgpayload) I would send self.client.publish(self.basetopic +"/{0}/Image".format(channelName),image) Would it just send jpeg/jpg image? It would suit better my need as I could directly display this image in HA without further processing of payload.

psyciknz commented 3 years ago

I’m not sure in binary data be an be transmitted in matt, that’s why I used the base 64 encoding.

maybe another option is to use camerevrnts for the motion detection/its but get ha to get the snap shot?