Using pi4j and WiringPi with balenaOS app

Am trying to deploy a Java application that uses pi4j which has dependency on the native library http://wiringpi.com/download-and-install/. When I try to run a program simple LED blinker it fails with message

wiringPiSetup: Unable to open /dev/mem or /dev/gpiomem: No such file or directory.
  Aborting your program because if it can not access the GPIO
  hardware then it most certianly won't work
  Try running with sudo?

Any clue how to get this working with BalenaOS ?

Thanks.

Kamesh

I got over this by added ENV UDEV=1 and running the service with previleged:true

Hi there @kameshs,

If you’re using a single container application, then by default, containers are privileged. However, it sounds like you’re using a multicontainer application. You don’t have to run this privileged however, for most hardware. There’s a guide on how to do this here.

Hope this helps!

@hedss - thanks for the link . excuse me for my ignorance in this IoT side of world… just getting myself into it :slight_smile:

no I don’t run multi container app, its single container only. So if I understand you correctly settings as show in the reference links is good for Single container as well and I can remove privileged settings?

Hi @kameshs,

Asking questions is great, it’s how we all learn! :smiley:

If you’re not using a multicontainer app with a docker-compose.yml file, then you should be able to access the /dev/mem and /dev/gpiomem from your single container without the need for privileged mode, that’s correct (and the balena Dashboard for your device should show a single service, named main, running).

If you are using a docker-compose.yml file, then you’ll either need to make the service privileged (as you mention above), or you’ll need to use the devices and cap_add sections of the docker-compose.yml as mentioned in the guide!

Best regards, Heds

Thats awesome, thanks @hedss