|
1 | 1 | # ipcam2mqtt
|
2 |
| -IPCamera alarm to MQTT bridge inspired to the mqtt-smarthome project. |
| 2 | + |
| 3 | +[](https://www.npmjs.com/package/ipcam2mqtt) |
| 4 | +[](https://github.com/semantic-release/semantic-release) |
| 5 | + |
| 6 | +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. |
| 7 | + |
| 8 | +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](https://github.com/mqtt-smarthome/mqtt-smarthome) for a rationale and architectural overview. |
| 9 | + |
| 10 | +## Installation |
| 11 | + |
| 12 | +Using ipcam2mqtt is really easy, but it requires at least [Node.js](https://nodejs.org/) v6 or higher. (This app is tested against v6 and v8). |
| 13 | + |
| 14 | +`sudo npm install -g ipcam2mqtt` |
| 15 | + |
| 16 | +## Usage |
| 17 | + |
| 18 | +```plain |
| 19 | +ipcam2mqtt 0.0.0-development |
| 20 | +Usage: ipcam2mqtt [options] |
| 21 | +
|
| 22 | +Options: |
| 23 | + -m, --mqtt mqtt broker url. See |
| 24 | + https://github.com/svrooij/ipcam2mqtt#mqtt-url |
| 25 | + [default: "mqtt://127.0.0.1"] |
| 26 | + -n, --name instance name. used as mqtt client id and as topic prefix |
| 27 | + [default: "cameras"] |
| 28 | + -p, --port The port to run on [default: 8000] |
| 29 | + --timeout The timeout in seconds for resetting back to inactive, -1 |
| 30 | + for no reset [default: 10] |
| 31 | + -k, --keep-images Set this if you want to keep the images in mqtt [boolean] |
| 32 | + -h, --help Show help [boolean] |
| 33 | + -l, --logging possiblevalues: "error", "warn","info","debug" |
| 34 | + [default: "info"] |
| 35 | + --version Show version number [boolean] |
| 36 | +``` |
| 37 | + |
| 38 | +### MQTT Url |
| 39 | + |
| 40 | +Use the MQTT url to connect to your specific mqtt server. Check out [mqtt.connect](https://github.com/mqttjs/MQTT.js#connect) for the full description. |
| 41 | + |
| 42 | +```plain |
| 43 | +Connection without port (port 1883 gets used) |
| 44 | +[protocol]://[address] (eg. mqtt://127.0.0.1) |
| 45 | +
|
| 46 | +Connection with port |
| 47 | +[protocol]://[address]:[port] (eg. mqtt://127.0.0.1:1883) |
| 48 | +
|
| 49 | +Secure connection with username/password and port |
| 50 | +[protocol]://[username]:[password]@[address]:[port] (eg. mqtts://myuser:[email protected]:8883) |
| 51 | +``` |
| 52 | + |
| 53 | +### Configure your cameras |
| 54 | + |
| 55 | +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. |
| 56 | + |
| 57 | +## Topics |
| 58 | + |
| 59 | +Every message starts with the instance name (specified with the `-n` argument), which defaults to `cameras` so we'll asume the default. |
| 60 | + |
| 61 | +### Connect messages |
| 62 | + |
| 63 | +This bridge uses the `cameras/connected` topic to send retained connection messages. Use this topic to check your if your hue bridge is still running. |
| 64 | + |
| 65 | +- `0` or missing is not connected (set by will functionality). |
| 66 | +- `1` is connected to mqtt, but have not received an image. |
| 67 | +- `2` is connected to mqtt and received our first image from a camera. |
| 68 | + |
| 69 | +### Motion detected |
| 70 | + |
| 71 | +If there is motion detected (eg. a file is received over FTP), you will see two messages on your mqtt server. |
| 72 | +A motion message on `cameras/username/motion` with the following properties |
| 73 | + |
| 74 | +- `name` The username used for the connection |
| 75 | +- `val` current state of the device. `active` or `inactive` |
| 76 | +- `filename` The filename of the uploaded image |
| 77 | +- `kind` The guessed kind of detection (based on the filename) |
| 78 | +- `ts` timestamp of last update. |
| 79 | + |
| 80 | +And an image message on `cameras/username/image`, this will just contain the raw image data. And can be displayed by various sources. |
| 81 | + |
| 82 | +## Use [PM2](http://pm2.keymetrics.io) to run in background |
| 83 | + |
| 84 | +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](http://pm2.keymetrics.io/docs/usage/quick-start/). |
| 85 | + |
| 86 | +## Special thanks |
| 87 | + |
| 88 | +This bridge is inspired on [hue2mqtt.js](https://github.com/hobbyquaker/hue2mqtt.js) by [Sabastian Raff](https://github.com/hobbyquaker). That was a great sample on how to create a globally installed, command-line, something2mqtt bridge. |
| 89 | + |
| 90 | +The actual FTP server part is mostly copied, improved and simplified from [mqtt-camera-ftpd](https://github.com/stjohnjohnson/mqtt-camera-ftpd/). It wasn't really working anymore and it wasn't a true CLI tool hence this new and improved version. |
| 91 | + |
| 92 | +## Beer |
| 93 | + |
| 94 | +This bridge took me a lot of hours to build, so I invite everyone using it to [Buy me a beer](https://✌️.tk/beer) |
0 commit comments