I’m have snap that communicate with a custom hid device. The app contained within the snap uses nodejs and the library I’m using is ‘node-hid’. Note that ‘node-hid’ uses the hidapi internally.
My app is running as a daemon and gives this error when I try to start it:
cannot initialize hidapi (hid_init failed)
I know that the nodejs app works on its own with no problems (as long as a specify sudo) but I cant seem to figure how to connect to hidraw plug.
I have also tried the raw-usb plug but that as not worked as well.
Running installing the snap in devmode works so that’s promising.
Here is a the yaml file:
grade: stable # must be 'stable' to release into candidate/stable channels
confinement: strict # use 'strict' once you have the right plugs and slots
apps:
hid-demo:
command: bin/hid-demo
plugs: [hidraw, network, raw-usb]
daemon: simple
restart-condition : always
parts:
hid-demo:
plugin: nodejs
stage-packages: [libusb-1.0-0]
override-pull: |
echo "Configure linux dependencies"
apt-get install build-essential git
apt-get install gcc-4.8 g++-4.8 && export CXX=g++-4.8
apt-get install libusb-1.0-0 libusb-1.0-0-dev
apt-get install -y pkg-config
snapcraftctl pull
source: .
instead of all the apt hackery in override-pull you should use the build-packages directive and simply list all the packages required to be pulled … along with this to get the HID api into your snap you should list libhidapi-hidraw0 and probably also libhidapi-libusb0 in stage-packages
The classic images (server/desktop) do not come with a gadget snap which could provide this interface … you’d need to build your own classic server image with a gadget (or simply use Ubuntu Core)