forked from gcgarner/IOTstack
-
Notifications
You must be signed in to change notification settings - Fork 308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kernel update may remove /dev/ttyAMA0
#690
Comments
Paraphraser
added a commit
to Paraphraser/IOTstack
that referenced
this issue
May 15, 2023
…nch - PR 1 of 3 Background: - SensorsIot#690 – Kernel update may remove /dev/ttyAMA0 Changes: 1. Removes Bluetooth-specific volumes and devices from template. 2. Updates TZ to `TZ=${TZ:-Etc/UTC}` syntax. 3. Realigns build arguments (yamllint). 4. Adds documentation to Node-RED wiki page (master branch) to explain how to re-add volumes and devices if Bluetooth support is required on a Raspberry Pi: - This means Node-RED will launch successfully on non-Pi hardware. - Documentation references `/dev/serial1` rather than `/dev/ttyAMA0`. Signed-off-by: Phill Kelley <[email protected]>
Paraphraser
added a commit
to Paraphraser/IOTstack
that referenced
this issue
May 15, 2023
…ranch - 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]>
Paraphraser
added a commit
to Paraphraser/IOTstack
that referenced
this issue
May 15, 2023
…al branch - PR 3 of 3 Background: - SensorsIot#690 – Kernel update may remove /dev/ttyAMA0 Changes: 1. Removes Bluetooth-specific volumes and devices from template. 2. Updates TZ to `TZ=${TZ:-Etc/UTC}` syntax. 3. Realigns build arguments (yamllint). 4. Removes `networks` and `logging` clauses (now harmonised with master and old-menu branches). Documentation on this branch not changed. Signed-off-by: Phill Kelley <[email protected]>
Paraphraser
added a commit
to Paraphraser/IOTstack
that referenced
this issue
May 15, 2023
…h - PR 1 of 2 Background: - SensorsIot#690 – Kernel update may remove /dev/ttyAMA0 Changes: 1. Replaces `ttyAMA0` with `serial0` in master path list. 2. Realigns comment and multiple trailing blank lines (yamllint). 3. Documentation adjusted to cater for both menu situations. Signed-off-by: Phill Kelley <[email protected]>
Paraphraser
added a commit
to Paraphraser/IOTstack
that referenced
this issue
May 15, 2023
…nch - PR 2 of 2 Background: - SensorsIot#690 – Kernel update may remove /dev/ttyAMA0 Changes: 1. Adopts generic syntax for device specification to prompt user to add the relevant key (`DECONZ_DEVICE_PATH`) and path (eg `/dev/serial0`) to `.env`. Example: ``` $ echo DECONZ_DEVICE_PATH=/dev/serial0 >>~/IOTstack/.env ``` 2. Reduces documentation to a stub pointing to the deCONZ page of the IOTstack Wiki. Signed-off-by: Phill Kelley <[email protected]>
Paraphraser
added a commit
to Paraphraser/IOTstack
that referenced
this issue
May 16, 2023
…er branch - PR 1 of 2 Background: - SensorsIot#690 – Kernel update may remove /dev/ttyAMA0 - [Home Assistant documentation](https://www.home-assistant.io/installation/raspberrypi#docker-compose) Changes: 1. Removes Bluetooth-specific volumes and devices from template. 2. Removes Pi-hardware-specific image options (still available but no longer mentioned in the Home Assistant documentation; and not relevant where IOTstack may be deployed on non-Pi hardware). 3. Adds documentation to Home Assistant wiki page (master branch) to explain how to re-add volumes and devices if Bluetooth support is required on a Raspberry Pi: - This means Home Assistant will launch successfully on non-Pi hardware. - Documentation references `/dev/serial1` rather than `/dev/ttyAMA0` as the external device but maintains the latter as the internal device. 3. Removes documentation from the Home Assistant wiki page (master branch) where Pi-hardware-specific image options were discussed. Signed-off-by: Phill Kelley <[email protected]>
Paraphraser
added a commit
to Paraphraser/IOTstack
that referenced
this issue
May 16, 2023
…menu branch - PR 2 of 2 Background: - SensorsIot#690 – Kernel update may remove /dev/ttyAMA0 - [Home Assistant documentation](https://www.home-assistant.io/installation/raspberrypi#docker-compose) Changes: 1. Removes Bluetooth-specific volumes and devices from template. 2. Removes hardware-specific image options (still available but no longer mentioned in the Home Assistant documentation; and not relevant where IOTstack may be deployed on non-Pi hardware). 3. Adds privileged flag (present on master branch and specified in the Home Assistant documentation). Signed-off-by: Phill Kelley <[email protected]>
Paraphraser
added a commit
to Paraphraser/IOTstack
that referenced
this issue
May 16, 2023
…anch - PR 1 of 2 Background: - SensorsIot#690 – Kernel update may remove /dev/ttyAMA0 Changes: 1. Adopts generic syntax for device specification to prompt user to add the relevant key (`OCTOPRINT_DEVICE_PATH`) and path (eg `/dev/ttyUDB0`) to `.env`. Example: ``` $ echo OCTOPRINT_DEVICE_PATH=/dev/ttyUSB0 >>~/IOTstack/.env ``` 2. Adopts `TZ=${TZ:-Etc/UTC}` 3. Corrects YAML "errors" identified by `yamllint`. 4. Rewrites documentation to explain the how-to of device-path setup in various situations. Signed-off-by: Phill Kelley <[email protected]>
Paraphraser
added a commit
to Paraphraser/IOTstack
that referenced
this issue
May 16, 2023
…branch - PR 2 of 2 Background: - SensorsIot#690 – Kernel update may remove /dev/ttyAMA0 Changes: 1. Adopts generic syntax for device specification to prompt user to add the relevant key (`OCTOPRINT_DEVICE_PATH`) and path (eg `/dev/ttyUDB0`) to `.env`. Example: ``` $ echo OCTOPRINT_DEVICE_PATH=/dev/ttyUSB0 >>~/IOTstack/.env ``` 2. Adopts `TZ=${TZ:-Etc/UTC}` 3. Corrects YAML "errors" identified by `yamllint`. Signed-off-by: Phill Kelley <[email protected]>
Paraphraser
added a commit
to Paraphraser/IOTstack
that referenced
this issue
May 16, 2023
…branch - PR 1 of 2 Background: - SensorsIot#690 – Kernel update may remove /dev/ttyAMA0 Changes: 1. Adopts generic syntax for device specification to prompt user to add the relevant key (`ZIGBEE2MQTT_DEVICE_PATH`) and path (eg `/dev/ttyUSB0`) to `.env`. Example: ``` $ echo ZIGBEE2MQTT_DEVICE_PATH=/dev/ttyUSB0 >>~/IOTstack/.env ``` 2. Adopts `TZ=${TZ:-Etc/UTC}` 3. Adds (disabled) environment variable to enable debugging. 4. Rewrites documentation to explain the how-to of device-path setup. Signed-off-by: Phill Kelley <[email protected]>
Paraphraser
added a commit
to Paraphraser/IOTstack
that referenced
this issue
May 16, 2023
…u branch - PR 2 of 2 Background: - SensorsIot#690 – Kernel update may remove /dev/ttyAMA0 Changes: 1. Adopts generic syntax for device specification to prompt user to add the relevant key (`ZIGBEE2MQTT_DEVICE_PATH`) and path (eg `/dev/ttyUSB0`) to `.env`. Example: ``` $ echo ZIGBEE2MQTT_DEVICE_PATH=/dev/ttyUSB0 >>~/IOTstack/.env ``` 2. Adopts `TZ=${TZ:-Etc/UTC}` 3. Adds (disabled) environment variable to enable debugging. Signed-off-by: Phill Kelley <[email protected]>
Open
Paraphraser
added a commit
to Paraphraser/IOTstack
that referenced
this issue
Apr 2, 2024
Expands discussion on hardware serial and Bluetooth devices. Follows on from SensorsIot#690 and includes more information about how to enable the devices under Bookworm. Research triggered by comments appended to SensorsIot#761. Signed-off-by: Phill Kelley <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Kernel update may remove
/dev/ttyAMA0
This post is intended to be:
Problem summary:
IOTstack uses
/dev/ttyAMA0
in two roles:/dev/ttyAMA0
with an actual serial or USB device (eg Zigbee adapter).The kernel change will have the effect of renaming
/dev/ttyAMA0
to/dev/serial1
. This will break any service definitions that rely on ttyAMA0.It is opportune to consider the wider implications of using Raspberry-Pi-specific devices names in a world where IOTstack is increasingly being deployed on non-Raspberry-Pi hardware.
All comments, criticisms and suggestions are welcome!!!!
Background
The background to this issue is two interrelated discussions started by @S474N :
To summarise my understanding:
@S474N used
sudo rpi-update
(rather thanapt upgrade
) to force a kernel update.This resulted in a kernel where
/dev/ttyAMA0
was no longer defined.The most immediate manifestation of this was when attempting to bring up the Node-RED container. Its service definition includes:
docker-compose will not instantiate a container if the external (left hand side) device
/dev/ttyAMA0
is not present.Historical context
Discussion on the Raspberry Pi forum suggests that the Raspberry Pi's "serial ports" have a slightly chequered family tree. I'm not sure I have this 100% right but I think it covers the basics:
historically,
/dev/ttyAMA0
meant the Raspberry Pi's serial port.when Pis gained Bluetooth capabilities:
/dev/ttyAMA0
came to mean the Bluetooth adapter; and/dev/ttyS0
meant the serial port, but only if/boot/config.txt
containedenable_uart=1
./dev/serial0
is a symlink to:/dev/ttyS0
on Pis with Bluetooth capability (assumingenable_uart=1
); but/dev/ttyAMA0
on Pis without Bluetooth capability,which makes
/dev/serial0
the preferred device to use when your actual intention is to refer to "the serial port"./dev/serial1
is:/dev/ttyAMA0
on Pis with Bluetooth capability, butwhich makes
/dev/serial1
the preferred device to use when your actual intention is to refer to the "Bluetooth adapter".Apparently, none of this is particularly new. We really should have been using serial0 and serial1 all along.
Kernel updates - coming fast
What is new is the notion that ttyAMA0 is about to be withdrawn in favour of serial1.
As of 2023-05-05, anyone keeping up-to-date via routine
apt upgrade
will probably have kernel 6.1.21-v8+.The version of the kernel where ttyAMA0 has been withdrawn is 6.1.25-v8+. It was installed by
rpi-update
so it's in advance of what you get if you stick toapt upgrade
. It's also a test version, meaning there is no final decision on whether ttyAMA0 will disappear once this kernel gets to final release.Revision .21 to .25 is not a big gap so, unless something changes such that
/dev/ttyAMA0
is preserved, we (IOTstack) are about to bang into this.IOTstack service definitions
Table 1 lists all the existing IOTstack master-branch service definitions that contain relevant
devices:
clauses.Node-RED
I'll deal with this first because it's likely to be the most immediate problem for the majority of IOTstack users.
The IOTstack service definition for Node-RED assumes flows may need access to the Raspberry Pi's Bluetooth adapter via the
node-red-contrib-generic-ble
add-on node ("BLE"). The BLE nodes depend on :The first line is the subject of this discussion. The other two devices (vcio and gpiomem) are also required for the BLE nodes to work on the Raspberry Pi so it's really an all-or-nothing deal.
The most appropriate response to the anticipated kernel change is:
If your flows need access to Bluetooth, replace the first device mapping above with:
- "/dev/serial1:/dev/serial1"
Changing the left-hand-side to
/dev/serial1
can be done now, ahead of the expected kernel change. It won't break any existing implementations.If your flows do not need access to Bluetooth:
devices
clause.See also Node-RED reference service definition.
deconz
master branch
/dev/null
is a placeholder which is replaced during a menu run. The template folder holds the master list:The menu generates an intermediate list stored in:
and then the content of the
hardware:
clause is merged into both of the following:~/IOTstack/services/docker-compose.save.yml
~/IOTstack/docker-compose.yml
The result is:
This is a placeholder role so the appropriate treatment is to replace ttyAMA0 in the master list with serial0.
However, that won't deal with any existing implementations unless the user:
git pull
to synchronise the local copy with GitHub.It's probably simpler to just hand-edit the three files in situ and replace "ttyAMA0" with "serial0":
~/IOTstack/services/deconz/build_settings.yml
~/IOTstack/services/docker-compose.save.yml
~/IOTstack/docker-compose.yml
old-menu branch
Old-menu branch has three separate service definition files. The most relevant is
service_raspbee.yml
which will need "ttyAMA0" to be replaced as discussed later at Generalising the placeholder problem.Home Assistant (container)
The current IOTstack service definition differs quite significantly from the home-assistant.io service definition:
All the highlighted lines were added by #485. The
devices:
are the same as for Node-RED so it's a Bluetooth role (confirmed by the PR). The service definition also has the "privileged" flag set. That does a whole lot of (IMO mostly bad) things, including mapping the whole of the host's/dev
into the container. In other words, the container can already see all the host's devices. Adding a subset via adevices:
clause does nothing.In terms of the problem at hand, simply removing the
devices:
clause causes the anticipated kernel update problem to go away. The container still has access to everything it needs because of the privileged flag.Old-menu branch lacks both the highlighted lines and the privileged flag. It will need to be harmonised.
Octoprint
In this case, ttyAMA0 is being used as a placeholder for a serial or USB device. Octoprint inside the container expects the 3D printer to appear on
/dev/ttyACM0
so the left hand side of the mapping must be changed to point to the actual 3D printer.This placeholder will break if
/dev/ttyAMA0
goes away.Zigbee2MQTT
This is another placeholder for a serial device which is going to break if
/dev/ttyAMA0
goes away. The left hand side of the mapping needs to be changed to point to the Zigbee adapter.The wider problem - when it isn't a Raspberry Pi
When IOTstack is installed on something that isn't a Raspberry Pi, the majority of IOTstack device mappings cause problems. That's because the devices listed in the templates are all specific to the Raspberry Pi OS and hardware. Using ttyAMA0 in both Bluetooth and placeholder roles just adds complexity.
The closest IOTstack gets to dealing with this problem is the troubleshooting section of the Wiki which basically says "comment-out the devices".
That's a little unsubtle (I wrote it so I can say that) because it doesn't really deal with the nuances.
There's no real way to automate device discovery. I can't see how the IOTstack menu is ever going to be sophisticated enough to be able to auto-discover answers to questions like:
What's the Bluetooth adapter called on this platform?
Does the absence of
/dev/«device»
mean:gpiomen
on non-Pi; orIs the fact that
/dev/ttyAMA0
existed yesterday but doesn't exist today explained by:Absent the menu acquiring sufficient smarts, the only real solution is human involvement to customise compose files after the menu has created the basic scaffolding.
Generalising the placeholder problem
I'm going to use Zigbee2MQTT as my example but the same principles apply to Octoprint and the old-menu version of Deconz.
The current Zigbee2MQTT service definition contains:
Interpretation:
It's a placeholder role so the "correct" replacement is:
However, as discussed earlier:
enable_uart=1
in/boot/config.txt
; andIn other words, serial0 being defined is the exception rather than the rule so, most of the time, docker-compose will refuse to start the container.
That leads to the temptation to perpetuate the both the current solution and the current problem by falling back upon serial1 for no better reason that "it's there":
Well, it's there on the Raspberry Pi so it will keep docker-compose happy on the Raspberry Pi. But it will still fail on non-Raspberry Pi.
Plus, even though serial1 keeps docker-compose happy on the Raspberry Pi, it still doesn't actually work. A Bluetooth interface isn't a Zigbee adapter, or a 3D printer, or whatever else a container might be expecting. The user still has to provide the actual device the container is expecting.
More to the point, using serial1 as a placeholder masks the problem. The user gets no insights into why the Zigbee container isn't actually working.
Providing the actual device generally boils down to the choice of:
/dev/ttyACMx
or/dev/ttyUSBx
), using that device name on the left hand side of adevices:
mapping, and accepting that device enumeration may well change the value of "x" thereby causing a mess; or/dev/serial/by-id/«identity»
path for a more robust solution; or/dev/My3DPrinter
or/dev/Zigbee_CC2531
) and using that.What's really needed is a way to prompt the user to figure out the correct device and communicate that to docker-compose. A "right place, right time" approach!
This is the generic syntax I'm proposing for placeholder roles:
For Zigbee2MQTT it would be something like this:
On first install, a user will get the following error message:
As error messages go, it could be more succinct but it does point you in the direction of the Zigbee2MQTT service definition.
In my case, I have a UDEV rule which establishes
/dev/Zigbee_CC2531
when the adapter is connected so I can meet this requirement with:You're probably wondering what happens if
/dev/Zigbee_CC2531
is defined in.env
but is not present at "up" time because I've disconnected the Zigbee adapter?Because I did the work of creating a UDEV rule, the error is still pointing in the right direction. The message is less informative if you use by-id or just-as-it-comes from host enumeration (
/dev/ttyACM0
) but we have to work with what we have.Generalising the Bluetooth problem
We have exactly two examples:
Home Assistant. It is using the privileged flag so the container already has access to the totality of the host's
/dev
. There's no need to double-up. The IOTstack service definition should mirror the "official" version from Home Assistant.This will work out-of-the-box on all platforms.
See also D-Bus socket.
Node-RED. I think the best solution is to remove the three devices from the service definition, and then document what is required if Bluetooth needs to be enabled.
Re-adding the three devices, by hand, will work out-of-the-box on the Pi.
For non-Pi, the user still has to figure out how the Bluetooth adapter presents itself and make the appropriate substitution. For example, on macOS that's likely to be:
If you're wondering, "why not use the privileged flag for Node-RED?" The answer is "because it's far too risky". Think about what
/dev
actually means. It includes things like:/dev/mem
- all the memory on the machine; and/dev/disk
- all your attached storage (SD/SSD)."Privileged" grants access to every add-on node, regardless of provenance. It's just not safe to bake that into IOTstack by default.
See also:
Related issues
D-Bus socket
The IOTstack service definition for Node-RED contains a volume mapping to the D-Bus socket. This was added, by me, via #70, for no better reason than if the node-red-contrib-generic-ble is included in the Dockerfile, the container goes into a restart loop unless this volume mapping is present.
The IOTstack master branch service definition for Home Assistant contains the same lines but it's not clear whether the author of #485 (@Tzaphkiel) came to the same conclusion (needed to avoid a restart loop) or if it was part of #485 because it was added in #70 (following the leader, as it were).
Googling "DBus site:.home-assistant.io" gets quite a few hits and many of them mention Bluetooth but I haven't been able to find anything recommending this volume mapping. Conversely, this link explains that D-Bus is how the HA Supervisor communicates with the host.
The container version of HA lacks the Supervisor, which is why many people run HA as an appliance, so this volume mapping would seem to be unnecessary. To put it another way, if this mapping was needed either generally or on the Pi, I would expect to find it mentioned in the HA documentation.
Although there's nothing wrong, per se, with a container engaging in inter-process communications via the host's D-Bus, it always bothers me when I see files in a compose file's volume mapping. That's because of what docker-compose does when it is bringing up a container. If the left hand side is missing, docker-compose treats the path as a specification for a directory and does the equivalent of a
mkdir -p
. Any processes expecting to find a file then get mightily confused and the result is a mess.In any normal system, D-Bus will always be running by the time docker-compose gets involved so this path will always point to a file. On the other hand, that D-Bus issues page probably wouldn't exist if D-Bus had never ever fouled-up so…
I wasn't really aware of this consideration when I proposed #70 so, on balance, it would be better if this line was removed from the template and the need for it documented for anyone wanting to enable Bluetooth access in Node-RED.
Docker socket
Issue #64 documents my experiments with Bluetooth prior to proposing #70. Part way through I wrote:
The current version of node-red-contrib-generic-ble no longer fails when
/var/run/docker.sock
is missing. That means it is no longer necessary so I'm proposing to remove it.Node-RED reference service definition
I'm providing these in advance of any Pull Request getting into IOTstack. Node-RED is the thing most likely to fail if ttyAMA0 goes away so good working reference definitions may come in handy.
The Node-RED service definition will be:
The Node-RED Wiki page will explain that enabling BLE access:
on the Raspberry Pi depends on:
Adding the foll,owing volume mapping:
- /var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket
Adding the following device mappings:
on non-Pi, depends on identifying the equivalent mappings.
The text was updated successfully, but these errors were encountered: