OH2 GPIO Binding broken and a possible workaround

I’m migrating to OpenHAB2, and I’d like to congratulate everyone who’s worked on it, its a great step up, especially with OpenHAB 2 bindings.
Unfortunately on my system at least the included V1.9 GPIO Binding doesn’t work reliably. After working initially, it went on to spit out an obscure error on booting about not being able to get a lock, so after wasting a few hours on it I’ve thrown it away and created a workaround. I only use GPIO for outgoing items so my needs are simple. I’ve installed wiringPi, and use the gpio tool that came with it, called from a rule to switch the GPIO Pins. I also use a shell script running from crontab to set them up as the pi boots.
WiringPi uses a different pin numbering scheme to the binding, but issuing gpio readall inside a command window displays a pinout diagram together with the current mode of each pin.

For anyone following on, from the linux script I send to each pin

gpio mode <wiringPi_Pin_Number> out
gpio mode <wiringPi_Pin_Number> 1

This is the same as activelow:yes with the normal binding.
Then from a rule I use

rule "operate gpio item"
when Item MyItem changed then
if (MyItem.state == ON)	{	executeCommandLine('"gpio" "write" "<wiringPi_Pin_Number>" "0"', 1000)	}	else	{	executeCommandLine('"gpio" "write" "<wiringPi_Pin_Number>" "1"', 1000)	}
end

There may well be much more elegant ways of doing this, but for me it works, and it will do until a better binding appears

Confirm - i already used wiringPi in other situation with success. I didn’t think about a so simple solution.
Works perfectly.

This way of work it’s also with gpio read - the code below works fine on my oh2:

    //GPIO READ
    val String results = executeCommandLine('"gpio" "read" "1"', 5000)
    //the following log is reported on /var/log/openhab2/openhab.log
    logInfo("gpio 1 state is:", results)
    //so for example if the previous command gave 0
    if results ==  "0" {
    //do something
    //code to do something
    }
1 Like