Coder Social home page Coder Social logo

svrooij / ipcam2mqtt Goto Github PK

View Code? Open in Web Editor NEW
26.0 5.0 5.0 374 KB

:video_camera: IPCamera alarm to MQTT bridge inspired to the mqtt-smarthome project.

Home Page: https://www.npmjs.com/package/ipcam2mqtt

License: MIT License

JavaScript 98.19% Dockerfile 1.81%
mqtt-smarthome mqtt ipcam

ipcam2mqtt's Introduction

ipcam2mqtt

npm docker pulls Support me on Github travis github issues mqtt-smarthome semantic-release

This node.js application is a bridge between the your IP Cameras (with sound or motion detection) and a mqtt server. That way your can have your home respond to sound detection events.

It's intended as a building block in heterogenous smart home environments where an MQTT message broker is used as the centralized message bus. See MQTT Smarthome on Github for a rationale and architectural overview.

Installation

Using ipcam2mqtt is really easy, but it requires at least Node.js v6 or higher. (This app is tested against node v10, v13 and the latest lts version).

npm install -g ipcam2mqtt

Usage

ipcam2mqtt 0.0.0-development
Usage: index.js [options]

Options:
  -m, --mqtt         mqtt broker url. See
                     https://github.com/svrooij/ipcam2mqtt#mqtt-url
                                                   [default: "mqtt://127.0.0.1"]
  -i, --instance     instance name. used as mqtt client id and as topic prefix
                                                            [default: "cameras"]
  -p, --port         The port to run on                          [default: 8000]
  --timeout          The timeout in seconds for resetting back to inactive, -1
                     for no reset                                  [default: 10]
  -k, --keep-images  Set this if you want to keep the images in mqtt   [boolean]
  -h, --help         Show help                                         [boolean]
  -v, --verbosity    Set the verbosity.
                   [choices: "error", "warn", "info", "debug"] [default: "info"]
  --version          Show version number                               [boolean]

MQTT Url

Use the MQTT url to connect to your specific mqtt server. Check out mqtt.connect for the full description.

Connection without port (port 1883 gets used)
[protocol]://[address] (eg. mqtt://127.0.0.1)

Connection with port
[protocol]://[address]:[port] (eg. mqtt://127.0.0.1:1883)

Secure connection with username/password and port
[protocol]://[username]:[password]@[address]:[port] (eg. mqtts://myuser:[email protected]:8883)

Configure your cameras

You now have and FTP server running on your computer. Now you can configure the cameras to send FTP snapshots to it when it detects movement or sound. The username you supply will be used as the device name.

Topics

Every message starts with the instance name (specified with the -i argument), which defaults to cameras so we'll asume the default.

Connect messages

This bridge uses the cameras/connected topic to send retained connection messages. Use this topic to check your if your ipcam2mqtt bridge is still running.

  • 0 or missing is not connected (set by will functionality).
  • 1 is connected to mqtt, but have not received an image.
  • 2 is connected to mqtt and received our first image from a camera.

Motion detected

If there is motion detected (eg. a file is received over FTP), you will see two messages on your mqtt server. A motion message on cameras/username/motion with the following properties

  • name The username used for the connection
  • val current state of the device. active or inactive
  • filename The filename of the uploaded image
  • kind The guessed kind of detection (based on the filename)
  • ts timestamp of last update.

And an image message on cameras/username/image, this will just contain the raw image data. And can be displayed by various sources.

Use PM2 to run in background

If everything works as expected, you should make the app run in the background automatically. Personally I use PM2 for this. And they have a great guide for this.

To start ipcam2mqtt with PM2, you have to use this command.

pm2 start ipcam2mqtt -x -- [regular-options]
# the -x -- part is to tell pm2 you want to specify arguments to the script. example:
pm2 start ipcam2mqtt -x -- -i cameras -m mqtt://your.mqtt.host:1883

Docker

You can also run this bridge on docker. Be sure to specify your own mqtt connection string! This command connects port 8021 (you can change this) to the container where the bridge runs at 8021.

You can also set the other properties by using the -e "IPCAM2MQTT_...=newvalue" argument. All the properties can be set with the prefix IPCAM2MQTT_ followed by the full name.

docker run -d -e "IPCAM2MQTT_MQTT=mqtt://your.mqtt.nl:1883" -p 8021:8021 --name ipcam2mqtt svrooij/ipcam2mqtt:latest
# Open (and follow) the logs
docker logs ipcam2mqtt -f

Special thanks

This bridge is inspired on hue2mqtt.js by Sabastian Raff. That was a great sample on how to create a globally installed, command-line, something2mqtt bridge.

The actual FTP server part is mostly copied, improved and simplified from mqtt-camera-ftpd. It wasn't really working anymore and it wasn't a true CLI tool hence this new and improved version.

Beer

This bridge took me a lot of hours to build, so I invite everyone using it check out my brand new Github sponsor page

ipcam2mqtt's People

Contributors

dependabot[bot] avatar greengiant avatar renovate-bot avatar renovate[bot] avatar svrooij 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

Watchers

 avatar  avatar  avatar  avatar  avatar

ipcam2mqtt's Issues

Significant delay after 1st ftp upload

Hi, thanks for this great project, however I'm facing some problem.

Every time after restarting ipcam2mqtt, the 1st ftp upload will always trigger the "Motion detected" message instantly, but then there will be 5-20 seconds delay between the time when camera uploaded image and the ipcam2matt "motion detected" message.

And the -v debug or --verbosity debug parameter doesn't work, so I can't get more debug info

Require password

At this moment every password is accepted, I should maybe require at least some sort off password. This function could be used.

Program stops to work after a certain amount of time

I use the dock image.

Docker log reads:

ipcam2mqtt_1           | 2019-07-25T02:39:56.952916898Z 2019-07-25 02:39:56.952 <info>  Motion detected for ftpuser
ipcam2mqtt_1           | 2019-07-25T02:40:07.974386526Z 2019-07-25 02:40:07.974 <info>  Motion detected for ftpuser
ipcam2mqtt_1           | 2019-07-25T02:40:18.991486184Z 2019-07-25 02:40:18.991 <info>  Motion detected for ftpuser
ipcam2mqtt_1           | 2019-07-25T03:37:16.890100437Z 2019-07-25 03:37:16.889 <info>  Motion detected for ftpuser
ipcam2mqtt_1           | 2019-07-25T03:37:27.877646251Z 2019-07-25 03:37:27.877 <info>  Motion detected for ftpuser
ipcam2mqtt_1           | 2019-07-25T03:37:49.056456207Z ERROR: <::ffff:192.168.3.78> Error sending file list, reading directory: Error: Not implemented
ipcam2mqtt_1           | 2019-07-25T03:37:59.882173049Z ERROR: <::ffff:192.168.3.78> Error sending file list, reading directory: Error: Not implemented
ipcam2mqtt_1           | 2019-07-25T03:38:10.819778096Z ERROR: <::ffff:192.168.3.78> Error sending file list, reading directory: Error: Not implemented
ipcam2mqtt_1           | 2019-07-25T03:38:21.873036788Z ERROR: <::ffff:192.168.3.78> Error sending file list, reading directory: Error: Not implemented
ipcam2mqtt_1           | 2019-07-25T06:53:03.740454131Z ERROR: <::ffff:192.168.3.78> Error sending file list, reading directory: Error: Not implemented
ipcam2mqtt_1           | 2019-07-25T06:53:14.713013235Z ERROR: <::ffff:192.168.3.78> Error sending file list, reading directory: Error: Not implemented

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


No npm token specified.

An npm token must be created and set in the NPM_TOKEN environment variable on your CI environment.

Please make sure to create an npm token and to set it in the NPM_TOKEN environment variable on your CI environment. The token must allow to publish to the registry https://registry.npmjs.org/.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Invalid npm token.

The npm token configured in the NPM_TOKEN environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/.

If you are using Two-Factor Authentication, make configure the auth-only level is supported. semantic-release cannot publish with the default auth-and-writes level.

Please make sure to set the NPM_TOKEN environment variable in your CI with the exact value of the npm token.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

MKD camera_test20190222080904: Error: Not implemented

My Reolink cameras insist on creating directories for snapshots. When I do a test from the camera (even when I tell the camera not to use a directory), I get the following from ipcam2mqtt:

ERROR: <::ffff:192.168.1.201> CWD //camera_test20190222080904: Error: ENOENT: no such file or directory, stat '/srv/homeassistant/camera_test20190222080904'
ERROR: <::ffff:192.168.1.201> CWD camera_test20190222080904: Error: ENOENT: no such file or directory, stat '/srv/homeassistant/camera_test20190222080904'
ERROR: <::ffff:192.168.1.201> MKD camera_test20190222080904: Error: Not implemented

Is there an easy fix for this on the ipcam2mqtt side of things? I don't even care to save the images, I just want to push them via MQTT to Home Assistant.

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.