New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Recent kernels no longer support sysfs interface for GPIO (raspberry pi) #250
Comments
I did not intend to close this issue when working on it in my fork... sorry. |
I worked on this over in my fork (please see the PR in my fork that accidentally closed this issue). I'd have offered it as a PR here, but:
I did, however, determine the code went from not-working to working by actually watering my lawn. |
Your code tweaks worked for me. However libgpiod in ArchLinuxARM is now at version 2.0.1 which completely breaks the older API. Downgrading to libgpiod 1.6.4 allowed your code to compile. Just lovely how GPIO handling in the kernel and libraries seem to change every few months. Figured by now those APIs would be fairly stable, but change for change sake I guess. Thanks again! |
Thanks for the heads-up! Looking at distros, it seems Ubuntu (the base image I used for the docker image), Alpine (what I probably should have used), and even openSUSE Tumbleweed (what my k8s cluster running opensprinkler for me uses natively) are all still at 1.6.x. I confirm, though, that Arch Linux is at 2.0.1. It looks like I should bring my fork up-to-date with this repo anyway, and I should see if I can support both old and new Separately: you could try running opensprinkler as a container using docker or containerd ( |
i got it working on bookworm by running the following commands wget https://raw.githubusercontent.com/jbalonso/opensprinkler-firmware/main/gpio.cpp \
-O gpiod.cpp # pulls @jbalonso's edited gpio.cpp renaming it gpiod.cpp
cp build.sh build_bw.sh # perserve executable
sed -i '26s/-dev/-dev libgpiod-dev/' build_bw.sh # avoid a second query by appending
sed -i '/raspi-gpio/,+5d' build_bw.sh # delete raspi-gpio and its command check
sed -i '/-DOSPI/s/gpio/gpiod/' build_bw.sh # in the `-DOSPI` line, change gpio to gpiod
sed -i '/-DOSPI/s/$/ -lgpiod/' build_bw.sh # append ` -lgpiod`
sudo ./build_bw.sh ospi # and finally run the build script diff between build.sh and build_bw.sh for visibility 26,32c26
< apt-get install -y libmosquitto-dev
< apt-get install -y raspi-gpio
< if ! command -v raspi-gpio &> /dev/null
< then
< echo "Command raspi-gpio is required and is not installed"
< exit 0
< fi
---
> apt-get install -y libmosquitto-dev libgpiod-dev
34c28
< g++ -o OpenSprinkler -DOSPI -std=c++14 main.cpp OpenSprinkler.cpp program.cpp opensprinkler_server.cpp utils.cpp weather.cpp gpio.cpp etherport.cpp mqtt.cpp -lpthread -lmosquitto
---
> g++ -o OpenSprinkler -DOSPI -std=c++14 main.cpp OpenSprinkler.cpp program.cpp opensprinkler_server.cpp utils.cpp weather.cpp gpiod.cpp etherport.cpp mqtt.cpp -lpthread -lmosquitto -lgpiod |
@wommy followed your instructions, still not working, any tips, or things to check? |
I suspect we'll all be happier if we added a github action to my repo to build the binary as well as the docker image. I wonder if we can assure that the |
Sorry about the delay. I will take a look at this soon. We are still in the middle of the semester and I don't have time to check all the details. The semester will be over in a few weeks by which time I will have more time. To be honest I don't understand why every couple of years Raspberry Pi decides to change the way gpios are operated. Instead of providing a backward compatible method, they just get rid of the old method. It's like not understanding what software abstraction means -- it should provide a high level interface that remain unchanged over decades. |
That would be great indeed... but I still wonder whats not working, since I can't see any logs or anything. Any idea?
@rayshobby thanks for the prompt reply. The real problem here is that the irrigation is not working for a week (since I upgraded raspibian) and i did not even know, until I noticed the plants getting sick... |
not at all, unless youre fluent in docker.
did you run those commands on the repo after a pull? your else block should look like this else
echo "Installing required libraries..."
apt-get update
apt-get install -y libmosquitto-dev libgpiod-dev
echo "Compiling firmware..."
g++ -o OpenSprinkler -DOSPI -std=c++14 main.cpp OpenSprinkler.cpp program.cpp opensprinkler_server.cpp utils.cpp weather.cpp gpiod.cpp etherport.cpp mqtt.cpp -lpthread -lmosquitto -lgpiod
fi |
tomorrow, im going to reinstall raspian bookworm to test this, as i might be missing a dependency |
Thanks @wommy. I ended up cloing your repo, fixing the missing libgpiod, std arguments, rebuilding and using the |
Why not downgrade Raspbian to Bullseye? Not sure if you noticed, but we've put a note on the instructions page: |
that notice was put up long after I upgraded |
Yeah, downgrading debian is, hmmm, not recommended anyway :) |
See https://forums.raspberrypi.com/viewtopic.php?t=343514.
On my recent system, running
Linux sprinkler 6.3.9-1-default #1 SMP PREEMPT_DYNAMIC Thu Jun 22 03:53:43 UTC 2023 (0df701d) aarch64 aarch64 aarch64 GNU/Linux
, the sysfs interface no longer works. This breaksraspi-gpio
, and I think this critically impacts the workings of https://github.com/OpenSprinkler/OpenSprinkler-Firmware/blob/master/gpio.cpp, beyond even just thesystem()
call toraspi-gpio
.A potential remedy is written up here: https://www.ics.com/blog/gpio-programming-exploring-libgpiod-library. There exists packages for
gpiod
(CLI tools),libgpiod2
(runtime libraries), andlibgpiod-dev
(runtime libraries and development headers). I notice three choices:raspi-gpio
and the sysfs interface with the use oflibgpiod
.rapsi-gpio
and the sysfs interface withsystem()
calls togpioset
.raspi-gpio
and the sysfs interface vs.gpioset
.I might be able to do a little empirical testing to see if
raspi-gpio
andgpioset
both work on older kernels.The text was updated successfully, but these errors were encountered: