Code Monkey home page Code Monkey logo

cam2mqtt's Introduction



cam2mqtt

Implements a translation layer between camera interfaces (ONVIF, ad-hoc HTTP APIs, etc) and MQTT.

Motivation

Some ONVIF software libraries are prone to reliability problems. If a camera goes offline for a while, the library won't know the camera is offline and won't recover nor fail (e.g. letting docker-compose restart the container). Moreover, some programs don't release resources reserved on the cameras (like ONVIF subscriptions) which can cause random connection problems on some cameras. These are severe problems for a security/alarm system that this software aims to solve.

Features

This program is designed with reliability in mind. Every component is independent and tries to recover by itself if any problem happens.

For now, only two modules are implemented:

  • ONVIF Events:
    • Motion events
    • AI powered object detection (only Reolink cameras on firmware >= 3.1.0.951, april 2022).
    • Visitor button press (on Reolink Video Doorbell)
  • Reolink:
    • Control
      • PTZ (absolute zoom)
      • Change night vision mode (auto, on, off)
      • Enable/disable IR lights (auto, off)
      • Change motion alarm sensitivity (old API)
      • Sync date time
      • Enable/disable Record (V1 & V2)
      • Enable/disable FTP (V1 & V2)
      • Turn on/off spotlight and change brightness
      • Change audio volume
      • Play alarm
      • Enable/disable fullscreen privacy mask
    • AI powered object detection
      • Person detection
      • Vehicle detection
      • Pet detection (not yet supported on some firmwares)
      • Face detection (not yet supported by firmware)

Requirements

  • Docker (if you want painless deployment)
  • MQTT broker (e.g. Mosquitto)
  • Al least one compatible camera

Hardware Compatibility

  • Reolink CX410, RLC-410, RLC-520, RLC-511W, E1 Zoom
  • Reolink RLC-510A, RLC-520A, RLC-511WA, RLC-810A, RLC-811A, RLC-820A, RLC-822A (incl. people and vehicle AI detection)
  • Reolink Video Doorbell PoE/Wifi
  • Other Reolink IP ONVIF cameras should work.
  • Any other IP camera supporting ONVIF event subscriptions (webhook or pullpoint-subscription based) should work.

Feel free to try other cameras and let me know if it works so I can update this list.

Run

Using docker/docker-compose

A precompiled docker image is available on docker hub.

image: acasal/cam2mqtt:latest

Use the included docker-compose.yml and the example config file config.example.yml as a template to create your config file.

$ docker-compose up

NOTE: if you don't use the ONVIF webHook subscription method, you can remove the port section on docker-compose.yml.

Build

Using SBT

$ sbt compile stage
The resulting binaries will be located at target/universal/stage

$ CONFIG=./my_config_file.yml sbt
sbt:cam2mqtt> run

MQTT Protocol

Check the MQTT protocol on this page.

Troubleshooting

P: I only receive the first motion on event from my Reolink camera

Some cameras like RLC-410W and E1 Zoom don't send the motion: off event, so it should be generated by software. To fix this issue, add this setting to your camera onvif module config.

      onvif:
        force_motion_debounce_time: 2 seconds

Adjust the time to fit your camera. A value between 1-3 seconds should be enough.

P: I don't receive AI detection events (people or vehicle detection) from my Reolink camera

This feature is only available on "A" Reolink cameras.

Reolink cameras have 2 ways to communicate AI detection state.

  • HTTP API: Polling based. Supported by all "A" IP cameras.
  • ONVIF subscription: Supported on some "A" cameras. Only those on firmware >= 3.1.0.951, april 2022. Most of the cameras don't have this firmware available as of December 2022.

For cameras on firmware < 3.1.0.951, april 2022 you should use the reolink module with option ai_detection_mode: on_motion if using it in conjunction with onvif module (recommended), or ai_detection_mode: continuous if not using the onvif module.

For cameras on firmware >= 3.1.0.951, april 2022, if using reolink module you should set ai_detection_mode: off (default behavior).

Check this Reolink firmware repository for and updated firmware for your Reolink camera.

Licensing

Copyright 2023 Arturo Casal

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

cam2mqtt's People

Contributors

alvarobrey avatar berfenger 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cam2mqtt's Issues

Could not parse config file

Hello!
I hope someone can help?
I dont know where to copy the config.yml file with docker cp?!
When i start the container it stops with the error "could not parse config file"
Thank you for help :)

Reolink RLC-810A

Hi,

I set up one RLC-810A and would like to receive not just motion but the AI detection events.

cameras:
  reolink_carport:
    host: <ip>
    username: <username>
    password: <password>
    modules:
      onvif:
        port: 8000
        monitor_events: true
        prefer_webhook_subscription: false
      reolink:
        # port: 443 # optional. 443/HTTPS by default
        # username: bob # optional. Alternative username for Reolink API
        # password: bobpass # optional. Alternative password for Reolink API
        # ssl: false # optional. Use ssl/HTTPS
        ai_detection_mode: continous # one of [off, on_motion, continuous]. on_motion requires onvif module to detect motion
        sync_datetime: false
        # audio: false # allow to control audio alarm volume (can't be autodetected)
        # alarm: false # allow to control alarm siren (can't be autodetected)
        # spotlight: false # allow to control spotlight (can't be autodetected)

Is this config correct?

In the log it says

[INFO ] 2023-01-14 13:04:32,359 akka://cam2mqtt/user/cameraman/cam_reolink_carport/mod_onvif - ONVIF Capabilities for camera reolink_carport:
Events: true
Pull-Point subscription: true
[INFO ] 2023-01-14 13:04:36,196 akka://cam2mqtt/user/cameraman/cam_reolink_carport/mod_reolink - Reolink Capabilities for camera reolink_carport:

From the README I am not sure if this configuration is the best for RLC-XXXA cameras. My firmware is v3.1.0.956_22041503, hardware IPC_523128M8MP.

Thanks for some feedback on this.

permanent status "offline" with new firmware on RLC520A V2

Hi,
on my Reolink RLC520A V2 I was running firmware "v3.1.0.989_22081701" which worked as extected.
After updating the firmware with IPC_523128M5MP_V2.2368_23062701.RLC-520A.OV05A10.5MP.REOLINK.pak the status stays on offline, nevertheless which parameter I choose in the settings. After re-installing to v3.1.0.989_22081701 it works again.

This is, what the log says:

2023-10-23 13:13:21 stdout [INFO ] 2023-10-23 13:13:21,949 akka://cam2mqtt/user/cameraman/cam_CamKEI/mod_reolink/reolinkAITracker - Message [net.bfgnet.cam2mqtt.camera.modules.reolink.ReolinkAIDetectionTrackingActor$GotAIStates] to Actor[akka://cam2mqtt/user/cameraman/cam_CamKEI/mod_reolink/reolinkAITracker#607064928] was unhandled. [6] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.
2023-10-23 13:13:19 stdout [INFO ] 2023-10-23 13:13:19,016 akka://cam2mqtt/user/cameraman/cam_CamFLI/mod_reolink - Message [scala.util.Success] wrapped in [akka.actor.typed.internal.AdaptMessage] to Actor[akka://cam2mqtt/user/cameraman/cam_CamFLI/mod_reolink#-1911425607] was not delivered. [5] dead letters encountered. If this is not an expected behavior then Actor[akka://cam2mqtt/user/cameraman/cam_CamFLI/mod_reolink#-1911425607] may have terminated unexpectedly. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.
2023-10-23 13:13:18 stdout at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)
2023-10-23 13:13:18 stdout at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
2023-10-23 13:13:18 stdout at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
2023-10-23 13:13:18 stdout at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
2023-10-23 13:13:18 stdout at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
2023-10-23 13:13:18 stdout at akka.dispatch.Mailbox.exec(Mailbox.scala:243)
2023-10-23 13:13:18 stdout at akka.dispatch.Mailbox.run(Mailbox.scala:231)
2023-10-23 13:13:18 stdout at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:270)
2023-10-23 13:13:18 stdout at akka.actor.ActorCell.invoke(ActorCell.scala:545)
2023-10-23 13:13:18 stdout at akka.actor.ActorCell.autoReceiveMessage(ActorCell.scala:562)
2023-10-23 13:13:18 stdout at akka.actor.ActorCell.receivedTerminated(ActorCell.scala:410)
2023-10-23 13:13:18 stdout at akka.actor.dungeon.DeathWatch.receivedTerminated$(DeathWatch.scala:69)
2023-10-23 13:13:18 stdout at akka.actor.dungeon.DeathWatch.receivedTerminated(DeathWatch.scala:70)
2023-10-23 13:13:18 stdout at scala.Option.foreach(Option.scala:437)
2023-10-23 13:13:18 stdout at akka.actor.dungeon.DeathWatch.$anonfun$receivedTerminated$1$adapted(DeathWatch.scala:70)
2023-10-23 13:13:18 stdout at akka.actor.dungeon.DeathWatch.$anonfun$receivedTerminated$1(DeathWatch.scala:79)
2023-10-23 13:13:18 stdout at akka.actor.ActorCell.receiveMessage(ActorCell.scala:579)
2023-10-23 13:13:18 stdout at akka.actor.typed.internal.adapter.ActorAdapter.aroundReceive(ActorAdapter.scala:91)
2023-10-23 13:13:18 stdout at akka.actor.typed.internal.adapter.ActorAdapter.handleSignal(ActorAdapter.scala:138)
2023-10-23 13:13:18 stdout at akka.actor.typed.Behavior$.interpretSignal(Behavior.scala:236)
2023-10-23 13:13:18 stdout at akka.actor.typed.Behavior$.interpret(Behavior.scala:273)
2023-10-23 13:13:18 stdout at akka.actor.typed.internal.InterceptorImpl.receiveSignal(InterceptorImpl.scala:92)
2023-10-23 13:13:18 stdout at akka.actor.typed.internal.RestartSupervisor.aroundSignal(Supervision.scala:263)
2023-10-23 13:13:18 stdout at akka.actor.typed.internal.AbstractSupervisor.aroundSignal(Supervision.scala:83)
2023-10-23 13:13:18 stdout at akka.actor.typed.internal.InterceptorImpl$anon$3.apply(InterceptorImpl.scala:67)
2023-10-23 13:13:18 stdout at akka.actor.typed.Behavior$.interpretSignal(Behavior.scala:236)
2023-10-23 13:13:18 stdout at akka.actor.typed.Behavior$.interpret(Behavior.scala:273)
2023-10-23 13:13:18 stdout at akka.actor.typed.internal.BehaviorImpl$ReceiveBehavior.receiveSignal(BehaviorImpl.scala:133)
2023-10-23 13:13:18 stdout at net.bfgnet.cam2mqtt.camera.Camera$anonfun$net$bfgnet$cam2mqtt$camera$Camera$routing$2.applyOrElse(Camera.scala:70)
2023-10-23 13:13:18 stdout at net.bfgnet.cam2mqtt.camera.Camera$anonfun$net$bfgnet$cam2mqtt$camera$Camera$routing$2.applyOrElse(Camera.scala:72)
2023-10-23 13:13:18 stdout java.lang.Exception: escalate failure
2023-10-23 13:13:18 stdout [ERROR] 2023-10-23 13:13:18,759 akka://cam2mqtt/user/cameraman/cam_CamFLI - Supervisor RestartSupervisor saw failure [5]: escalate failure
2023-10-23 13:13:18 stdout at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)
2023-10-23 13:13:18 stdout at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
2023-10-23 13:13:18 stdout at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
2023-10-23 13:13:18 stdout at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
2023-10-23 13:13:18 stdout at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
2023-10-23 13:13:18 stdout at akka.dispatch.Mailbox.exec(Mailbox.scala:243)
2023-10-23 13:13:18 stdout at akka.dispatch.Mailbox.run(Mailbox.scala:231)
2023-10-23 13:13:18 stdout at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:270)
2023-10-23 13:13:18 stdout at akka.actor.ActorCell.invoke(ActorCell.scala:547)
2023-10-23 13:13:18 stdout at akka.actor.ActorCell.receiveMessage(ActorCell.scala:579)
2023-10-23 13:13:18 stdout at akka.io.TcpConnection.aroundReceive(TcpConnection.scala:33)
2023-10-23 13:13:18 stdout at akka.actor.Actor.aroundReceive$(Actor.scala:535)
2023-10-23 13:13:18 stdout at akka.actor.Actor.aroundReceive(Actor.scala:537)
2023-10-23 13:13:18 stdout at akka.io.TcpOutgoingConnection$anonfun$connecting$1.applyOrElse(TcpOutgoingConnection.scala:111)
2023-10-23 13:13:18 stdout at akka.io.TcpOutgoingConnection.akka$io$TcpOutgoingConnection$reportConnectFailure(TcpOutgoingConnection.scala:53)
2023-10-23 13:13:18 stdout at akka.io.TcpOutgoingConnection$anonfun$connecting$1.$anonfun$applyOrElse$4(TcpOutgoingConnection.scala:111)
2023-10-23 13:13:18 stdout at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:946)
2023-10-23 13:13:18 stdout at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:672)
2023-10-23 13:13:18 stdout at java.base/sun.nio.ch.Net.pollConnect(Native Method)
2023-10-23 13:13:18 stdout Caused by: java.net.ConnectException: Connection refused
2023-10-23 13:13:18 stdout akka.stream.StreamTcpException: Tcp command [Connect(192.168.30.248/:8000,None,List(),Some(10 seconds),true)] failed because of java.net.ConnectException: Connection refused

Can you please take a look?
Thanks

[Reolink] Change auth to token based auth

Use a token based authentication instead of the current implementation that does not work on every camera.

Take the opportunity to implement support for the new encrypted API.

Alerts of objects outside the detection zone?

Hi,

I get alerts for objects which are outside of the detection zone of my camera.
Is this an issue of cam2mqtt (maybe a known limitation) or maybe an issue with the Reolink-API being used?

Thanks.

Error on cam2mqtt Docker

Hello,

I just discover your project and would run it on my Docker but i'm facing an issue :
Error response from daemon: Could not check if docker-default AppArmor profile was loaded: open /sys/kernel/security/apparmor/profiles: no such file or directory

Can you help me ? Docker is the latest version, installed on Debian10 up to date (SMP Debian 5.10.205-2 (2023-12-31))

thx

Problem with Reolink RLC-520A

Hi,

I set up the software for two Reolink RLC-810A und everything is working absolutly fine.
Today I added an Reolink RLC-520A ( v3.1.0.801_22010701) with the same setting like on my 810A.
But I didn´t receive any AI events via MQTT.

Here is my config:
`mqtt:
host: 192.168.XXX.XXX
port: 1888
username: username
password: password
#base_name: cam2mqtt
ssl: false
#required: true # leave it on true (default) to avoid losing messages on startup

webhook:
external_url: http://192.168.XXX.XXX:8081 # only needed for webhook subscriptions

cameras:
Hof:
host: 192.168.XXX.XXX
username: username
password: password
modules:
onvif:
port: 8000
monitor_events: true
prefer_webhook_subscription: false
reolink:
port: 443 # optional. 443/HTTPS by default
# username: username # optional. Alternative username for Reolink API
# password: password # optional. Alternative password for Reolink API
ssl: true # optional. Use ssl/HTTPS
sync_datetime: false

Terrasse:
host: 192.168.XXX.XXX
username: username
password: password
modules:
onvif:
port: 8000
monitor_events: true
prefer_webhook_subscription: false
reolink:
port: 443 # optional. 443/HTTPS by default
# username: username # optional. Alternative username for Reolink API
# password: password # optional. Alternative password for Reolink API
ssl: true # optional. Use ssl/HTTPS
sync_datetime: false

Haustur:
host: 192.168.XXX.XXX
username: username
password: password
modules:
onvif:
port: 8000
monitor_events: true
prefer_webhook_subscription: false
reolink:
port: 443 # optional. 443/HTTPS by default
# username: username # optional. Alternative username for Reolink API
# password: password # optional. Alternative password for Reolink API
ssl: true # optional. Use ssl/HTTPS
sync_datetime: false
`

I already compared all settings on the cameras, but they are all the same.
Does anyone else have Problem wit the RLC-520A ?

Installation and configuration

Is possible have information about how install and configure it to works with more that one camera?

I have installed the docker image and create a config.yml file but when I try to run
docker run -v /home/array81/cam2mqtt:/config acasal/cam2mqtt

I get error about config file not found but the config.yml is inside /home/array81/cam2mqtt folder

No MQTT Messages from 'Reolink Module' (Config-Issue?)

Hi

Since you mentined some changes on the latest release, I am testing cam2mqtt with a Reolink RLC-523WA with the latest firmware version v3.1.0.804_22011510. While the 'Onvif Module' works flawless, unfortunately I can not see any messages from the 'Reolink Module' in my MQTT broker.

I would assume the following is critical in the config.yml to have the 'Reolink Module' working:

  • webhook: external_url: http://192.168.xxx.xx:8000 ==> This is expected to represent the camera IP with the 'Onvif-Port' (Reolink Onvif Standard Port = 8000) ?
  • cameras: camera-id: modules: onvif: prefer_webhook_subscriptions: ==> Set to 'true' ?

Also on the 'docker-compose.yml', should I also add the port 8000 under services: cam2mqtt: ports: ?

Thanks for a short comment / confirmation on the config.yml and 'docker-compose.yml' settings.
Also, any other idea how to get the 'Reolink Module' working is appreciated.

Regards
Marcus

Reolink E1 Zoom

I have an issue with my Reolink E1 Zoom, where it only reports the first motion once the docker container starts, any subsequent movement is not reported. MQTT shows all of the Reolink features and I can change via MQTT infra red setting etc.
I have 4 other cameras which all report motion ok but they all have AI motion detection, they are a mixture of RLC-820A, RLC-510A, RLC-810A.
I have tried reverting the firmware from the July version to the February version.
Also motion from the E1 Zoom is reported ok into Home Assistant using its integration.

Any help would be appreciated.
Thanks

Done some further checking and my RLC-410W also exhibits the same issue.

Reolink CX410 works as expect4ed

An update can be made to the documentation.

I've connected an CX410 and this works as expected.
motion and person detection successfully triggered and received in MQTT.

Runs with Reolink RLC-811A

Not an issue.

Just wanted to confirm that it works via ONVIF (default port: 8000) with a Reolink RLC-811A. I have not tested the Reolink specific stuff but ONVIF motion events happily appear on MQTT.
Thanks for the good work!

[Reolink] Implement continuous AI detection tracking

Check cam AI detection state through GetAiState API calls doing periodic polling to send events to MQTT when AI detection state changes.
Now this is done only while movement is detected using ONVIF motion events.

CAM2MQTT doesn't accept special character

Hello,

I was fighting to understand why no Reolink capabilities was found during this evening up to i try to remove a special character in the password of my cameras.

I have a "!" in my password, and it doesn't work, without this special character it is working.

Can you handle special character ?

thx

Add more features to Reolink Cameras

Hi Arturo,

I would like to implement new commands to Reolink Cameras.
(for example, ability to enable/disable notifications).

I'm not familiar with Scala, so can you explain me how the program is structured ?

My goal is to include this onvif/mqtt gateway in a Jeedom Plugin (domotic controller).

Regards,

Patrice

Add key functions 'SetPtzPreset' and 'GetAiState'

Hi,
First of all - thank you for your great work here! I would like to use cam2mqtt as a module in a Home Automation application (SmarthomeNG, see [https://www.smarthomeng.de/]. What I am missing are the following functions:

  • call a specific PTZ Position (Reolink Command "SetPtzPreset")
  • get the AI Alarm State (Reolink Command "GetAiState")

Is that something you could consider to add to your code?

Regards - Marcus

"Visitor" Event for Reolink Video Doorbell PoE

Hi,
I honor your work - it's really easy to use your docker image.
One feature I am missing is the "visitor" event (button press @ doorbell cam).
Is it easy for you to implement it? I'm not used to scala / java ...
Thanks in advance,
Johannes

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.