Closed gitmirko closed 1 year ago
Hi, you do have the problem with all gpios or only via dht22/Adafruit lib?
I've just tried adding an normal pin as output, but even with passing an additional device I get another kind of error:
[...]
digital_outputs:
- name: led
module: raspberrypi
pin: 18
on_payload: "ON"
off_payload: "OFF"
initial: low
[...]
pi@raspberrypi:~ $ docker run --name="mqtt-gpio" --privileged --device /dev/mem --device /dev/gpiomem --device /dev/i2c-1 -v /home/pi/docker/mqtt-gpio/config.yml:/config.yml -v /etc/localtime:/etc/localtime:ro flyte/mqtt-gpio:armv7l
2020-05-18 22:16:37,346 mqtt_gpio (INFO): Startup
2020-05-18 22:16:38,021 mqtt_gpio (DEBUG): Last will set on 'home/wohnzimmer/status' as 'dead'.
Collecting RPi.GPIO
Downloading RPi.GPIO-0.7.0.tar.gz (30 kB)
Building wheels for collected packages: RPi.GPIO
Building wheel for RPi.GPIO (setup.py): started
Building wheel for RPi.GPIO (setup.py): finished with status 'done'
Created wheel for RPi.GPIO: filename=RPi.GPIO-0.7.0-cp36-cp36m-linux_armv7l.whl size=61793 sha256=66134c6ff5dc2712bbc79535676f79730c3aa32feb47caf5ef6d5e9176f65b42
Stored in directory: /home/mqttgpio/.cache/pip/wheels/84/c0/d6/73a6e9f98b9d29edd7c6e981dce47852c3321f34518c80dce1
Successfully built RPi.GPIO
Installing collected packages: RPi.GPIO
Successfully installed RPi.GPIO-0.7.0
Collecting Adafruit_DHT
Downloading Adafruit_DHT-1.4.0.tar.gz (15 kB)
Building wheels for collected packages: Adafruit-DHT
Building wheel for Adafruit-DHT (setup.py): started
Building wheel for Adafruit-DHT (setup.py): finished with status 'done'
Created wheel for Adafruit-DHT: filename=Adafruit_DHT-1.4.0-cp36-cp36m-linux_armv7l.whl size=30317 sha256=5d34264809782db299aa4fe389928e961591baea99f64ccc20c976e68ef4090d
Stored in directory: /home/mqttgpio/.cache/pip/wheels/af/d8/00/6f0c819ab5f38ea5ececf1b698a9e53888e271300d5f202260
Successfully built Adafruit-DHT
Installing collected packages: Adafruit-DHT
Successfully installed Adafruit-DHT-1.4.0
Traceback (most recent call last):
File "/usr/local/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/local/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/mqttgpio/pi_mqtt_gpio/server.py", line 901, in <module>
main(args)
File "/home/mqttgpio/pi_mqtt_gpio/server.py", line 802, in main
initialise_digital_output(out_conf, GPIO_MODULES[out_conf["module"]])
File "/home/mqttgpio/pi_mqtt_gpio/server.py", line 540, in initialise_digital_output
gpio.setup_pin(out_conf["pin"], PinDirection.OUTPUT, None, out_conf)
File "/home/mqttgpio/pi_mqtt_gpio/modules/raspberrypi.py", line 47, in setup_pin
self.io.setup(pin, direction, pull_up_down=pullup, initial=initial)
RuntimeError: No access to /dev/mem. Try running as root!
docker run --name="mqtt-gpio" --privileged --device /dev/mem --device /dev/gpiomem
https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities says, that you can use --device, if you don't want to use --privileged. May you check one without the other: just --privileged or --device=?
syntax on help page, looks different:
docker run --device=/dev/sda:/dev/xvdc
I've just tried only with --privileged and another try specifying the devices with the syntax from the linked documentation. No luck at all:
root@raspberrypi:~# docker run --name="mqtt-gpio" --privileged -v /home/pi/docker/mqtt-gpio/config.yml:/config.yml -v /etc/localtime:/etc/localtime:ro flyte/mqtt-gpio:armv7l
2020-05-19 22:21:23,774 mqtt_gpio (INFO): Startup
2020-05-19 22:21:25,507 mqtt_gpio (DEBUG): Last will set on 'home/wohnzimmer/status' as 'dead'.
Collecting RPi.GPIO
Downloading RPi.GPIO-0.7.0.tar.gz (30 kB)
Building wheels for collected packages: RPi.GPIO
Building wheel for RPi.GPIO (setup.py): started
Building wheel for RPi.GPIO (setup.py): finished with status 'done'
Created wheel for RPi.GPIO: filename=RPi.GPIO-0.7.0-cp36-cp36m-linux_armv7l.whl size=61764 sha256=250e4ed1ce647e6958e2f2851eec2bc97ba6cf26832b60139fe9e9c84fb05461
Stored in directory: /home/mqttgpio/.cache/pip/wheels/84/c0/d6/73a6e9f98b9d29edd7c6e981dce47852c3321f34518c80dce1
Successfully built RPi.GPIO
Installing collected packages: RPi.GPIO
Successfully installed RPi.GPIO-0.7.0
Collecting Adafruit_DHT
Downloading Adafruit_DHT-1.4.0.tar.gz (15 kB)
Building wheels for collected packages: Adafruit-DHT
Building wheel for Adafruit-DHT (setup.py): started
Building wheel for Adafruit-DHT (setup.py): finished with status 'done'
Created wheel for Adafruit-DHT: filename=Adafruit_DHT-1.4.0-cp36-cp36m-linux_armv7l.whl size=30333 sha256=3f7313bdb7fae4f2503c69df3377a3088bfb5275940ebb379ea4be24896c2888
Stored in directory: /home/mqttgpio/.cache/pip/wheels/af/d8/00/6f0c819ab5f38ea5ececf1b698a9e53888e271300d5f202260
Successfully built Adafruit-DHT
Installing collected packages: Adafruit-DHT
Successfully installed Adafruit-DHT-1.4.0
Traceback (most recent call last):
File "/usr/local/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/local/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/mqttgpio/pi_mqtt_gpio/server.py", line 901, in <module>
main(args)
File "/home/mqttgpio/pi_mqtt_gpio/server.py", line 802, in main
initialise_digital_output(out_conf, GPIO_MODULES[out_conf["module"]])
File "/home/mqttgpio/pi_mqtt_gpio/server.py", line 540, in initialise_digital_output
gpio.setup_pin(out_conf["pin"], PinDirection.OUTPUT, None, out_conf)
File "/home/mqttgpio/pi_mqtt_gpio/modules/raspberrypi.py", line 47, in setup_pin
self.io.setup(pin, direction, pull_up_down=pullup, initial=initial)
RuntimeError: No access to /dev/mem. Try running as root!
root@raspberrypi:~# docker run --name="mqtt-gpio" --device /dev/mem:/dev/mem --device /dev/gpiomem:/dev/gpiomem --device /dev/i2c-1:/dev/i2c-1 -v /home/pi/docker/mqtt-gpio/config.yml:/config.yml -v /etc/localtime:/etc/localtime:ro flyte/mqtt-gpio:armv7l
2020-05-19 22:32:26,060 mqtt_gpio (INFO): Startup
2020-05-19 22:32:27,430 mqtt_gpio (DEBUG): Last will set on 'home/wohnzimmer/status' as 'dead'.
Collecting RPi.GPIO
Downloading RPi.GPIO-0.7.0.tar.gz (30 kB)
Building wheels for collected packages: RPi.GPIO
Building wheel for RPi.GPIO (setup.py): started
Building wheel for RPi.GPIO (setup.py): finished with status 'done'
Created wheel for RPi.GPIO: filename=RPi.GPIO-0.7.0-cp36-cp36m-linux_armv7l.whl size=61783 sha256=2b09aa35b6c22e49825b250cf1a309918dc1139e3bfc5efd42c977aa252f01de
Stored in directory: /home/mqttgpio/.cache/pip/wheels/84/c0/d6/73a6e9f98b9d29edd7c6e981dce47852c3321f34518c80dce1
Successfully built RPi.GPIO
Installing collected packages: RPi.GPIO
Successfully installed RPi.GPIO-0.7.0
Collecting Adafruit_DHT
Downloading Adafruit_DHT-1.4.0.tar.gz (15 kB)
Building wheels for collected packages: Adafruit-DHT
Building wheel for Adafruit-DHT (setup.py): started
Building wheel for Adafruit-DHT (setup.py): finished with status 'done'
Created wheel for Adafruit-DHT: filename=Adafruit_DHT-1.4.0-cp36-cp36m-linux_armv7l.whl size=30320 sha256=35500c891345e234538200a35ed94e0b40411c7a3fc94efad754f3310c56f02a
Stored in directory: /home/mqttgpio/.cache/pip/wheels/af/d8/00/6f0c819ab5f38ea5ececf1b698a9e53888e271300d5f202260
Successfully built Adafruit-DHT
Installing collected packages: Adafruit-DHT
Successfully installed Adafruit-DHT-1.4.0
Traceback (most recent call last):
File "/usr/local/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/local/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/mqttgpio/pi_mqtt_gpio/server.py", line 901, in <module>
main(args)
File "/home/mqttgpio/pi_mqtt_gpio/server.py", line 802, in main
initialise_digital_output(out_conf, GPIO_MODULES[out_conf["module"]])
File "/home/mqttgpio/pi_mqtt_gpio/server.py", line 540, in initialise_digital_output
gpio.setup_pin(out_conf["pin"], PinDirection.OUTPUT, None, out_conf)
File "/home/mqttgpio/pi_mqtt_gpio/modules/raspberrypi.py", line 47, in setup_pin
self.io.setup(pin, direction, pull_up_down=pullup, initial=initial)
RuntimeError: No access to /dev/mem. Try running as root!
I've just tried only with --privileged and another try specifying the devices with the syntax from the linked documentation. No luck at all:
root@raspberrypi:~# docker run --name="mqtt-gpio" --privileged -v /home/pi/docker/mqtt-gpio/config.yml:/config.yml -v /etc/localtime:/etc/localtime:ro flyte/mqtt-gpio:armv7l 2020-05-19 22:21:23,774 mqtt_gpio (INFO): Startup 2020-05-19 22:21:25,507 mqtt_gpio (DEBUG): Last will set on 'home/wohnzimmer/status' as 'dead'. Collecting RPi.GPIO Downloading RPi.GPIO-0.7.0.tar.gz (30 kB) Building wheels for collected packages: RPi.GPIO Building wheel for RPi.GPIO (setup.py): started Building wheel for RPi.GPIO (setup.py): finished with status 'done' Created wheel for RPi.GPIO: filename=RPi.GPIO-0.7.0-cp36-cp36m-linux_armv7l.whl size=61764 sha256=250e4ed1ce647e6958e2f2851eec2bc97ba6cf26832b60139fe9e9c84fb05461 Stored in directory: /home/mqttgpio/.cache/pip/wheels/84/c0/d6/73a6e9f98b9d29edd7c6e981dce47852c3321f34518c80dce1 Successfully built RPi.GPIO Installing collected packages: RPi.GPIO Successfully installed RPi.GPIO-0.7.0 Collecting Adafruit_DHT Downloading Adafruit_DHT-1.4.0.tar.gz (15 kB) Building wheels for collected packages: Adafruit-DHT Building wheel for Adafruit-DHT (setup.py): started Building wheel for Adafruit-DHT (setup.py): finished with status 'done' Created wheel for Adafruit-DHT: filename=Adafruit_DHT-1.4.0-cp36-cp36m-linux_armv7l.whl size=30333 sha256=3f7313bdb7fae4f2503c69df3377a3088bfb5275940ebb379ea4be24896c2888 Stored in directory: /home/mqttgpio/.cache/pip/wheels/af/d8/00/6f0c819ab5f38ea5ececf1b698a9e53888e271300d5f202260 Successfully built Adafruit-DHT Installing collected packages: Adafruit-DHT Successfully installed Adafruit-DHT-1.4.0 Traceback (most recent call last): File "/usr/local/lib/python3.6/runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "/usr/local/lib/python3.6/runpy.py", line 85, in _run_code exec(code, run_globals) File "/home/mqttgpio/pi_mqtt_gpio/server.py", line 901, in <module> main(args) File "/home/mqttgpio/pi_mqtt_gpio/server.py", line 802, in main initialise_digital_output(out_conf, GPIO_MODULES[out_conf["module"]]) File "/home/mqttgpio/pi_mqtt_gpio/server.py", line 540, in initialise_digital_output gpio.setup_pin(out_conf["pin"], PinDirection.OUTPUT, None, out_conf) File "/home/mqttgpio/pi_mqtt_gpio/modules/raspberrypi.py", line 47, in setup_pin self.io.setup(pin, direction, pull_up_down=pullup, initial=initial) RuntimeError: No access to /dev/mem. Try running as root!
root@raspberrypi:~# docker run --name="mqtt-gpio" --device /dev/mem:/dev/mem --device /dev/gpiomem:/dev/gpiomem --device /dev/i2c-1:/dev/i2c-1 -v /home/pi/docker/mqtt-gpio/config.yml:/config.yml -v /etc/localtime:/etc/localtime:ro flyte/mqtt-gpio:armv7l 2020-05-19 22:32:26,060 mqtt_gpio (INFO): Startup 2020-05-19 22:32:27,430 mqtt_gpio (DEBUG): Last will set on 'home/wohnzimmer/status' as 'dead'. Collecting RPi.GPIO Downloading RPi.GPIO-0.7.0.tar.gz (30 kB) Building wheels for collected packages: RPi.GPIO Building wheel for RPi.GPIO (setup.py): started Building wheel for RPi.GPIO (setup.py): finished with status 'done' Created wheel for RPi.GPIO: filename=RPi.GPIO-0.7.0-cp36-cp36m-linux_armv7l.whl size=61783 sha256=2b09aa35b6c22e49825b250cf1a309918dc1139e3bfc5efd42c977aa252f01de Stored in directory: /home/mqttgpio/.cache/pip/wheels/84/c0/d6/73a6e9f98b9d29edd7c6e981dce47852c3321f34518c80dce1 Successfully built RPi.GPIO Installing collected packages: RPi.GPIO Successfully installed RPi.GPIO-0.7.0 Collecting Adafruit_DHT Downloading Adafruit_DHT-1.4.0.tar.gz (15 kB) Building wheels for collected packages: Adafruit-DHT Building wheel for Adafruit-DHT (setup.py): started Building wheel for Adafruit-DHT (setup.py): finished with status 'done' Created wheel for Adafruit-DHT: filename=Adafruit_DHT-1.4.0-cp36-cp36m-linux_armv7l.whl size=30320 sha256=35500c891345e234538200a35ed94e0b40411c7a3fc94efad754f3310c56f02a Stored in directory: /home/mqttgpio/.cache/pip/wheels/af/d8/00/6f0c819ab5f38ea5ececf1b698a9e53888e271300d5f202260 Successfully built Adafruit-DHT Installing collected packages: Adafruit-DHT Successfully installed Adafruit-DHT-1.4.0 Traceback (most recent call last): File "/usr/local/lib/python3.6/runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "/usr/local/lib/python3.6/runpy.py", line 85, in _run_code exec(code, run_globals) File "/home/mqttgpio/pi_mqtt_gpio/server.py", line 901, in <module> main(args) File "/home/mqttgpio/pi_mqtt_gpio/server.py", line 802, in main initialise_digital_output(out_conf, GPIO_MODULES[out_conf["module"]]) File "/home/mqttgpio/pi_mqtt_gpio/server.py", line 540, in initialise_digital_output gpio.setup_pin(out_conf["pin"], PinDirection.OUTPUT, None, out_conf) File "/home/mqttgpio/pi_mqtt_gpio/modules/raspberrypi.py", line 47, in setup_pin self.io.setup(pin, direction, pull_up_down=pullup, initial=initial) RuntimeError: No access to /dev/mem. Try running as root!
same issue for me
Same.
I am having a similar issue but I am trying to run a python script with a php file. Whenever I try to run it i get RuntimeError: No access to /dev/mem. Try running as root!. I am using apache2 to run a webserver and i have setup then index.php file to run a simple python. Anyone know how to solve this error.
Hi, I have the same error, however, it's for the newest version of mqtt_io add-on:
Add-on: MQTT IO
Expose GPIO modules and digital sensors via MQTT for remote control and monitoring.
-----------------------------------------------------------
Add-on version: 0.1.3
You are running the latest version of this add-on.
System: Home Assistant OS 9.3 (aarch64 / raspberrypi4-64)
Home Assistant Core: 2022.10.5
Home Assistant Supervisor: 2022.10.0
I'm using this config:
mqtt:
host: ...
port: ...
user: ...
password: ...
topic_prefix: home/depot/climate
ha_discovery:
enabled: yes
sensor_modules:
- name: dht_depot
module: dht22
type: DHT22
pin: 4
sensor_inputs:
- name: depot_temp
module: dht_depot
interval: 10
digits: 4
type: temperature
ha_discovery:
name: Depot temperature
device_class: temperature
- name: depot_humidity
module: dht_depot
interval: 10
digits: 4
type: humidity
ha_discovery:
name: Depot humidity
device_class: humidity
And here is the log:
2022-11-02 20:37:12 mqtt_io.server [INFO] Connected to MQTT
2022-11-02 20:37:21 mqtt_io.server [ERROR] Exception when retrieving value from sensor 'depot_temp':
Traceback (most recent call last):
File "/usr/lib/python3.10/site-packages/mqtt_io/server.py", line 561, in poll_sensor
value = await get_sensor_value()
File "/usr/lib/python3.10/site-packages/backoff/_async.py", line 133, in retry
ret = await target(*args, **kwargs)
File "/usr/lib/python3.10/site-packages/backoff/_async.py", line 66, in retry
ret = await target(*args, **kwargs)
File "/usr/lib/python3.10/site-packages/mqtt_io/server.py", line 556, in get_sensor_value
return await sensor_module.async_get_value(sens_conf)
File "/usr/lib/python3.10/site-packages/mqtt_io/modules/sensor/__init__.py", line 57, in async_get_value
return await loop.run_in_executor(ThreadPoolExecutor(), self.get_value, sens_conf)
File "/usr/lib/python3.10/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/lib/python3.10/site-packages/mqtt_io/modules/sensor/dht22.py", line 62, in get_value
humidity, temperature = self.sensor.read_retry(self.sensor_type, self.pin)
File "/usr/lib/python3.10/site-packages/Adafruit_DHT/common.py", line 94, in read_retry
humidity, temperature = read(sensor, pin, platform)
File "/usr/lib/python3.10/site-packages/Adafruit_DHT/common.py", line 81, in read
return platform.read(sensor, pin)
File "/usr/lib/python3.10/site-packages/Adafruit_DHT/Raspberry_Pi_2.py", line 34, in read
raise RuntimeError('Error accessing GPIO.')
RuntimeError: Error accessing GPIO.
Is it something wrong with my config? I have tried two different DHT22 devices connected in the same way
How do you execute it? Looks like a privilege problem!
I simply added the add-on to the HA and clicked the run button. I'm using HASSIO so I assumed it runs with full access to everything.
Hmm, okay. That's a setup I do not have, so I may not help you. I guess it's a HASSIO problem/decision? https://community.home-assistant.io/t/access-rpi-gpio-in-custom-addon/383429 <-- Says 64bit can't use GPIOs https://community.home-assistant.io/t/removal-of-gpio-support/372222/162 <-- no direct use of GPIO, so the addons won't be, too, I guess.
So I would have to install it with other distribution and then install HA and mqtt.io separately. Thanks for help! I'll back with my findings here
@mchmielarz i will close this issue, because it was originally related to docker (2020). Please create a new issue or use #293 Thanks!
Hi, I'm struggling with getting the docker container to access the GPIO. I'm running a raspberry pi 3B+ with raspbian. I've attached a AM2302 on pin 4 and configured pi-mqtt-gpio as follow:
This is the output of the container and the log (I've killed the container with CTRL-C):
I'm out of ideas. Could someone help me out?
Best regards Mirko