Skip to content

Instantly share code, notes, and snippets.

@mblackstock
Last active December 1, 2017 19:19
Show Gist options
  • Save mblackstock/ec8c5834260078a60ba4fc4f641fead3 to your computer and use it in GitHub Desktop.
Save mblackstock/ec8c5834260078a60ba4fc4f641fead3 to your computer and use it in GitHub Desktop.
Node-RED flow that takes pictures when signalled using MQTT and sends them to a HTTP endpoint

Mac Camera Flow README

This flow runs on a Mac to take small photos using a web cam when signalled via MQTT.

Prequisites

This flow relies on imagesnap being installed on your Mac to take pictures using the built in web cam.

How it works

When a message is sent to the MQTT endpoint, a new photo is taken, then resized using imagesnap called with an exec node. The file is read, then sent via HTTP by base64 encoding to a private FRED HTTP endpoint.

It can be used as part of a remote security camera solution where the cloud can be used to trigger and view remote images, and do further storage and image processing.

[
{
"id": "723bff0a.755dd",
"type": "mqtt in",
"z": "cd4c1f53.7e90c",
"name": "",
"topic": "users/mike/camera",
"qos": "2",
"broker": "ca9779be.e06278",
"x": 250,
"y": 100,
"wires": [
[
"4256edf3.35b104"
]
]
},
{
"id": "6db536bd.4318a8",
"type": "debug",
"z": "cd4c1f53.7e90c",
"name": "",
"active": true,
"console": "false",
"complete": "true",
"x": 830,
"y": 420,
"wires": []
},
{
"id": "4256edf3.35b104",
"type": "exec",
"z": "cd4c1f53.7e90c",
"command": "imagesnap /Users/mike/.node-red/snapshot.png",
"addpay": false,
"append": "",
"useSpawn": "false",
"timer": "",
"oldrc": false,
"name": "",
"x": 610,
"y": 100,
"wires": [
[],
[
"6db536bd.4318a8"
],
[
"f42ffe85.a9bb4"
]
]
},
{
"id": "f0b68ebe.182f2",
"type": "file in",
"z": "cd4c1f53.7e90c",
"name": "",
"filename": "/Users/mike/.node-red/snapshot.png",
"format": "",
"chunk": false,
"sendError": false,
"x": 570,
"y": 220,
"wires": [
[
"5fbdb149.6f648"
]
]
},
{
"id": "604d60a9.056c2",
"type": "inject",
"z": "cd4c1f53.7e90c",
"name": "",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": false,
"x": 320,
"y": 40,
"wires": [
[
"4256edf3.35b104"
]
]
},
{
"id": "f0f5e80d.4bdea8",
"type": "http request",
"z": "cd4c1f53.7e90c",
"name": "",
"method": "POST",
"ret": "txt",
"url": "https://mike.fred.sensetecnic.com/api/camera",
"tls": "",
"x": 830,
"y": 340,
"wires": [
[
"6db536bd.4318a8"
]
]
},
{
"id": "5fbdb149.6f648",
"type": "change",
"z": "cd4c1f53.7e90c",
"name": "add headers",
"rules": [
{
"t": "set",
"p": "headers['x-auth-key']",
"pt": "msg",
"to": "SECRET_FRED_DEV_API_KEY",
"tot": "str"
},
{
"t": "set",
"p": "headers['x-auth-user']",
"pt": "msg",
"to": "mike",
"tot": "str"
},
{
"t": "set",
"p": "headers['Content-type']",
"pt": "msg",
"to": "image/png",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 830,
"y": 220,
"wires": [
[
"e2d1e8a3.3af848"
]
]
},
{
"id": "f42ffe85.a9bb4",
"type": "exec",
"z": "cd4c1f53.7e90c",
"command": "sips -Z 640 /Users/mike/.node-red/snapshot.png",
"addpay": false,
"append": "",
"useSpawn": "false",
"timer": "",
"oldrc": false,
"name": "",
"x": 630,
"y": 160,
"wires": [
[],
[],
[
"f0b68ebe.182f2"
]
]
},
{
"id": "e2d1e8a3.3af848",
"type": "base64",
"z": "cd4c1f53.7e90c",
"name": "",
"x": 820,
"y": 280,
"wires": [
[
"f0f5e80d.4bdea8"
]
]
},
{
"id": "ca9779be.e06278",
"type": "mqtt-broker",
"z": "",
"name": "",
"broker": "mqtt.sensetecnic.com",
"port": "1883",
"clientid": "mike-e294810f",
"usetls": false,
"compatmode": true,
"keepalive": "60",
"cleansession": true,
"willTopic": "",
"willQos": "0",
"willPayload": "",
"birthTopic": "",
"birthQos": "0",
"birthPayload": ""
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment