Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

added service pigpiod + improvements related to node-red service #30

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
9f77cfe
added service pigpiod
Oct 3, 2019
8ad15b3
typo
Oct 3, 2019
f5c5bf1
changed CMD
Oct 3, 2019
1bdb890
-
Oct 3, 2019
61fe39e
-
Oct 3, 2019
fba5c04
-
Oct 3, 2019
2531bef
change start command
Oct 3, 2019
c5e50b4
add clean up instructions
Oct 3, 2019
1966c61
set option -a 1
Oct 3, 2019
cacf448
moved start instructions to start script
Oct 3, 2019
a0912af
-
Oct 3, 2019
b323bd6
-
Oct 3, 2019
edb207c
-
Oct 3, 2019
61de2b2
-
Oct 3, 2019
b0c251b
added logging
Oct 3, 2019
a22a0e1
improved start.sh
Oct 3, 2019
7837061
improve start script
Oct 3, 2019
70249f6
changed sleep from 5 to 20
Oct 4, 2019
d35853f
-
Oct 4, 2019
995ea78
disabled network_mode host
Oct 4, 2019
7fece14
moved some config from node-red to pigpiod
Oct 4, 2019
c0b3037
further tweaked docker-compose.yml
Oct 4, 2019
803c258
also installed the node-red-node-pi-gpiod
Oct 4, 2019
2068d14
assured the flows are properly setup
Oct 4, 2019
0256fb9
correction
Oct 4, 2019
71ebba5
put balena_flows.json in correct folder
Oct 4, 2019
6cb792d
move balena flow to correct location
Oct 4, 2019
f386cf4
don't overwrite the balena flows file
Oct 4, 2019
0841b4c
added GPIO flow
Oct 4, 2019
83bd513
put flow in correct folder
Oct 4, 2019
639ab3b
pigpiod port mapping
Oct 5, 2019
8af38fb
node-red listens to standard port 1880 instead of 80
Oct 5, 2019
475a1fc
updated the flow
Oct 5, 2019
2b75d2f
add extra logging
Oct 5, 2019
9802358
logging improvement
Oct 5, 2019
582ec59
adding extra check logic
Oct 5, 2019
21dc2ad
improved logging
Oct 5, 2019
4ed737f
readme update
Oct 5, 2019
d676e6f
finalized readme for changes
Oct 5, 2019
ef06933
added link in readme
Oct 5, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# balena-node-red

A Node-RED application with [balena-supervisor](https://balena.io/docs/reference/supervisor/supervisor-api/) flow [support](https://github.com/balena-io-projects/node-red-contrib-balena), can be managed remotely via balena [publicURL](https://balena.io/docs/learn/manage/actions/#enable-public-device-url)
This application consists of 2 services:
* `node-red` = A [Node-RED](https://nodered.org/) application that can be accessed remotely via the balena [publicURL](https://balena.io/docs/learn/manage/actions/#enable-public-device-url). It consists of the following 2 flows (or tabs):
* `Supervisor`: uses [node-red-contrib-balena](https://github.com/balena-io-projects/node-red-contrib-balena) to interact with the [balena-supervisor](https://balena.io/docs/reference/supervisor/supervisor-api/).
* `GPIO`: simple flow shows how the node [node-red-node-pigpiod](https://flows.nodered.org/node/node-red-node-pi-gpiod) can be used to read GPIO pins from the raspberry pi.
* `pigpiod` = this service runs the daemon [pigpiod](http://abyz.me.uk/rpi/pigpio/pigpiod.html). This daemon must be running if you want to interact with the GPIO pins of your raspberry pi using the Node-RED node [node-red-node-pigpiod](https://flows.nodered.org/node/node-red-node-pi-gpiod)

## Configure via [environment variables](https://balena.io/docs/learn/manage/serv-vars/)
## Configure node-red service via [environment variables](https://balena.io/docs/learn/manage/serv-vars/)
Variable Name | Default | Description
------------ | ------------- | -------------
PORT | `80` | the port that exposes the Node-RED UI
PORT | `1880` | the port that exposes the Node-RED editor. Note that host port 80 is mapped to 1880 so that Node-RED editor can also be accessed through the Balena publicURL if activated.
USERNAME | `none` | the Node-RED admin username
PASSWORD | `none` | the Node-RED admin password [hash](https://nodered.org/docs/security#generating-the-password-hash)

Expand Down
19 changes: 14 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
version: '2'
volumes:
resin-data:
node-red-data:
services:
node-red:
build: ./node-red
volumes:
- 'resin-data:/data'
- 'node-red-data:/data'
restart: always
privileged: true
network_mode: host
labels:
io.balena.features.supervisor-api: '1'
ports:
- 80:1880 # will make that the balena public URL maps to the node-red editor.
pigpiod:
build: ./pigpiod
restart: always
privileged: true
cap_add:
- SYS_RAWIO
- SYS_RAWIO # not sure if this is really needed
devices:
# not sure if all below options are really needed.
- "/dev/mem:/dev/mem"
- "/dev/gpiomem:/dev/gpiomem"
- "/dev/i2c-1:/dev/i2c-1"
ports:
- 80:80
# this is only needed in case applications not running on this device also want to connect to
# this pigpiod daemon.
- 8888:8888

3 changes: 2 additions & 1 deletion node-red/Dockerfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ FROM balenalib/%%BALENA_MACHINE_NAME%%-debian-node:12-stretch-build as build
RUN JOBS=MAX npm install -g --production --unsafe-perm \
node-red \
node-red-admin \
node-red-contrib-balena
node-red-contrib-balena \
node-red-node-pi-gpiod

###
# Runtime image
Expand Down
1 change: 1 addition & 0 deletions node-red/app/flow/balena_flows.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"id":"9cc05709.c67948","type":"tab","label":"Supervisor"},{"id":"e40296d5.afa1c8","type":"tab","label":"GPIO","disabled":false,"info":""},{"id":"7b3c835.42a197c","type":"device","z":"9cc05709.c67948","name":"device state","x":290,"y":100,"wires":[["a558696e.8d6a58"]]},{"id":"a558696e.8d6a58","type":"debug","z":"9cc05709.c67948","name":"","active":true,"console":"false","complete":"false","x":530,"y":80,"wires":[]},{"id":"8409e5a5.c42218","type":"inject","z":"9cc05709.c67948","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":100,"y":80,"wires":[["7b3c835.42a197c"]]},{"id":"71dc1612.c5a5b8","type":"ping","z":"9cc05709.c67948","name":"ping supervisor","x":300,"y":160,"wires":[["6ccb806.e54788"]]},{"id":"6ccb806.e54788","type":"debug","z":"9cc05709.c67948","name":"","active":true,"console":"false","complete":"false","x":530,"y":140,"wires":[]},{"id":"33d9d041.abcaf","type":"inject","z":"9cc05709.c67948","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":100,"y":140,"wires":[["71dc1612.c5a5b8"]]},{"id":"d0264e40.37d05","type":"blink","z":"9cc05709.c67948","name":"blink LED","x":280,"y":220,"wires":[["86799168.15833"]]},{"id":"a9c0e5a5.a56b18","type":"inject","z":"9cc05709.c67948","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":100,"y":200,"wires":[["d0264e40.37d05"]]},{"id":"86799168.15833","type":"debug","z":"9cc05709.c67948","name":"","active":true,"console":"false","complete":"false","x":530,"y":200,"wires":[]},{"id":"3a2b2271.e1618e","type":"restart","z":"9cc05709.c67948","name":"restart container","x":300,"y":280,"wires":[["327ce3e4.ef82fc"]]},{"id":"9cfd3e14.edb96","type":"inject","z":"9cc05709.c67948","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":100,"y":260,"wires":[["3a2b2271.e1618e"]]},{"id":"327ce3e4.ef82fc","type":"debug","z":"9cc05709.c67948","name":"","active":true,"console":"false","complete":"false","x":530,"y":260,"wires":[]},{"id":"65836558.590aac","type":"purge","z":"9cc05709.c67948","name":"purge data partition","x":310,"y":400,"wires":[["63c3d14.445573"]]},{"id":"d1e3768f.f61a28","type":"inject","z":"9cc05709.c67948","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":100,"y":320,"wires":[["78f897ea.317e68"]]},{"id":"1e42ca5c.3ea2b6","type":"inject","z":"9cc05709.c67948","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":100,"y":380,"wires":[["65836558.590aac"]]},{"id":"cf8e1b03.362578","type":"debug","z":"9cc05709.c67948","name":"","active":true,"console":"false","complete":"false","x":530,"y":320,"wires":[]},{"id":"63c3d14.445573","type":"debug","z":"9cc05709.c67948","name":"","active":true,"console":"false","complete":"false","x":530,"y":380,"wires":[]},{"id":"78f897ea.317e68","type":"reboot","z":"9cc05709.c67948","name":"reboot device","x":300,"y":340,"wires":[["cf8e1b03.362578"]]},{"id":"9a4a17fb.b0fcf8","type":"inject","z":"9cc05709.c67948","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":100,"y":440,"wires":[["dc1fc581.286e38"]]},{"id":"dc1fc581.286e38","type":"shutdown","z":"9cc05709.c67948","name":"shutdown device","x":310,"y":460,"wires":[["ba67e108.0a268"]]},{"id":"ba67e108.0a268","type":"debug","z":"9cc05709.c67948","name":"","active":true,"console":"false","complete":"false","x":530,"y":440,"wires":[]},{"id":"43ab7b2e.f479c4","type":"debug","z":"e40296d5.afa1c8","name":"PIN: 31","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":360,"y":120,"wires":[]},{"id":"33097ea6.18f122","type":"pi-gpiod in","z":"e40296d5.afa1c8","name":"","host":"pigpiod","port":8888,"pin":"6","intype":"PUD_OFF","debounce":"25","read":true,"x":110,"y":120,"wires":[["43ab7b2e.f479c4"]]},{"id":"df4263f1.1eb73","type":"comment","z":"e40296d5.afa1c8","name":"Below node listens to GPIO pin 31","info":"","x":200,"y":60,"wires":[]}]
264 changes: 0 additions & 264 deletions node-red/app/flows/balena.json

This file was deleted.

4 changes: 2 additions & 2 deletions node-red/app/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

module.exports = {
// the tcp port that the Node-RED web server is listening on
uiPort: process.env.PORT || 80,
uiPort: process.env.PORT || 1880,

// By default, the Node-RED UI accepts connections on all IPv4 interfaces.
// The following property can be used to listen on a specific interface. For
Expand Down Expand Up @@ -48,7 +48,7 @@ module.exports = {
debugMaxLength: 1000,

// The file containing the flows. If not set, it defaults to flows_<hostname>.json
//flowFile: 'flows.json',
flowFile: 'balena_flows.json',

// To enabled pretty-printing of the flow within the flow file, set the following
// property to true:
Expand Down
14 changes: 11 additions & 3 deletions node-red/app/start.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
#!/bin/bash

# Make the default flows available in the user library
mkdir -p /data/node-red/user/lib/flows || true
cp /usr/src/app/flows/* /data/node-red/user/lib/flows/
# Make the flow balena_flows.json available in the user library
mkdir -p /data/node-red/user || true

# only copy the flow balena_flows.json if it doesn't exist as we don't want to overwrite any
# changes made via the node-red editor.
if [ ! -f /data/node-red/user/balena_flows.json ]; then
echo "Copying balena_flows.json from repository to folder /data/node-red/user"
cp /usr/src/app/flow/balena_flows.json /data/node-red/user/balena_flows.json
else
echo "NOT copying balena_flows.json from repository to folder /data/node-red/user as this flow already exists in that folder !!"
fi

# Start app
DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket node-red --settings /usr/src/app/settings.js
12 changes: 12 additions & 0 deletions pigpiod/Dockerfile.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM balenalib/%%BALENA_MACHINE_NAME%%-debian-node:12-stretch-run

RUN apt-get update && \
apt-get install -yq --no-install-recommends \
pigpio \
python-pigpio && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Copy and Start app
ADD start.sh /start.sh
CMD ["bash", "/start.sh"]
Loading