libpi4j.so error with raspberrypi4-64-ubuntu Image

Hi Team,

Just few days before I started looking on the balena and I am very much like this concept.

I installed the open balena in my server(vps) and installed a Java application on my raspberry-4. I could successfully deploy application in my RPi. When the application started I am blinking an LED bulb which is attached to the Pi. So I used Pi4J lib for controlling the GPIO ports. This is worked in Raspbian OS before. But when I deployed in balena I am getting the exception like “java.lang.UnsatisfiedLinkError: ‘int com.pi4j.wiringpi.Gpio.wiringPiSetup()’” because another exception throwing before this which is “ERROR com.pi4j.util.NativeLibraryLoader - Unable to load [libpi4j.so] using path: [/lib/raspberrypi/dynamic/libpi4j.so]”

I think this is because of the missing of “wiringpi”. I installed it in the image,but still getting the same exception. I pasted the content of Dockerfile below. Please verify I am not sure I followed the correct steps.

For Raspbian the wiringpi is already installed. In this case I used the base image “balenalib/raspberrypi4-64-ubuntu-openjdk:11”.

My question is, Can I use any image with raspbian os which works in the Balena Engine?

If it is NOT, any solution for this issue?

Dockerfile

FROM maven:3.5-jdk-8-alpine AS build
RUN apk update
RUN apk add --no-cache git
ADD settings.xml /root/.m2/settings.xml
COPY . /build
RUN mvn -f /build/pom.xml clean package -DskipTests

FROM balenalib/raspberrypi4-64-ubuntu-openjdk:11
RUN apt-get update && apt-get install -y git && apt-get install -y build-essential
RUN git clone https://github.com/WiringPi/WiringPi.git wiringpi && cd wiringpi && git checkout tags/final_official_2.50 && ./build
RUN cd …
RUN apt-get install -y maven
RUN git clone https://github.com/Pi4J/pi4j-v2.git pi4j && cd pi4j && mvn clean install

#RUN gpio -v
WORKDIR my-device
COPY --from=build /build/target/my-device-1.0.jar my-device.jar
EXPOSE 8080
ENTRYPOINT [“java”, “-jar”, “my-device.jar”]

Thanks & Regards
Anoop John

Hi there,

I think the first place to start is to dive into the Balena base images documentation here: https://www.balena.io/docs/reference/base-images/base-images

Looking at your dockerfile I would advice for installing packages you should use RUN install_packages if possible. docs here The install_packages command does some nice things regarding retry logic.

Also it looks like the second FROM line should be: FROM balenalib/raspberrypi4-64-ubuntu-openjdk:11-jdk or FROM balenalib/raspberrypi4-64-ubuntu-openjdk:11-jre

Let me know if changing those things help you further

Not sure about raspi4

I was working on raspi 3b+ my os crashed and I installed a new one
This is when I faced the error while executing the code
After researching a lot…I saw pi4j website
Execute these lines in terminal window

Now everything works perfectly for me

I Think this error is because of wiringpi is not recognized in new os(2021) version

sudo apt-get remove wiringpi -y
sudo apt-get --yes install git-core gcc make
cd ~
git clone GitHub - WiringPi/WiringPi: Gordon's Arduino wiring-like WiringPi Library for the Raspberry Pi (Unofficial Mirror for WiringPi bindings) --branch master --single-branch wiringpi
cd ~/wiringpi
sudo ./build

Hi @shamika17

Thanks for the solution! Just wondering - was this on balenaOS or Raspbian?