Closed mrumpf closed 5 years ago
Looking at the source code shows that the class GPIODataHolder has a static initializer: https://github.com/openhab/openhab2-addons/blob/master/addons/binding/org.openhab.binding.mcp23017/src/main/java/org/openhab/binding/mcp23017/internal/GPIODataHolder.java When the statement in this initializer fails, the NoClassDefFountError is thrown. An improvement could be to wrap the call to the Pi4j library with a try-catch block and log the error.
When I run the example: https://github.com/Pi4J/pi4j/blob/master/pi4j-example/src/main/java/NonPrivilegedGpioExample.java on my Raspberry Pi 3 B+
It dumps the following message on the console:
root@raspberrypi:~/pi4j# java -cp pi4j-1.1/lib/pi4j-core.jar:. NonPrivilegedGpioExample
<--Pi4J--> Non-Privileged GPIO Example ... started.
Unable to determine hardware version. I see: Hardware : BCM2835
,
- expecting BCM2708 or BCM2709.
If this is a genuine Raspberry Pi then please report this
to projects@drogon.net. If this is not a Raspberry Pi then you
are on your own as wiringPi is designed to support the
Raspberry Pi ONLY.
The Pi4j library issue discusses the topic here: https://github.com/Pi4J/pi4j/issues/319
After updating the library to version 1.2-SNAPSHOT this error went away, but revealed that WiringPi was missing on my RaspberryPi.
<--Pi4J--> Non-Privileged GPIO Example ... started.
Feb 05, 2019 11:44:31 AM com.pi4j.util.NativeLibraryLoader load
SEVERE: Unable to load [libpi4j.so] using path: [/lib/raspberrypi/dynamic/libpi4j.so]
java.lang.UnsatisfiedLinkError: /tmp/libpi4j3979346242306016496.so: libwiringPi.so: cannot open shared object file: No such file or directory
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1824)
at java.lang.Runtime.load0(Runtime.java:809)
at java.lang.System.load(System.java:1086)
at com.pi4j.util.NativeLibraryLoader.loadLibraryFromClasspath(NativeLibraryLoader.java:159)
at com.pi4j.util.NativeLibraryLoader.load(NativeLibraryLoader.java:105)
at com.pi4j.wiringpi.GpioUtil.<clinit>(GpioUtil.java:64)
at NonPrivilegedGpioExample.main(NonPrivilegedGpioExample.java:50)
Exception in thread "main" java.lang.UnsatisfiedLinkError: com.pi4j.wiringpi.GpioUtil.isPrivilegedAccessRequired()Z
at com.pi4j.wiringpi.GpioUtil.isPrivilegedAccessRequired(Native Method)
at NonPrivilegedGpioExample.main(NonPrivilegedGpioExample.java:50)
After installing it apt-get install wiringpi
the example started successfully.
I updated the MCP23017 Wiki page with a "Dependencies" section to make it clear that the library is required: #4806
Since June 2018 people ask the maintainer for a 1.2 release of the library: https://github.com/Pi4J/pi4j/issues/418 Unfortunately he seems to be unresponsive. I suggest to simply commit the 1.2-SNAPSHOT libraries to the lib folder of the mcp23017 binding.
Pi4J version 1.2 has been released: PR #5014.
Expected Behavior
No exception should occur, or at least a better error message to be able to resolve the issue.
Current Behavior
Possible Solution
Steps to Reproduce (for Bugs)
Context
Your Environment
OpenHAB 2.4 with MCP23017 binding on Raspbian (Debian 9.6)
Thing definition
Item definition