Skip to content

Commit 4040c47

Browse files
committed
2023-05-15 Node-RED adaptation to expected kernel change - old-menu branch - PR 2 of 3
Background: - SensorsIot#690 – Kernel update may remove /dev/ttyAMA0 Changes: 1. Removes Bluetooth-specific volumes and devices from template. 2. Replaces env-file reference with inline `TZ=${TZ:-Etc/UTC}`. 3. Realigns build arguments (yamllint). 4. Removes outdated nodered.env file. 5. Reduces documentation to a stub pointing to the Node-RED page of the IOTstack Wiki. Signed-off-by: Phill Kelley <[email protected]>
1 parent fea7968 commit 4040c47

File tree

3 files changed

+5
-126
lines changed

3 files changed

+5
-126
lines changed

.templates/nodered/nodered.env

Lines changed: 0 additions & 1 deletion
This file was deleted.

.templates/nodered/service.yml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,14 @@
33
build:
44
context: ./services/nodered/.
55
args:
6-
- DOCKERHUB_TAG=latest
7-
- EXTRA_PACKAGES=
6+
- DOCKERHUB_TAG=latest
7+
- EXTRA_PACKAGES=
88
restart: unless-stopped
99
user: "0"
10-
env_file: ./services/nodered/nodered.env
10+
environment:
11+
- TZ=${TZ:-Etc/UTC}
1112
ports:
1213
- "1880:1880"
1314
volumes:
1415
- ./volumes/nodered/data:/data
1516
- ./volumes/nodered/ssh:/root/.ssh
16-
- /var/run/docker.sock:/var/run/docker.sock
17-
- /var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket
18-
devices:
19-
- "/dev/ttyAMA0:/dev/ttyAMA0"
20-
- "/dev/vcio:/dev/vcio"
21-
- "/dev/gpiomem:/dev/gpiomem"

docs/Containers/Node-RED.md

Lines changed: 1 addition & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1,118 +1,3 @@
11
# Node-RED
2-
## References
3-
- [Docker](https://hub.docker.com/r/nodered/node-red)
4-
- [website](https://nodered.org/)
5-
6-
## Build warning
7-
The Node-RED build will complain about several issues. This is completely normal behaviour.
8-
9-
## SQLite
10-
Thanks to @fragolinux the SQLite node will install now. **WARNING it will output many error and will look as if it has gotten stuck. Just give it time and it will continue.**
11-
12-
## GPIO
13-
To communicate to your Pi's GPIO you need to use the `node-red-node-pi-gpiod` node. It allowes you to connect to multiple Pis from the same nodered service.
14-
15-
You need to make sure that pigpdiod is running. The recommended method is listed [here](https://github.com/node-red/node-red-nodes/tree/master/hardware/pigpiod)
16-
You run the following command `sudo nano /etc/rc.local` and add the line `/usr/bin/pigpiod` above `exit 0` and reboot the Pi. There is an option to secure the service see the writeup for further instuctions.
17-
18-
Fot the Rpi Image you will also need to update to the most recent version
19-
20-
```
21-
sudo apt-get update
22-
sudo apt-get install pigpio python-pigpio python3-pigpio
23-
```
24-
25-
Drop the gpio node and use your Pi's IP. Example: 192.168.1.123 (127.0.0.1 won't work because this is the local address of every computer'.)
26-
27-
## Securing Node-RED
28-
To secure Node-RED you need a password hash. There is a terminal script `./services/nodered/terminal.sh` execute it to get into the terminal.
29-
Copy the helper text `node -e ..... PASSWORD`, paste it and change your password to get a hash.
30-
31-
Open the file `./volumes/nodered/data/settings.js` and follow the writeup on https://nodered.org/docs/user-guide/runtime/securing-node-red for further instructions
32-
33-
34-
## Sharing files between Node-RED and the host
35-
Containers run in a sandboxed environment they can't see the host (the Pi itself) file system. This presents a problem if you want to read a file directly to the host from inside the container. Fortunately there is a method, the containers have been set up with volume mapping. The volume maps a specific directory or file from the host file system into the container. Therefore if you write to that directory both the host and the container can see the files.
36-
37-
Consider the following:
38-
39-
The docker-compose.yml file shows the following for Node-RED
40-
```
41-
volumes:
42-
- ./volumes/nodered/data:/data
43-
```
44-
If inside Node-RED you were to write to the `/data` folder then the host would see it in `~/IOTstack/volumes/nodered/data` (the ./volumes above implies relative to the docker-compose.yml file)
45-
46-
![image](https://user-images.githubusercontent.com/46672225/68073532-e2e51b80-fd99-11e9-955e-3f27e1c57998.png)
47-
48-
The flow writes the file `/data/test.txt` and it is visible in the host as `~/IOTstack/volumes/nodered/data/test.txt`
49-
50-
Remember, files and directories in the volume are persistent between restarts. If you save your data elsewhere it will be destroyed should you restart. Creating a subdirectory in volume i.e. `/data/storage/` would be advised
51-
52-
## Using Bluetooth
53-
In order to allow Node-RED to access the Pi's Bluetooth module the docker-comose.yml file needs to be modified to allow it access. `network_mode: "host"` needs to be added (make sure the indentation is correct, us spaces not tabs):
54-
55-
```
56-
nodered:
57-
container_name: nodered
58-
build: ./services/nodered/.
59-
restart: unless-stopped
60-
user: "0"
61-
network_mode: "host"
62-
```
63-
By activating host mode the Node-RED container can no longer access containers by name `http://influxdb:8086` will no longer work. Node-RED thinks it now is the host and therefore access to the following services will look as follows:
64-
* influxdb `http://127.0.0.1:8086`
65-
* GPIO `127.0.0.1` port `8888`
66-
* MQTT `127.0.0.1`
67-
68-
## Unused node in Protainer
69-
70-
Portainer will report that the nodered image is unsed, this is normal due to the method used build the image. This is normal behavior. It is not advised to remove it as it is used as the base for the iotstack_nodered image, you will need to redownload it should you rebuild the nodered image.
71-
72-
<img width="1444" alt="UnusedImage" src="https://user-images.githubusercontent.com/34226495/69213978-cd555b80-0bb9-11ea-8734-1c42ff52bf7d.png">
73-
74-
## Running the exec node against the host Pi
75-
76-
Due to the isolation between containers and the host the exec node will run against the container.
77-
78-
There is a solution to work around this. You can use ssh to execute a script on the pi. It requires a little setup but is possible.
79-
80-
For this example I'll be running a simple script called test.sh
81-
I create a file called test.sh in my IOTstack directory with nano
82-
83-
The contents are as follows:
84-
```bash
85-
#!/bin/bash
86-
echo "hello"
87-
exit 0
88-
```
89-
90-
The exit 0 will stop the exec node from reporting an issue.
91-
92-
Its a good idea to add the shebang at the top. make it executable with `chmod +x test.sh`
93-
94-
This nodered running open the nodered terminal with `./services/nodered/terminal.sh` or `docker exec -it nodered /bin/bash` or use portainer
95-
96-
create the ssh folder in the data directory (the /data directory is persistently mapped volume)
97-
98-
`mkdir -p /data/ssh`
99-
100-
create key, this will require naming the output file
101-
102-
`ssh-keygen -f /data/ssh/nodered` put in any additional config you want key type strength
103-
copy the key to the Pi. When asked for a password leave it blank
104-
105-
copy the ssh-key to your pi
106-
107-
`ssh-copy-id -i /data/ssh/nodered [email protected]` replace with your static IP address. You will have to reply yes to the prompt. You may also see an error referring to regular expressions however you can ignore it.
108-
109-
now to execute a script on the pi run `ssh -i /data/ssh/nodered [email protected] /home/pi/IOTstack/test.sh`
110-
111-
type exit to leave the terminal
112-
113-
(you could also restart your pi with `ssh -i /data/ssh/nodered [email protected] sudo reboot`)
114-
115-
in node red in your exec node you can run the command `ssh -i /data/ssh/nodered [email protected] /home/pi/IOTstack/test.sh` other the script or command of your choice
116-
117-
![image](https://user-images.githubusercontent.com/46672225/70431264-55c27000-1a85-11ea-8706-b087dc39479d.png)
1182

3+
Node-RED documentation can be found on the [IOTstack Wiki](https://sensorsiot.github.io/IOTstack/Containers/Node-RED/).

0 commit comments

Comments
 (0)