Acessing serial device from a snap package

Hi,

I’m trying to access a board (Razberry HAT) attached the GPIO pins on a Rasberry Pi 3+.

The snap package I’m using is zwavejs2mqtt on a Rasbian (and Ubuntu Server «classic») OS. I’m not using Ubuntu Core.

The device is available at /dev/ttyAMA0. I’ve confirmed it working by compiling Zwavejs2MQTT and run it outside of the snap environment.

However I’m not able to access it from within the snap. The board is not listed from the command snap interface serial-port, only zwavejs2mqtt:serial-port shows up, so there’s no connection to be made between the snap and the OS.

Anyone that can guide me to a fix?

Have you tried turning on the experimental hotplug support? https://snapcraft.io/docs/hotplug-support

Hi, yes I have that enabled.

@rpi:~/zwavejs2mqtt $ sudo snap get system experimental
Key                   Value
experimental.hotplug  true

But isn’t that for «USB to serial» devices?

EDIT: Seems like the only way of accessing the device, is to install it in --devmode and edit the udev rules:

$ echo "SUBSYSTEM==\"usb\", MODE=\"0660\", GROUP=\"root\"" | sudo tee /etc/udev/rules.d/00-usb-permissions.rules
$ sudo udevadm control --reload-rules

Installing it with --classic (doesn’t work) or --devmode (works) shouldn’t be the solution.

I’ve tried to look for DENIED messages in dmesg (and with snappy-debug) without any success.

Heres the output of udevadm info -a -n /dev/ttyAMA0:

@rpi:~/zwavejs2mqtt $ udevadm info -a -n /dev/ttyAMA0

Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.

  looking at device '/devices/platform/soc/3f201000.serial/tty/ttyAMA0':
    KERNEL=="ttyAMA0"
    SUBSYSTEM=="tty"
    DRIVER==""
    ATTR{close_delay}=="50"
    ATTR{closing_wait}=="3000"
    ATTR{console}=="N"
    ATTR{custom_divisor}=="0"
    ATTR{flags}=="0x10000000"
    ATTR{io_type}=="2"
    ATTR{iomem_base}=="0x3F201000"
    ATTR{iomem_reg_shift}=="0"
    ATTR{irq}=="114"
    ATTR{line}=="0"
    ATTR{port}=="0x0"
    ATTR{power/control}=="auto"
    ATTR{power/runtime_active_time}=="0"
    ATTR{power/runtime_status}=="unsupported"
    ATTR{power/runtime_suspended_time}=="0"
    ATTR{type}=="32"
    ATTR{uartclk}=="48000000"
    ATTR{xmit_fifo_size}=="16"

  looking at parent device '/devices/platform/soc/3f201000.serial':
    KERNELS=="3f201000.serial"
    SUBSYSTEMS=="amba"
    DRIVERS=="uart-pl011"
    ATTRS{driver_override}=="(null)"
    ATTRS{id}=="00241011"
    ATTRS{irq0}=="114"
    ATTRS{power/control}=="auto"
    ATTRS{power/runtime_active_time}=="1104747"
    ATTRS{power/runtime_status}=="active"
    ATTRS{power/runtime_suspended_time}=="0"

  looking at parent device '/devices/platform/soc':
    KERNELS=="soc"
    SUBSYSTEMS=="platform"
    DRIVERS==""
    ATTRS{driver_override}=="(null)"
    ATTRS{power/control}=="auto"
    ATTRS{power/runtime_active_time}=="0"
    ATTRS{power/runtime_status}=="unsupported"
    ATTRS{power/runtime_suspended_time}=="0"

  looking at parent device '/devices/platform':
    KERNELS=="platform"
    SUBSYSTEMS==""
    DRIVERS==""
    ATTRS{power/control}=="auto"
    ATTRS{power/runtime_active_time}=="0"
    ATTRS{power/runtime_status}=="unsupported"
    ATTRS{power/runtime_suspended_time}=="0"

as you have already found, hotplug support only works for USB devices … serial interface slots can only be provided by gadget snaps, the only way out here would be to build a classic image with a classic gadget snap from scratch … or to switch to Ubuntu Core …

But then again, I have to roll my own to access the serial port?

This won’t be an option. I’m quite sure the users that want to use the snap package of zwavejs2mqtt is not willing to use another OS than they have already installed. They most likely have a bunch of other services already running on their system.

Which is wrong. :slight_smile:

On a RPi3: Editing the config.txt in the ubuntu seed partition with:

enable_uart=1
dtoverlay=pi3-miniuart-bt
core_freq=250
  • and remove the console=-.-.-- from cmdline.txt
  • and plugging the zwavejs2mqtt:serial-port to pi:bt-serial

works! I did this before the initial «seeding» on a fresh SD-card. Not sure if the seeding part from the these files only happens once or not.

yay ! great you found a way … (though you might indeed lose bluetooth that way)

Yay! :smiley: I don’t need bluetooth. I think the bt-serial slot in the core is just referring to the path /dev/ttyAMA which this needs. :slight_smile:

1 Like