Skip to content

Commit 9521726

Browse files
committed
2024-04-02 Node-RED documentation - master branch
Expands discussion on hardware serial and Bluetooth devices. Follows on from #690 and includes more information about how to enable the devices under Bookworm. Research triggered by comments appended to #761. Signed-off-by: Phill Kelley <[email protected]>
1 parent 7a05f32 commit 9521726

File tree

1 file changed

+103
-31
lines changed

1 file changed

+103
-31
lines changed

docs/Containers/Node-RED.md

Lines changed: 103 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ The third method is *portable*, meaning a flow can conceptually refer to "this"
278278

279279
``` yaml
280280
extra_hosts:
281-
- "host.docker.internal:host-gateway"
281+
- "host.docker.internal:host-gateway"
282282
```
283283

284284
If you use this method, your flows can refer to "this" host using the domain name "host.docker.internal".
@@ -436,7 +436,9 @@ To communicate with your Raspberry Pi's GPIO you need to do the following:
436436
437437
Don't try to use 127.0.0.1 because that is the loopback address of the Node-RED container.
438438

439-
## Serial Port Access { #accessSerial }
439+
## Serial Devices { #accessSerial }
440+
441+
### USB devices { #usbSerial }
440442

441443
Node-RED running in a container *can* communicate with serial devices attached to your Raspberry Pi's USB ports. However, it does not work "out of the box". You need to set it up.
442444

@@ -452,7 +454,6 @@ You have three basic options:
452454

453455
``` yaml
454456
devices:
455-
- …
456457
- "/dev/ttyUSB0:/dev/ttyUSB0"
457458
```
458459

@@ -477,8 +478,7 @@ You have three basic options:
477478

478479
``` yaml
479480
volumes:
480-
- …
481-
- /dev:/dev:ro
481+
- /dev:/dev:ro
482482
```
483483

484484
> The "read-only" flag (`:ro`) prevents the container from doing dangerous things like destroying your Raspberry Pi's SD or SSD. Please don't omit that flag!
@@ -496,8 +496,8 @@ You have three basic options:
496496

497497
``` yaml
498498
device_cgroup_rules:
499-
- 'c 1:* rw' # access to devices like /dev/null
500-
- 'c 188:* rmw' # change numbers to your device
499+
- 'c 1:* rw' # access to devices like /dev/null
500+
- 'c 188:* rmw' # change numbers to your device
501501
```
502502

503503
In the above:
@@ -525,6 +525,102 @@ At the time of writing (Feb 2023), it was not possible to add `node-red-node-ser
525525
RUN npm install node-red-node-serialport --build-from-source
526526
```
527527

528+
### hardware serial port { #piSerial }
529+
530+
Historically, `/dev/ttyAMA0` referred to the Raspberry Pi's serial port. The situation became less straightforward once Pis gained Bluetooth capabilities:
531+
532+
* On Pis *without* Bluetooth hardware:
533+
534+
- `/dev/ttyAMA0` means the serial port; and
535+
- `/dev/serial0` is a symlink to `/dev/ttyAMA0`
536+
537+
* On Pis *with* Bluetooth capabilities:
538+
539+
- `/dev/ttyS0` means the serial port; and
540+
- `/dev/serial0` is a symlink to `/dev/ttyS0`
541+
542+
In addition, whether `/dev/ttyS0` (and, therefore, `/dev/serial0`) are present at runtime depends on adding the following line to `config.txt`:
543+
544+
```
545+
enable_uart=1
546+
```
547+
548+
And, if that isn't sufficiently confusing, the location of `config.txt` depends on the OS version:
549+
550+
* Bullseye (and earlier): `/boot/config.txt`
551+
* Bookworm: `/boot/firmware/config.txt`
552+
553+
Rolling all that together, if you want access to the hardware serial port from Node-RED, you need to:
554+
555+
1. Add `enable_uart=1` to `config.txt`.
556+
2. Reboot.
557+
3. Add a device-mapping to Node-RED's service definition:
558+
559+
``` yaml
560+
devices:
561+
- /dev/serial0:/dev/«internalDevice»
562+
```
563+
564+
where `«internalDevice»` is whatever device the add-on node you're using is expecting, such as `ttyAMA0`.
565+
566+
4. Recreate the Node-RED container by running:
567+
568+
``` console
569+
$ cd ~/IOTstack
570+
$ docker-compose up -d nodered
571+
```
572+
573+
### Bluetooth device { #bluetoothSupport }
574+
575+
If you enable the `node-red-contrib-generic-ble` add on node, you will also need to make the following changes:
576+
577+
1. If you are running Bookworm, you will need to use `sudo` to edit this file:
578+
579+
```
580+
/boot/firmware/config.txt
581+
```
582+
583+
You need to add this line to the end of the file:
584+
585+
```
586+
dtparam=krnbt=off
587+
```
588+
589+
You then need to reboot. This adds the Bluetooth device to `/dev`.
590+
591+
2. Find the the Node-RED service definition in your `docker-compose.yml`:
592+
593+
* Add the following mapping to the `volumes:` clause:
594+
595+
```yaml
596+
- /var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket
597+
```
598+
599+
* Add the following `devices:` clause:
600+
601+
```yaml
602+
devices:
603+
- "/dev/serial1:/dev/serial1"
604+
- "/dev/vcio:/dev/vcio"
605+
- "/dev/gpiomem:/dev/gpiomem"
606+
```
607+
608+
3. Recreate the Node-RED container:
609+
610+
``` console
611+
$ cd ~/IOTstack
612+
$ docker-compose up -d nodered
613+
```
614+
615+
Notes:
616+
617+
* These changes are *specific* to the Raspberry Pi. If you need Bluetooth support on non-Pi hardware, you will need to figure out the details for your chosen platform.
618+
* Historically, `/dev/ttyAMA0` meant the serial interface. Subsequently, it came to mean the Bluetooth interface but only where Bluetooth hardware was present, otherwise it still meant the serial interface.
619+
620+
On Bookworm and later, if it is present, `/dev/ttyAMA1` means the Bluetooth Interface.
621+
622+
On Bullseye and later, `/dev/serial1` is a symbolic link pointing to whichever of `/dev/ttyAMA0` or `/dev/ttyAMA1` means the Bluetooth interface. This means that `/dev/serial1` is the most reliable way of referring to the Bluetooth Interface. That's why it appears in the `devices:` clause above.
623+
528624
## Sharing files between Node-RED and the Raspberry Pi { #fileSharing }
529625

530626
Containers run in a sandboxed environment. A process running inside a container can't see the Raspberry Pi's file system. Neither can a process running outside a container access files inside the container.
@@ -1457,27 +1553,3 @@ All remaining lines of your original *Dockerfile* should be left as-is.
14571553
### Applying the new syntax { #july2022build }
14581554

14591555
Run the [re-building the local Node-RED image](#rebuildNodeRed) commands.
1460-
1461-
## Bluetooth support { #bluetoothSupport }
1462-
1463-
If you enable the `node-red-contrib-generic-ble` add on node, you will also need to make the following changes to the Node-RED service definition in your `docker-compose.yml`:
1464-
1465-
* Add the following mapping to the `volumes:` clause:
1466-
1467-
```yaml
1468-
- /var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket
1469-
```
1470-
1471-
* Add the following `devices:` clause:
1472-
1473-
```yaml
1474-
devices:
1475-
- "/dev/serial1:/dev/serial1"
1476-
- "/dev/vcio:/dev/vcio"
1477-
- "/dev/gpiomem:/dev/gpiomem"
1478-
```
1479-
1480-
Notes:
1481-
1482-
* These changes are *specific* to the Raspberry Pi. If you need Bluetooth support on non-Pi hardware, you will need to figure out the details for your chosen platform.
1483-
* Historically, `/dev/ttyAMA0` meant "the serial interface" on Raspberry Pis. Subsequently, it came to mean "the Bluetooth interface" where Bluetooth support was present. Now, `/dev/serial1` is used to mean "the Bluetooth interface".

0 commit comments

Comments
 (0)