Sharing docker-compose between Pi2 and Pi3, and accessing serial port

Hi all,

I’ve got an application that’s communicating with hardware over the serial port.

I’ve got two Resinio Starter type Applications, based on the RPi 2 and RPi 3 respectively.

I’m able to get both working independently so they can successfully both receive and send info over the GPIO pins. Awesome!

Now my issue - I’d really like to support both platforms from the same code base.

Here’s an extract from my docker-compose.yml file:

devices:
  - "/dev/ttyAMA0:/dev/ttyAMA0"
  - "/dev/ttyS0:/dev/ttyS0"
  - "/dev/mem:/dev/mem"

I’ve defined some Application Service variables, which I use to override the port connected to - this is great, so I connect to ttyS0 on a Pi3, and ttyAMA0 on the Pi2.

This is all good, except my application won’t start on the Pi2, as it fails with:

no such container -linux runtime spec devices: error gathering device information while adding custom device “/dev/ttyS0”: lstat /dev/ttyS0: no such file or directory '

28.06.18 14:34:01 (+1200) Installed service 'dashboard sha256:6036aa8d1fee8a0b0a90dc05157f2707a2a4e5f1361ee51f2c97d367feef21ae'
28.06.18 14:34:01 (+1200) Starting service 'dashboard sha256:6036aa8d1fee8a0b0a90dc05157f2707a2a4e5f1361ee51f2c97d367feef21ae'
28.06.18 14:34:04 (+1200) Failed to start service 'dashboard sha256:6036aa8d1fee8a0b0a90dc05157f2707a2a4e5f1361ee51f2c97d367feef21ae' due to '(HTTP code 404) no such container -linux runtime spec devices: error gathering device information while adding custom device "/dev/ttyS0": lstat /dev/ttyS0: no such file or directory '

If I remove the ttyS0 devices line in the docker-compose file, the RPi2 works, but the RPi3 doesn’t anymore, as it’s not mapped to the docker container.

Is there a way to make the docker-compose devices mapping conditional or overridden for a given Resinio application, or perhaps use two different docker-compose files? Or is there a way to map docker devices within the Resin.io user interface?

Hi,

The raspbian foundation introduced a serial port aliases a while ago. Raspberry Pi 3 serial0 will point to GPIO pins 14 and 15 and use the “mini-uart” aka /dev/ttyS0. On other Raspberry Pi’s it will point to the hardware UART and /dev/ttyAMA0, so where possible refer to the serial port via it’s alias of “serial0” and your code should work on both Raspberry Pi 3 and other Raspberry Pi’s.

You can use this feature on a resin device with resinOS 2.0.2 or higher.

1 Like