I'm doing some experiments with openHAB2 on my Raspberry Pi 3 (with Raspbian installed).
At the moment I've connected a LED to GPIO pin #2 and I'm able to turn it on/off from openHAB2.
The problem is that when I shutdown my Raspberry, the LED linked to GPIO pin #2 remains active.
I've read this link from OpenHAB official documentation about GPIO binding and seems that I have to unexport GPIO pin editing the body of the do_stop() function on openHAB init.d script.
I've done two attempts:
1) I've edited the do_stop() function that way (copy-paste from openHAB documentation about GPIO):
do_stop()
{
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile
$PIDFILE $
#unexport all gpio's
echo 2 > /sys/class/gpio/unexport
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
# Wait for children to finish too if this is a daemon that forks
# and if the daemon is only ever run from this initscript.
# If the above conditions are not satisfied then add some other code
# that waits for the process to drop all resources that could be
# needed by services started subsequently. A last resort is to
# sleep for some time.
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec
$DAEMON
[ "$?" = 2 ] && return 2
# Many daemons don't delete their pidfiles when they exit.
rm -f $PIDFILE
return "$RETVAL"
}
2) I've edited the default init.d script adding only the line about unexporting GPIO pin #2:
do_stop() {
log_daemon_msg "Stopping $DESC" "$NAME"
echo "2" > /sys/class/gpio/unexport
if /usr/share/openhab2/runtime/bin/stop
then
# workaround stop returns before the openhab process has really stopped
timeout=0
if stpid=`cat /var/run/openhab2.pid 2> /dev/null`; then
killwaitpid $stpid
fi
rm -f $PIDFILE
# In case the pid in the pidfile was wrong, also kill/stop existing process
killwaitpid $EXISTINGPID
log_end_msg 0
return 0
else
log_end_msg 1
return 1
fi
}
Both solutions don't work and the LED turns ON after Raspberry was turned off, even if I turn my Raspberry off with the LED OFF; where is the mistake?