Migration problems pi4j v1.4 to 2.1.1 #203
Replies: 9 comments 5 replies
-
As this is simply teasing me I'm still investigating. I tried ~/pigpio-master/EXAMPLES/Python/GPIO_STATUS/gpio_status.py which complained that the deamon wasn't running. I'm not sure if the pi4jv2 requires that the deamon is running so I did a
My EventListener is still not triggered, but I observed that gpio_status.py displays different values on pin 27 when I snap with my fingers near the sensor:
0=1 INPUT: 0 11=0 INPUT: 0 22=0 INPUT: 0 and another try: 0=1 INPUT: 0 11=0 INPUT: 0 22=0 INPUT: 0 I thought that I would only get 0/1 here but it seems that I get the loudness? |
Beta Was this translation helpful? Give feedback.
-
I also found out that I missed some preconditions: pi4j was not available on the pi (though I think it's not necessary since it should be available within java through the maven dependencies) While https://pi4j.com/getting-started/set-up-a-new-raspberry-pi/ is missing the point of installing PI4J so the pi shows
However the java app, i.e. my Listener is not impressed by the change. Which part went wrong? |
Beta Was this translation helpful? Give feedback.
-
You're correct, installing Pi4J is not needed as PiGpio is compiled into the library, also the daemon is not used. Can you add similar PrintInfo code from https://github.com/Pi4J/pi4j-example-minimal/blob/main/src/main/java/com/pi4j/example/MinimalExample.java#L101 to validate that everything is loaded correctly? Ah, and do you start your application with |
Beta Was this translation helpful? Give feedback.
-
Just a hint when starting java with systemd: create a bash script to start the application you can execute successfully yourself, and use that in systemd file, eg |
Beta Was this translation helpful? Give feedback.
-
OK two things I discovered in the meantime after checking your hints, especially: I obviously missed the shading part, which I added. The other difference I observed is, that I'm using springs plugin to build the self executable, instead of the maven jar plugin:
After adding the Shade Plugin and also integrating the PrintInfo I got the following on console:
Unfortunatley my Listener is still not triggered (I added log output as first statement there, also no breakpoint holds there). |
Beta Was this translation helpful? Give feedback.
-
From what I see here the output looks OK... Can you also output the registry? |
Beta Was this translation helpful? Give feedback.
-
I added the registry call, I looks like this now:
Looks like there is someting missing?
Project compiles now with java17 also. I had some troubles with the switch first, as the fat jar could not find java first after switching to sdkman. But setting the java_home also in the service.conf solved the problem with location java at service start. |
Beta Was this translation helpful? Give feedback.
-
Since I'm tapping in the dark, I tried the one thing or the other, I used a static class to to the initialization, in your vaadin example you use a service. As far as I know a spring service could create some instances - that was why I used the static approach first, I will switch to an ApplicationScope Bean afterwards. However I refactored me setup and now I saw
in my app logs. Which I haven't seen before. As I assume that my systemd setup may cause problems, I will first see that it's working by invoking by using sudo. Doing this the PrintInfo suddenly shows something in the registry (and the exception above vanishes):
I was almost ready to jump up from the couch and doing the hamster-dance, however my listener is still not being triggerd. My Listener is Autowired, but this seem not to work in my setup:
Strange, but this is solvable... |
Beta Was this translation helpful? Give feedback.
-
just noticed this line the value and timeunit must match, so I guess you would need TimeUnit.SECONDS based on the name of your debounce value. this is the Pi4J code you are calling from this
|
Beta Was this translation helpful? Give feedback.
-
Hi there,
I'm trying to upgrade my noice threshold sensor (as KY-038 module from AZDelivery used with a raspi 3 model b, rev1.2).
My setup (java based) works well with p4j v1 (using wiring pi pin 2).
Now I'm trying the v2 setup, where wiring 2 is mapped on GPIO/BCM 27
It all starts up well but my event listener does not fire at all.
On the pi I checked also via python with this:
This works. As soon as I clap in my hand I got the "1" and the loop stops. Why does the new java api is not working?
used dependencies from pom.xml
And heres how I setup the PIN and listener (SENSOR_BCM_PIN = 27) :
pigpiod -v
79
Thanks for any help.
Stefan
Beta Was this translation helpful? Give feedback.
All reactions