Skip to content

Control IP cameras through MQTT reliably. Supports ONVIF (motion) and HTTP (reolink) control APIs.

License

Notifications You must be signed in to change notification settings

berfenger/cam2mqtt

Repository files navigation



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.