Page 1 of 1

gpio fails as of kernel 6.6 on rpi

Posted: Sunday 17 March 2024 20:48
by akamming
Just did an sudo apt update && sudo apt upgrade -y on my pi, which did quite an update on the pi os.

One of the changes was upgrade to kernel 6.6, and now i found out gpio does not work anymore.

On my watermeter plugin i now get the following error:

2024-03-17 20:40:37.307 Error: Watermeter: RuntimeError: Failed to add edge detection

This error is on this line:
GPIO.add_event_detect(gpio_pin, GPIO.BOTH, callback = Interrupt, bouncetime = bouncetime)

(GPIO refers to rpi.GPIO)

anyone have an idea how to fix?

EDIT: Did some research myself. Turns out a lot is changed for GPIO as of kernel 6.6 (which is now the new standard kernel for raspberry pi os), so logged an issue: https://github.com/domoticz/domoticz/issues/6040

Re: gpio fails as of kernel 6.6 on rpi

Posted: Friday 22 March 2024 13:57
by akamming
hmmm... this is the so maniest issue where i did not get support on the forum. No pun intended for everyone who works very hard to keep this community alive. But it is a bit worrying that support is dropping for domoticz..

anyway... until the issue is solved in the code i created a workaround to be able to still control the switches. posting it here, in case someone has the same issue.

so basically what is happening that the number of the gpio is changed as of kernel 6.6 and domoticz cannot handle this. (should be fixed in the code).

the new numbers can be found if you do a "cat /sys/kernel/debug/gpio". You will get output like this:

Code: Select all

 gpio-512 (ID_SDA              )
 gpio-513 (ID_SCL              )
 gpio-514 (GPIO2               )
 gpio-515 (GPIO3               )
 gpio-516 (GPIO4               )
 gpio-517 (GPIO5               )
 gpio-518 (GPIO6               )
 gpio-519 (GPIO7               )
 gpio-520 (GPIO8               )
 gpio-521 (GPIO9               )
 gpio-522 (GPIO10              )
 gpio-523 (GPIO11              )
 gpio-524 (GPIO12              )
 gpio-525 (GPIO13              )
 gpio-526 (GPIO14              |sysfs               ) out hi ACTIVE LOW
 gpio-527 (GPIO15              |sysfs               ) in  hi
 gpio-528 (GPIO16              )
 gpio-529 (GPIO17              )
 gpio-530 (GPIO18              |lg                  ) in  hi IRQ
 gpio-531 (GPIO19              )
 gpio-532 (GPIO20              )
 gpio-533 (GPIO21              )
 gpio-534 (GPIO22              )
 gpio-535 (GPIO23              )
 gpio-536 (GPIO24              )
 gpio-537 (GPIO25              )
 gpio-538 (GPIO26              )
 
in list you can find the new number for the pin (in my case 526 for gpio-14 which controls my "buitenlamp")

you can then still activate the gpio using the sysfs interface, in my case for gpio14:

Code: Select all

echo 526 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio526/direction
echo 1 > /sys/class/gpio/gpio526/active_low
after this you can create a dummy switch and a helper script to control the gpio:

Code: Select all

-- helper script for gpio

return {
	on = {
		devices = {
			'Buitenlamp Carport'  -- the name of the dummy switch
		}
	},
	logging = {
		level = domoticz.LOG_DEBUG,
		marker = 'GPIO helper',
	},
	execute = function(domoticz, device)
		domoticz.log('Device ' .. device.name .. ' was changed to ' .. device.state, domoticz.LOG_DEBUG)
		if (device.active) then
		    domoticz.log("Switching on",domoticz.LOG_DEBUG)
		    domoticz.executeShellCommand("echo 1 > /sys/class/gpio/gpio526/value")   -- set to correct gpio
		else 
		    domoticz.log("Switching off",domoticz.LOG_DEBUG)
		    domoticz.executeShellCommand("echo 0 > /sys/class/gpio/gpio526/value")  -- set to correct gpio
		end
	end
}

Re: gpio fails as of kernel 6.6 on rpi

Posted: Friday 22 March 2024 14:12
by willemd
akamming wrote: Friday 22 March 2024 13:57 hmmm... this is the so maniest issue where i did not get support on the forum. No pun intended for everyone who works very hard to keep this community alive. But it is a bit worrying that support is dropping for domoticz..
Keep in mind that not many users will have had this issue, so supporting experience from others was probably not existing. Maybe only the one's that installed domoticz on a RPi 5. I remember a thread about it. As a frontrunner, indeed your own research, or a post on a Raspberry Pi forum, is the way forward then.

Re: gpio fails as of kernel 6.6 on rpi

Posted: Friday 22 March 2024 14:45
by waltervl
And also in the github issue I mentioned an existing github issue that tried to solve your issue...
What more can we do?

Re: gpio fails as of kernel 6.6 on rpi

Posted: Friday 22 March 2024 20:37
by akamming
I regret a bit I made this remark caissière apparently it demotivates the people who still support this community

It’s just a bit that i see a trend. In the past any issue I posted on this forum I got much more feedback. So i am a bit worried that the Community for this very nice product is becoming smaller and smaller

Anyway really appreciate the work a lot of people like you are doing Here. So I won’t make similar remarks again

Re: gpio fails as of kernel 6.6 on rpi

Posted: Monday 02 December 2024 15:10
by mmolema
How do you make this dummy button?
I created a dummy in hardware and when I try to manually create a switch and select this dummy as hardware and Sysfs GPIO as type gpio516-input appears in the Sysfs GPIO field, but when I try to add the device I get the message: "undefined"
Image

Re: gpio fails as of kernel 6.6 on rpi

Posted: Monday 02 December 2024 15:58
by waltervl
You should not make a dummy device.
See the instructions on the wiki: https://wiki.domoticz.com/GPIO

Re: gpio fails as of kernel 6.6 on rpi

Posted: Monday 02 December 2024 16:06
by mmolema
The method as described in the wiki doesn't work anymore that is what this topic is all about.
as akamming writes above you should make a dummy switch and create some scripting

Re: gpio fails as of kernel 6.6 on rpi

Posted: Monday 02 December 2024 16:26
by waltervl
The issue as logged in https://github.com/domoticz/domoticz/issues/6040 is solved in latest stable 2024.7

So it should work again as akamming tested it in a beta release. No need to do a workaround. But best is that @akamming will reply here indeed.

Re: gpio fails as of kernel 6.6 on rpi

Posted: Monday 02 December 2024 16:30
by akamming
waltervl wrote: Monday 02 December 2024 16:26 The issue as logged in https://github.com/domoticz/domoticz/issues/6040 is solved in latest stable 2024.7

So it should work again as akamming tested it in a beta release. No need to do a workaround. But best is that @akamming will reply here indeed.
it's indeed fixed in the domoticz code.. so the above mentioned workaround is no longer neccessary...

Re: gpio fails as of kernel 6.6 on rpi

Posted: Monday 02 December 2024 19:29
by mmolema
Ok, then it might just be me.
I tired to run the sysfs commands in the terminal and that only worked if I added 512 to the required number. and if I did so finally something appeared in domoticz (see screenshot above)
But now I installed an older version of pi os with kernel 6.1 to be sure. and now things like sudo sh -c 'echo 4 > /sys/class/gpio/export' don't give errors in the terminal.
I modified /etc/rc.local to look like:
Image
after reboot I still don't have a gpio pin available in domoticz "No sysfs-gpio exports"

a little background:
I was running a pi1B for 10 years, 2 weeks ago I tried an update because a couldn't connect to it anymore with the domoticz app.
since the it's dark arround the house, after a lot of struggling I found out that the Pi1 is no longer supported so I upgraded to a pi3B
but somehow I cant get the GPIO running again.

Re: gpio fails as of kernel 6.6 on rpi

Posted: Thursday 05 December 2024 16:17
by mmolema
If anyone can help me on this that wile be much appreciated:

1) I create a new install of PI OS
2) I install domoticz using ' sudo bash -c "$(curl -sSfL https://install.domoticz.com)" '
4 ) I add folowing lines to the end of /etc/init.d/domoticz.sh :
echo 538 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio538/direction
5) Using the console I can switch a LED that I wired to pin 26 with:
echo 1 > /sys/class/gpio/gpio538/value
echo 0 > /sys/class/gpio/gpio538/value
6) I open domoticz in the browser and create Genric sysfs GPIO Hardware
7) I try to manually add a switch of type Sysfs GPIO and behind Sysfs GPIO: I read 'No sysfs-gpio exports'

What am I doing wrong?

Re: gpio fails as of kernel 6.6 on rpi

Posted: Tuesday 17 December 2024 20:41
by theo11
Hi,

I was using GPIO, doorbell application, on Buster and that was working fine with Generic sysfs GPIO in domoticz on PI 3B+.

I completely re-installed with Bookworm and using docker and I had the same problem, I cannot get it to work again.
I am running Bookworm Linux rpi2-3b 6.6.51+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.6.51-1+rpt3 (2024-10-08) aarch64 GNU/Linux.

Sysfs is already for a longer time deprecated and the new interface is https://github.com/brgl/libgpiod.
The libgpiod is already pre-installed in Bookworm.

I have created a dummy doorbell device in Domoticz and created the following script:
#!/bin/bash
#
# Monitor GPIO doorbell application
#
CHIP_NAME=gpiochip0
GPIO=4

ACTIVE_STATE=--active-low
NUM_EVENTS="--num-events=20"
EDGE_EVENT=-f

RPI="192.168.111.102:8080/"
SWITCH_CMD="json.htm?type=command&param=switchlight&"
# Dummy doorbell device Domoticz
IDX=96

while :
do
# gpiomon -l -n 1 -f gpiochip0 $GPIO
EVENT=`/usr/bin/gpiomon $ACTIVE_STATE $NUM_EVENTS $EDGE_EVENT $CHIP_NAME $GPIO`
# echo $EVENT
hostcmd="http://${RPI}${SWITCH_CMD}idx=${IDX}&switchcmd=On"
# echo $hostcmd
curlres=`/usr/bin/curl -sS $hostcmd`
done

This mon_doorbell.sh script runs as daemon.
Created the following file etc/systemd/system/mon_doorbell.service:
Unit]
Description=Monitor doorbell

[Service]
ExecStart=/opt/domoticz/store/scripts/scripts/mon_doorbell.sh
Restart=on-failure

[Install]
WantedBy=multi-user.target


Then run the following commands to enable and start the daemon.
sudo systemctl daemon reload
sudo systemctl enable mon_doorbell.service
sudo systemctl start mon_doorbell.service

The dummy doorbell device sends a telegram notification to my cellphone.

Works perfectly.