npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ipcam2mqtt

v1.2.2

Published

A special FTP server for receiving images from IPCameras and forwarding them to MQTT, for use in a smarthome.

Downloads

75

Readme

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