Wanted: Simple steps to connect to a raspberry pi serial port

Hi, I have a desire to use the wmbusmeters snap on a raspberry pi with a CUL-based add-on board that should be accessible via /dev/ttyAMA0.

Snapd is installed using instructions from Install snapd on Raspberry Pi using the Snap Store | Snapcraft

wmbusmeters is installed using instructions from https://wmbusmeters.github.io/wmbusmeters-wiki/SNAP.html

wmbusmeters with verbose logs tells me:

(serial) you do not have the correct permissions to open the tty /dev/ttyAMA0 and you do not share the same access group.

I have tried to connect the ‘serial-port’ but cannot find a way to get any closer than:

$ sudo snap connections --all
Interface       Plug                        Slot             Notes
network         wmbusmeters:network         :network         -
network-bind    wmbusmeters:network-bind    :network-bind    -
raw-usb         wmbusmeters:raw-usb         :raw-usb         manual
serial-port     wmbusmeters:serial-port     -                -
system-observe  wmbusmeters:system-observe  :system-observe  manual

How do I get wmbusmeters:serial-port to point to /dev/ttyAMA0?

$ sudo snap connect wmbusmeters:serial-port /dev/ttyAMA0

$ sudo snap connect wmbusmeters:serial-port core:serial-port
error: snap "core" has no slot named "serial-port"

$ sudo snap connect wmbusmeters:serial-port core:/dev/ttyAMA0
error: snap "core" has no slot named "/dev/ttyAMA0"

I searched and searched - probably for the wrong thing - and haven’t found any for-dummies-explanation that shows which commands or configuration files to work with, so any pointers are very welcome!

Thanks in advance!!

The answer somewhat depends if your raspberry pi uses ubuntu-core as the operating system, or if it is using any other operating system.

On ubuntu-core, hardware accessories are usually statically described by the board-specific gadget snap. There you would find an interface that declares the /dev/ttyAMA0 serial port. On other systems this functionality is also available but it is somewhat more difficult to use, as you need to have a classic gadget that are fairly obscure. In both cases the declaration is static.

A long time ago snapd grew a limited capability to handle hot-plug devices, where without prior declaration an existing device is discovered and made available. This code, to the best of my knowledge, has not been enabled unconditionally and sits behind a feature flag that you may enable or disable on individual installations.

You can give this a try by running:

snap set system experimental.hotplug=true

This should give you a new serial port you can connect to with snap connect. If for whatever reason you want to back out of that, use snap unset system experimental.hotplug.

It is a newly installed raspbian OS, so a debian ‘bullseye’.

I ran ‘sudo snap set system experimental.hotplug=true’ and rebooted. There seems to be no serial ports added:

$ sudo snap connections --all
Interface       Plug                        Slot             Notes
network         wmbusmeters:network         :network         -
network-bind    wmbusmeters:network-bind    :network-bind    -
raw-usb         wmbusmeters:raw-usb         :raw-usb         manual
serial-port     wmbusmeters:serial-port     -                -
system-observe  wmbusmeters:system-observe  :system-observe  manual

There are two serial ports available in hardware:

$ dmesg|grep serial|grep tty
[    3.208463] 3f201000.serial: ttyAMA0 at MMIO 0x3f201000 (irq = 99, base_baud = 0) is a PL011 rev2
[    3.218045] 3f215040.serial: ttyS0 at MMIO 0x3f215040 (irq = 71, base_baud = 50000000) is a 16550

Where can I read about the classig gadget approach?

Classic gadget is just a gadget snap that is meant for classic and has interfaces. The problem is then you have to have a model assertion, a brand and a few things have to be signed right.

I did this a while ago but I cannot remember the details of how to do this with the snap store. I think it starts with a gadget snap that you upload as yourself to the store but I think this requires some permissions (gadgets) and you won’t be able to experiment entirely offline AFAIK.

As for the serial port, having a look at the code, at present, it is only limited to USB-attached serial. If you ran Ubuntu Core the serial port /ttyAMA0 is exported as bt-serial (you can look at /snap/pi/current/meta/snap.yaml to confirm that).

I think I understand. It doesn’t sound like a feasible route. I think I have to abandon snap and go another route. Thank you very much for your insights!

I think you should be able to use your snap on a Ubuntu Core running on the same hardware. Running classic distributions like Raspbian on a Pi is good for development but not so good when you have many of them to look after or keep up-to-date.