alarmserver icon indicating copy to clipboard operation
alarmserver copied to clipboard

Server got alarm but no mqtt message

Open grossmanns opened this issue 3 years ago • 24 comments

First, thanks for this work !

But it must be a config problem on my side, because the server got the alarm status from cams, but does not send any message over mqtt : My config : mqtt: enabled: true username: mymqttuser without brackets password: mymqttuserpassword without brackets port: 1883 server: 192.168.1.xxx topicroot: camera-alerts

Container's log: HISI: DEVICE ALERT: { "Address" : "0xF801A8C0", "Channel" : 0, "Descrip" : "", "Event" : "HumanDetect", "SerialID" : "00781cd57136458b", "StartTime" : "2021-12-24 12:52:08", "Status" : "Start", "Type" : "Alarm" }

I tried with or without brackets for the password ....

grossmanns avatar Dec 24 '21 11:12 grossmanns

Here is the log of Home Assistant's MQTT broker : `New client connected from 172.30.xx.x as alarmserver-go-81 (p2, c1, k2, u'myuser').

Socket error on client 6ZgkMEdIO6F6psuRezX, disconnecting.`

grossmanns avatar Dec 24 '21 14:12 grossmanns

And alarmserver's log : MQTT: CONNECTED TO 192.168.x.x

grossmanns avatar Dec 24 '21 16:12 grossmanns

Hello, have you resolved this? If not - can you please try the latest version since many bugs were fixed since.

Please let me know how it goes! Thanks!

toxuin avatar May 21 '22 02:05 toxuin

Hi, I just tested the latest image : in my cams config, i put the 192.168.1.xxx ip of my rpi4. Should I rather put the docker container's ip : 172.17.0.xxx ? no error message on the log, only : Initializing MQTT bus...

Here my config : `debug: false

mqtt: enabled: true username: ************ password: ********** port: 1883 server: "192.168.1.xxx" topicroot: camera-alerts

hisilicon: enabled: true port: 15002

ftp: enabled: true port: 21 password: ******** allowFiles: true rootPath: "./ftp"`

And nothing else, no log of the cams, no alarm message .... in the hisilicon part, is there anything to declare ? (ip of the cams ? )

grossmanns avatar May 21 '22 08:05 grossmanns

Works great in fact : once the debug is turned to true, i can read the alarms ! Need to find now, out how to integrate it into Home Assistant... Thanks for the work !

grossmanns avatar May 21 '22 13:05 grossmanns

Just tried to use mqtt with : mqtt: enabled: true username: ****** password: ******* port: 1883 server: "192.168.1.xxx" topicroot: camera-alerts

Debug log from your server tells : 2022-05-21T14:28:32.884757000Z HISI: DEVICE ALERT: { "Address" : "0xxxxxxxxx", "Channel" : 3, "Descrip" : "", "Event" : "MotionDetect", "SerialID" : "fexxxxxxxxxxxxxxxxxx", "StartTime" : "2022-05-21 16:28:31", "Status" : "Stop", "Type" : "Alarm" }

Container logs tells : MQTT: CONNECTED TO 192.168.1.xxxx But no Mqtt topic published in HA when I listen to 'camera-alerts'

grossmanns avatar May 21 '22 14:05 grossmanns

The problem lies with Socket error on client *?*, disconnecting. on MQTT broker side. Home Assistant uses mosquitto and it's known to throw this exact message for basically whatever problem there is with the client connection. I'm going to add some more logging around reasons for disconnection in the next version of alarmserver. Is there anything fancy about your MQTT broker at all? 🤔

To try out the new version, please pull toxuin/alarmserver:mqtt-reconnect-log tag instead of latest. This should display more messages when disconnected from MQTT and upon reconnection.

toxuin avatar May 22 '22 14:05 toxuin

I pulled the new version, nothing changed, no message sent. So I tried to use the webhooks, and added in the config :

webhooks: enabled: true items: - url: "http://myHAserver:8123/api/webhook/motioneye-COUR-camera-started" headers: - "X-Beep: boop"

But no communication neither.

grossmanns avatar Jun 05 '22 09:06 grossmanns

Are there any error messages in the console? The tagged version should've not necessarily fixed the issue you're having, but rather it should give us more insight on what's going on.

toxuin avatar Jun 29 '22 23:06 toxuin

No message about mqtt, which i need to get work.

But webhooks displays following :

`
STARTING...

CONFIG: Hisilicon server enabled: true Hikvision server enabled: false FTP server enabled: true mqtt.port: **** mqtt.topicRoot: camera-alerts mqtt.server: ********** mqtt.username: *********** mqtt.password set: true Initializing MQTT bus... MQTT: CONNECTED TO 192.************ MQTT BUS INITIALIZED Initializing Webhook bus... WEBHOOK BUS INITIALIZED STARTED HISILICON SERVER STARTED FTP SERVER 2022/06/30 06:41:18 alarmserver-go listening on 21 HISI: DEVICE CONNECTED: 192.******************* HISI: DEVICE ALERT: { "Address" : "0xEA01****", "Channel" : 2, "Descrip" : "", "Event" : "HumanDetect", "SerialID" : "fe38701b7d3c2158", "StartTime" : "2022-06-30 08:42:45", "Status" : "Start", "Type" : "Alarm" } WEBHOOKS: Got bad status code delivering payload to http://192.*********************started: 405 WEBHOOKS: Response body: 405: Method Not Allowed HISI: DEVICE CONNECTED: 192.168.1.234:59942 HISI: DEVICE ALERT: { "Address" : "0xEA0", "Channel" : 2, "Descrip" : "", "Event" : "HumanDetect", "SerialID" : "fe38701b7d3c2158", "StartTime" : "2022-06-30 08:42:48", "Status" : "Stop", "Type" : "Alarm" } WEBHOOKS: Got bad status code delivering payload to http://192.1***********************camera: 405 WEBHOOKS: Response body: 405: Method Not Allowed `

grossmanns avatar Jun 30 '22 06:06 grossmanns

There doesn't seem to be anything wrong with MQTT from alarmserver's perspective. Could you use some MQTT client to verify that messages are arriving to the broker?

Webhook error you're seeing is due to the wrong HTTP method.

In your config:

webhooks:
  enabled: true
  items:
    - url: "http://myHAserver:8123/api/webhook/motioneye-COUR-camera-started"
      headers: - "X-Beep: boop"

Make sure you don't have method: "GET" in the webhook item (or have it explicitly as POST). It's there by default and it would give exactly this error if you just leave it there. Also, you don't need x-beep-boop there. That is just an example value. It won't hurt anything, but wouldn't do anything useful either 😄

I just checked this with my HA and same webhook config - it works great.

toxuin avatar Jun 30 '22 16:06 toxuin

About the mqtt part : I added the post method to the config. In the broker, is displayed, just after launch : `Message 1 reçu sur camera-alerts/alarmserver à 10:11 : { "status": "up" } QoS: 0 - Retain: false

Message 0 reçu sur camera-alerts/alarmserver à 10:11 : { "status": "down" }`

First message is "down" and then "up". It should mean everything is OK, but why is there no alarm message when motion is detected ?

grossmanns avatar Jul 01 '22 08:07 grossmanns

And about the webhook part : I got it to work ! Is there a way to send a webhook that depends on the camera that sent the alarm ? Something like : items: - url: http://192.168.***.***/api/webhook/motioneye-{{channel of the alarm}}-camera-started

grossmanns avatar Jul 04 '22 14:07 grossmanns

Somehow my comment got lost : I have the same issue : alarm is showing in the logs, but no MQTT message is being sent. I am using eqmx as mqtt broker, it's gui shows me there is no connection issue between alarmserver and it. I even tried with debug true and false and also tried the above custom image that does log when I kill the connection from eqmx/mqtt side but does reconnect properly and even when connected still no mqtt event is published...

Can you have a look ? I'm using the alarmserver hisilicon thing with a HView camera that sends alerts, I see them in the logs in form of a json object.

toxic0berliner avatar Jul 25 '22 09:07 toxic0berliner

@toxic0berliner please verify that your config has MQTT bus enabled:

mqtt:
  enabled: true

and there is connection to the broker - your logs should say:

MQTT BUS INITIALIZED
MQTT: CONNECTED TO server.com

If you could post your config here (with secret data stripped) - it would be helpful. Also, just to make sure your camera sends alarms in the expected format, could you enable debug mode (debug: true) and capture some alerts from the camera in the logs and attach those here? More specifically, I am looking for either HISI: DEVICE ALERT: {"SerialID": "... lines or something like HISI: TCP READ ERROR.

I somehow cannot reproduce the missing MQTT issue, and it seems like it is happening for more than one user, so I'd like to get to the bottom of this.

toxuin avatar Jul 27 '22 00:07 toxuin

Hi, i have the same issue. I get alarms from cameras in docker container but nothing in home assistant.

Also MQTT BUS INITIALIZED MQTT: CONNECTED

but i cant see mqtt messages in home assistant anyway.

lovian83 avatar Aug 01 '22 15:08 lovian83

Do you have debug mode enabled? Any errors in the mqtt broker logs? Please post your config file!

toxuin avatar Aug 01 '22 17:08 toxuin

Debug is set to true. No mqtt publication, no webhook publication. Alarm is received from camera :

HISI: DEVICE ALERT: { "Address" : "0xEA01A8C", "Channel" : 6, "Descrip" : "", "Event" : "MotionDetect", "SerialID" : "fe38701b7d3c2158", "StartTime" : "2022-08-05 09:01:53", "Status" : "Start", "Type" : "Alarm" } WEBHOOKS: Response body: *empty* HISI: DEVICE CONNECTED: 192.168.1.234:39784 HISI: DEVICE ALERT: { "Address" : "0xEA01A8C", "Channel" : 6, "Descrip" : "", "Event" : "MotionDetect", "SerialID" : "fe38701b7d3c2158", "StartTime" : "2022-08-05 09:01:54", "Status" : "Stop", "Type" : "Alarm" } WEBHOOKS: Response body: *empty*

grossmanns avatar Aug 05 '22 07:08 grossmanns

Thanks! Can I also have your config please?

Line WEBHOOKS: Response body: *empty* is saying that webhook did fire and the server replied, although with empty body.

toxuin avatar Aug 05 '22 07:08 toxuin

Yes 👍

`debug: true

mqtt: enabled: true username: mylogin password: "mypass" port: xxxx server: "192.168.x.x" topicroot: camera-alerts method: "POST"

hisilicon: enabled: true port: 15002

webhooks: enabled: true items: - url: http://192.168.x.x:xxxx/api/webhook/camera-motion method: "POST" `

grossmanns avatar Aug 05 '22 07:08 grossmanns

Sorry for the time it took me to provide the feedback :

the logs :

STARTING...
CONFIG:
  SERVER: Hisilicon - enabled: true
    port: 15002
  SERVER: Hikvision - enabled: false
    camera count: 0
  Dahua server enabled: false
    cams: 0
  SERVER: FTP - enabled: true
HISI: DEVICE CONNECTED: xx.xx.xx.xx:58866
HISI: DEVICE ALERT: { "Address" : "0xXXXXXXXX", "Channel" : 0, "Descrip" : "", "Event" : "HumanDetect", "SerialID" : "XXXXXXXXXXXXXXXXXXXX", "StartTime" : "2022-08-05 08:56:52", "Status" : "Start", "Type" : "Alarm" }

No mqtt message published : image

The config

debug: true

hisilicon:
  enabled: true
  port: 15002

ftp:
  enabled: true
  port: 21
  password: "XXXXXXXXXXXXXXXXXX"
  allowFiles: true
  rootPath: "./ftp"

mqtt:
  enabled: true
  username: alarmserver
  password: "XXXXXXXXXXXXXXXXXXXX"
  port: 1883
  server: "eqmx"
  topicroot: camera-alerts

toxic0berliner avatar Aug 05 '22 08:08 toxic0berliner

I have the same config script. Debug enabled... alarms received from cameras in alarm server... but it does not send mqtt messages...

Webhooks works well. I am traying to separate in home assistant depending of what camera report the alarm.

lovian83 avatar Aug 10 '22 18:08 lovian83

I just tried to use alarmserver with EMQX and I must say that it works, but the configuration is not trivial.

Here is my test setup: gist

Please note that in this setup your topicRoot needs to be set as localhost/camera-alerts and not just camera-alerts. Also needless to say that this setup should NOT be copy-pasted and used as-is, because it was intended for debugging purposes only, completely disregarding any safety.

redis.conf is rather large, but here's what I've changed in it compared to default config:

  • bind 0.0.0.0 - allows redis to listen on all interfaces, and disables IPv6
  • requirepass test123 - password to connect to redis
  • port 63790 - basically irrelevant, I had another redis instance running on my machine 😛

EMQX as a broker requires substantial configuration to work with alarmserver. Nothing extraordinary, but it won't work out of the box with default settings. During my brief introduction to it - while debugging this - I've stumbled on messages being sent but not received, topics not created, subscriptions not delivering any messages and many more. I am 100% sure the reason for this is my clumsy setup, but this goes to show that unless your broker is configured 100% right - there may be problems with message delivery that would look like alarmserver didn't send anything - while it did, but the message was not delivered due to some ACL misconfiguration in EMQX.

To debug your issues with MQTT messages not being delivered, you can connect to the broker with any MQTT client (I use MQTT Explorer) and subscribe to # - meaning "everything". Then, try to publish a message to your topicRoot, for example publish { "test": true } to camera-alerts. You should see the message you just published in your client's subscription. If you don't - that means broker did not notify other subscribers either, so for example Home Assistant won't even know about camera alarm in this case.

toxuin avatar Aug 16 '22 17:08 toxuin

Please note that in this setup your topicRoot needs to be set as localhost/camera-alerts and not just camera-alerts. Also needless to say that this setup should NOT be copy-pasted and used as-is, because it was intended for debugging purposes only, completely disregarding any safety.

It did the trick ! Everything works as expected. I even can make the difference between the camera alerts, thanks to the following command :

{{ trigger.payload_json.Status=='Start' and trigger.payload_json.Channel==0 }}

Thanks so much !!!

grossmanns avatar Aug 19 '22 08:08 grossmanns

@toxic0berliner @lovian83 are you guys still having this issue or is it safe to close this? Also please see my comment about EMQX above, just in case.

toxuin avatar Sep 08 '22 20:09 toxuin

Sorry, got sucked up in something entirely different and have no time to dig up that crappy camera again, seems you got it working with localhost/camera-alerts, I've stopped using eqmx anyway in favor of mosquitto embedded in home-assistant and found frigate does way better event detection than the AI camera without too much load on my CPU. So I'll revisit only in a few month if CPU is too high with several camera and I wannt to disable frigate event detection and turn back to this instead to let the camera do it by itself ;)

So yes, for me you can safely close it ;)

toxic0berliner avatar Sep 09 '22 01:09 toxic0berliner

Thank you! Feel free to open another issue if you encounter it again.

toxuin avatar Sep 20 '22 17:09 toxuin

OK, thanks for reply. I hoped it would have been a simple error of not listening to the right topic, but I see it's more complicated, and exceed my abilities. Is there another way to launch a scenario in home assistant through your server ?

Le dim. 22 mai 2022 à 16:40, Toxuin @.***> a écrit :

The problem lies with Socket error on client ?, disconnecting. on MQTT broker side. Home Assistant uses mosquitto and it's known to throw this exact message for basically whatever problem there is with the client connection. I'm going to add some more logging around reasons for disconnection in the next version of alarmserver. Is there anything fancy about your MQTT broker at all? 🤔

— Reply to this email directly, view it on GitHub https://github.com/toxuin/alarmserver/issues/8#issuecomment-1133910997, or unsubscribe https://github.com/notifications/unsubscribe-auth/AO7LNIDK5B75JCJUESHLSCLVLJBN7ANCNFSM5KWQVYFQ . You are receiving this because you authored the thread.Message ID: @.***>

grossmanns avatar Oct 11 '22 07:10 grossmanns