berfenger / cam2mqtt

Control IP cameras through MQTT reliably. Supports ONVIF (motion) and HTTP (reolink) control APIs.
Apache License 2.0
47 stars 3 forks source link


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:

Requirements

Hardware Compatibility

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.

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.