- Platform information:
- Hardware: Orange PI Zero 512MB
- OS: Armbian 5.90 Orangepizero Debian buster next 4.19.57
- Docker version: 18.09.7
- Docker image: openhab/openhab:2.4.0-armhf-debian
- openHAB version: 2.4.0
- Issue of the topic:
Can not access to GPIO from OpenHab running in docker container
- Configurations:
gpio.items
Switch LED { gpio="pin:10 force:yes" }
Contact sensor "sensor [%s]" { gpio="pin:12 force:yes debounce:10 activelow:yes" }
gpio.sitemap
sitemap gpio label="GPIO"
{
Frame label=""
{
Switch item=LED
Text item=sensor
}
}
- Services configuration gpio.cfg
sysfs=/sys
debounce=10
- logs:
/opt/openhab/userdata/logs/openhab.log
2019-07-09 20:35:05.647 [INFO ] [panel.internal.HABPanelDashboardTile] - Started HABPanel at /habpanel
2019-07-09 20:35:23.259 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘home.items’
2019-07-09 20:35:32.426 [INFO ] [thome.model.lsp.internal.ModelServer] - Started Language Server Protocol (LSP) service on port 5007
2019-07-09 20:35:33.548 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘home.sitemap’
2019-07-09 20:35:36.318 [INFO ] [.dashboard.internal.DashboardService] - Started Dashboard at http://172.17.0.2:8080
2019-07-09 20:35:36.325 [INFO ] [.dashboard.internal.DashboardService] - Started Dashboard at https://172.17.0.2:8443
2019-07-09 20:35:39.545 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui
2019-07-09 20:35:39.833 [INFO ] [ui.habmin.internal.servlet.HABminApp] - Started HABmin servlet at /habmin
2019-07-09 20:35:40.236 [ERROR] [ab.binding.gpio.internal.GPIOBinding] - Error occurred while creating backend object for item DoorSensor, exception: /sys/class/gpio/unexport
2019-07-09 20:35:40.242 [ERROR] [ab.binding.gpio.internal.GPIOBinding] - Error occurred while creating backend object for item RaspiLED, exception: /sys/class/gpio/unexport
- Description:
# useradd -r -s /sbin/nologin openhab # mkdir /opt/openhab # mkdir /opt/openhab/conf # mkdir /opt/openhab/userdata # mkdir /opt/openhab/addons # chown -R openhab:openhab /opt/openhab
groupadd gpio && usermod -aG gpio openhab
cat > /etc/udev/rules.d/99-gpio.rules << “EOF”
SUBSYSTEM==“gpio”, ACTION==“add”, RUN=“/bin/sh -c ’
chown -R root:gpio /sys/class/gpio && chmod -R 770 /sys/class/gpio;
chown -R root:gpio /sys$DEVPATH && chmod -R 770 /sys$DEVPATH
'”
EOF
Installed docker to use: armbian-config
docker run
–name openhab
–net=host
-v /etc/localtime:/etc/localtime:ro
-v /etc/timezone:/etc/timezone:ro
-v /opt/openhab/conf:/openhab/conf
-v /opt/openhab/userdata:/openhab/userdata
-v /opt/openhab/addons:/openhab/addons
-v /sys:/sys
-d
-e USER_ID=uid
-e GROUP_ID=gid
–restart=always
openhab/openhab:version-architecture-distribution
-v /sys:/sys - for access to gpio
symbol # - means that the command runs from the user root.
version - 2.4.0
architecture - armhf
distribution - debian
to get architecture execute:
# uname --m
my: armv7l
Architectures:
amd64 for most desktop computers (e.g. x64, x86-64, x86_64)
armhf for ARMv7 devices 32 Bit (e.g. most RaspberryPi 1/2/3)
arm64 for ARMv8 devices 64 Bit (not RaspberryPi 3)
uid and gid - execute:
id openhab
my:
docker run
docker run --name openhab
–net=host
-v /etc/localtime:/etc/localtime:ro
-v /etc/timezone:/etc/timezone:ro
-v /opt/openhab/conf:/openhab/conf
-v /opt/openhab/userdata:/openhab/userdata
-v /opt/openhab/addons:/openhab/addons
-v /sys:/sys
-e USER_ID=999
-e GROUP_ID=998
–restart=always
-d
openhab/openhab:2.4.0-armhf-debian
Afrer Installed openHab I installed GPIO Binding:
http://ip:8080/paperui/index.html#/extensions?tab=binding
GPIO Binding
binding-gpio1 - 1.13.0
gpio didn’t work from openHAB
I tried SSH into a Container:
docker exec -it openhab /bin/bash
out gpio
echo "7" > /sys/class/gpio/export echo "out" > /sys/class/gpio/gpio7/direction echo "1" > /sys/class/gpio/gpio7/value
in gpio
echo "6" > /sys/class/gpio/export echo "in" > /sys/class/gpio/gpio6/direction cat /sys/class/gpio/gpio6/value
has access to GPIO
I had stopped docker
docker stop openhab
and installed openHab to use armbian-config.
OpenHab installed and has access to GPIO.
I have deployed docker container with openhab into raspbery pi 3B
OpenHab from docker into raspbery pi 3B has access to GPIO.
First of all thank you so much for read this question.
How to get access from openHab running in Docker Armbian access to GPIO?
Thank you very much for your responce.
References