-
Notifications
You must be signed in to change notification settings - Fork 338
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
[Snap] Give add-ons access to serial ports #3152
Comments
The same will likely be true for the Z-Wave add-on too, since that also uses a serial connection. In order to access serial ports, a snap needs access to the serial-port interface. We can request this interface in snapcraft.yaml, but it is usually not connected by default so would require a user to manually connect the interface on the command line. We can request an exception in the snap store but it may not be granted. As I understand it on Ubuntu Core it also requires serial device paths to be hard coded in a gadget snap, unless using the experimental hotplug support, which is still marked as experimental and therefore can not be enabled by default. This may be a problem because the gateway supports multiple USB dongles. As I understand it the existing Raspbian image supports hotplug USB devices. |
as long as the zigbee devices are USB dongles (vs. actual sub-d attached serial devices) it should be possible to simply turn on hotplug support of the UbuntuCore image via a gadget.yaml setting (or simply tell the user to turn it on manually when used out of a pre-made image) ... could you try turning on hotplug on your test device and see if the dongle can be found or if we need to dig deeper here ... (perhaps hardware-observe or system-observe interfaces might be needed alongside and probably udevadm as a bundled binary, we'd need more logs here but i think this could be a viable way forward.) |
@ogra1 Thank you for the advice. I enabled hotplug with a Digi XStick (Zigbee dongle) and Aeotec Z-Stick (Z-Wave dongle) plugged in and saw the following:
So that's a good start. Oddly, when I disconnected the Aeotec Z-Wave dongle and plugged a Z-Wave dongle from Sigma Designs in its place, it was detected as aeotecz-stickgen5zw0 - so that's not ideal... But the obvious question is if a Looking at the source code of the Zigbee adapter add-on as a starting point, it appears to use the serialport npm package (and home-grown serial-prober package which builds on serialport to probe a serial port for certain vendor and product IDs). I have no idea what magic serialport uses on the back end, but it seems to support a lot of different architectures. Presumably to get USB dongles to connect dynamically at runtime on Ubuntu Core we would need some additional logic which automatically connects the serial-port plug to sockets as they appear. Is that even possible? FYI I'm already adding a |
udevadm could monitor the plug events so your app can be notified about a dongle being added/removed and act accordingly, hardware-observe was simply a guess like system-observe ... For the monitoring you could then have a scripted daemon that operates around something like:
|
@ogra1 Thank you for this suggestion. The following is the output of udevadm when I plugged in an XStick Zigbee dongle:
I'm not completely clear on how you're suggesting I would get from this output to the gateway application being able to access the USB device. As I understand it the hotplug support dynamically creates "slots" for the serial-port interface, but how would I get the gateway application to then automatically connect its serial-port plug to that slot when it appears? Does the user not need to manually run Currently the WebThings Zigbee adapter add-on uses this home-grown serial-prober package (which uses the serialport npm package) to detect and connect to serial ports. It looks for devices with a path like I'm not sure whether once the serial-port interface is connected this existing code might "Just Work"? I'm thinking maybe not if the interface only gives you access to a specific serial port, it may not let you list them? I also note that the DEVNAME output by udevadm is of the form /dev/bus/usb/001/004, which I understand describes the full physical USB topology with metadata about each device, rather than just looking like a plain serial port. I'm not sure how the gateway application would get from this to a useable serial port? |
@ogra1 @dilyn-corner @lorenzo-medici Am I right in thinking that programmatically connecting a plug to a slot would require the snapd-control interface, which is considered super privileged and would therefore require a store assertion to even add a plug to the gateway snap in the public Snap Store, let alone have it autoconnect? I've noticed that in the documentation for the serial-port interface it appears that it's possible to specify a serial-port plug which autoconnects to a specific device path or a triplet of If I've understood correctly then this would require hard coding the the vendor and product IDs of every possible hardware dongle we might ever want to connect to in a long list of plugs in snapcraft.yaml, which doesn't scale at all but might be a way for us to get started. When a triplet of What happens if multiple dongles with the same |
You are correct, and additionally it is quite a challenge to get a snap with snapd-control in the Global Store, let alone autoconnecting. Regarding specifically serial-port things, snapd has been hard at work adding support for hotplugging. The serial-port interface is currently the only interface which supports this (experimental) feature, but I've been using it on my own system for quite some time and it has proven quite useful. You can try it with |
@dilyn-corner Thank you for your reply, but @ogra1 already linked to the hotplug documentation. Please see my questions above. In summary: I understand that the hotplug support automatically creates serial-port slots, but how do I get my snap to connect to them? |
May require the serial-port/raw-usb interface.
Currently the Zigbee add-on does not work...
STR:
Expected:
Actual:
Logs from /var/snap/webthings-gateway/current.webthings/log/run-app.log:
The text was updated successfully, but these errors were encountered: