Skip to content

Commit

Permalink
Node-Red - add support for node-red-contrib-generic-ble
Browse files Browse the repository at this point in the history
Following on from issue SensorsIot#64, this adds support for Bluetooth in
Node-Red:

1. Adds two volume mappings to the template `service.yml`:

	```
	- /var/run/docker.sock:/var/run/docker.sock
	- /var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket
	```

2. Adds device mappings to the template `service.yml`:

	```
	devices:
		- "/dev/ttyAMA0:/dev/ttyAMA0"
		- "/dev/vcio:/dev/vcio"
		- "/dev/gpiomem:/dev/gpiomem"
	```

3. Changes `build.sh` to:

	* unconditionally satisfy the `eudev-dev` dependency for
`node-red-contrib-generic-ble` by inserting these lines in the
generated `Dockerfile`:

		```
		USER root
		RUN apk update
		RUN apk upgrade
		RUN apk add --no-cache eudev-dev
		```

	* Add `node-red-contrib-generic-ble` to the list of optional nodes.

4. Changes `menu.sh` to:

	* define a `user_in_group` function to facilitate checking whether
the current user is a member of a particular group.
	* extends the initial checking performed by the menu to ensure that
the current user is a member of both `docker` and `bluetooth` groups.

> On the first run of the menu after this patch is applied, most users
will likely encounter a reboot prompt enforcing membership of the
`bluetooth` group.
  • Loading branch information
Paraphraser committed Nov 12, 2020
1 parent afb4733 commit 91c3fc3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .templates/nodered/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ node_selection=$(whiptail --title "Node-RED nodes" --checklist --separate-output
"node-red-contrib-alexa-local" " " "OFF" \
"node-red-contrib-heater-controller" " " "OFF" \
"node-red-contrib-deconz" " " "OFF" \
"node-red-contrib-generic-ble" " " "OFF" \
3>&1 1>&2 2>&3)

##echo "$check_selection"
Expand All @@ -51,6 +52,12 @@ sqliteflag=0

touch $nr_dfile
echo "FROM nodered/node-red:latest" >$nr_dfile

echo "USER root" >>$nr_dfile
echo "RUN apk update" >>$nr_dfile
echo "RUN apk upgrade" >>$nr_dfile
echo "RUN apk add --no-cache eudev-dev" >>$nr_dfile

#node red install script inspired from https://tech.scargill.net/the-script/
echo "RUN for addonnodes in \\" >>$nr_dfile
for checked in "${checked_nodes[@]}"; do
Expand Down
6 changes: 6 additions & 0 deletions .templates/nodered/service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@
- "1880:1880"
volumes:
- ./volumes/nodered/data:/data
- /var/run/docker.sock:/var/run/docker.sock
- /var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket
devices:
- "/dev/ttyAMA0:/dev/ttyAMA0"
- "/dev/vcio:/dev/vcio"
- "/dev/gpiomem:/dev/gpiomem"
33 changes: 30 additions & 3 deletions menu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ declare -a armhf_keys=(
"adminer"
"openhab"
"zigbee2mqtt"
"deconz"
"deconz"
"pihole"
"plex"
"tasmoadmin"
Expand Down Expand Up @@ -133,6 +133,11 @@ function command_exists() {
command -v "$@" > /dev/null 2>&1
}

function user_in_group()
{
groups | grep -q "\b$1\b"
}

function minimum_version_check() {
# minimum_version_check required_version current_major current_minor current_build
# minimum_version_check "1.2.3" 1 2 3
Expand Down Expand Up @@ -355,8 +360,29 @@ if command_exists docker; then
sudo apt upgrade docker docker-compose
fi
fi

requestRebootflag=0

for G in docker bluetooth ; do

if user_in_group $G ; then
echo "checked membership of $G group."
else
echo "user is NOT a member of the $G group. Setting it now."
sudo usermod -G $G -a $USER
requestRebootflag=1
fi

done

if [ $requestRebootflag = 1 ] ; then
if (whiptail --title "Restart Required" --yesno "It is recommended that you restart your device now. Select yes to do so now" 20 78); then
sudo reboot
fi
fi

else
echo "docker not installed"
echo "docker not installed - you must choose Install Docker"
fi

#---------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -384,7 +410,8 @@ case $mainmenu_selection in
else
echo "Install Docker"
curl -fsSL https://get.docker.com | sh
sudo usermod -aG docker $USER
sudo usermod -G docker -a $USER
sudo usermod -G bluetooth -a $USER
fi

if command_exists docker-compose; then
Expand Down

0 comments on commit 91c3fc3

Please sign in to comment.