flyte / mqtt-io

Expose GPIO modules (Raspberry Pi, Beaglebone, PCF8754, PiFace2 etc.) and digital sensors (LM75 etc.) to an MQTT server for remote control and monitoring.
MIT License
467 stars 157 forks source link

module orangepi crash #284

Closed whakru closed 1 year ago

whakru commented 2 years ago

Describe the bug i just want to tweak the GPIO on my orange pi 3 lts. Took an example and it doesn't work.

Error messages and traceback

s6-rc: info: service s6rc-oneshot-runner: starting
s6-rc: info: service s6rc-oneshot-runner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service fix-attrs successfully started
s6-rc: info: service legacy-cont-init: starting
cont-init: info: running /etc/cont-init.d/00-banner.sh
-----------------------------------------------------------
 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: Ubuntu 22.04.1 LTS  (aarch64 / odroid-c2)
 Home Assistant Core: 2022.9.6
 Home Assistant Supervisor: 2022.09.1
-----------------------------------------------------------
 Please, share the above information when looking for help
 or support in, e.g., GitHub, forums or the Discord chat.
-----------------------------------------------------------
cont-init: info: /etc/cont-init.d/00-banner.sh exited 0
cont-init: info: running /etc/cont-init.d/01-log-level.sh
Log level is set to DEBUG
cont-init: info: /etc/cont-init.d/01-log-level.sh exited 0
cont-init: info: running /etc/cont-init.d/mqtt-io.sh
cont-init: info: /etc/cont-init.d/mqtt-io.sh exited 0
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service legacy-services: starting
services-up: info: copying legacy longrun mqtt-io (no readiness notification)
s6-rc: info: service legacy-services successfully started
[20:09:07] INFO: Starting MQTT IO...
2022-09-24 20:09:16 mqtt_io.__main__ [ERROR] MqttIo crashed!
Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/mqtt_io/__main__.py", line 107, in main
    mqtt_gpio.run()
  File "/usr/lib/python3.10/site-packages/mqtt_io/server.py", line 1227, in run
    self._init_gpio_modules()
  File "/usr/lib/python3.10/site-packages/mqtt_io/server.py", line 244, in _init_gpio_modules
    self.gpio_modules[gpio_config["name"]] = _init_module(
  File "/usr/lib/python3.10/site-packages/mqtt_io/server.py", line 122, in _init_module
    module_config = validate_and_normalise_config(module_config, module_schema)
  File "/usr/lib/python3.10/site-packages/mqtt_io/config/__init__.py", line 105, in validate_and_normalise_config
    raise ConfigValidationFailed(
mqtt_io.exceptions.ConfigValidationFailed: Config did not validate:
board:
- required field
Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/usr/lib/python3.10/site-packages/mqtt_io/__main__.py", line 115, in <module>
    main()
  File "/usr/lib/python3.10/site-packages/mqtt_io/__main__.py", line 107, in main
    mqtt_gpio.run()
  File "/usr/lib/python3.10/site-packages/mqtt_io/server.py", line 1227, in run
    self._init_gpio_modules()
  File "/usr/lib/python3.10/site-packages/mqtt_io/server.py", line 244, in _init_gpio_modules
    self.gpio_modules[gpio_config["name"]] = _init_module(
  File "/usr/lib/python3.10/site-packages/mqtt_io/server.py", line 122, in _init_module
    module_config = validate_and_normalise_config(module_config, module_schema)
  File "/usr/lib/python3.10/site-packages/mqtt_io/config/__init__.py", line 105, in validate_and_normalise_config
    raise ConfigValidationFailed(
mqtt_io.exceptions.ConfigValidationFailed: Config did not validate:
board:
- required field
[20:09:16] WARNING: MQTT IO crashed, halting add-on
s6-rc: info: service legacy-services: stopping
[20:09:17] INFO: MQTT IO stopped
s6-rc: info: service legacy-services successfully stopped
s6-rc: info: service legacy-cont-init: stopping
s6-rc: info: service legacy-cont-init successfully stopped
s6-rc: info: service fix-attrs: stopping
s6-rc: info: service fix-attrs successfully stopped
s6-rc: info: service s6rc-oneshot-runner: stopping
s6-rc: info: service s6rc-oneshot-runner successfully stopped

Config

mqtt:
  host: localhost
  port: 1883
  user: "*****"
  password: "*******"
  topic_prefix: home/mqtt_io

gpio_modules:
  - name: orgpio
    module: orangepi

digital_outputs:
  - name: fans
    module: orgpio
    pin: 1
    on_payload: "ON"
    off_payload: "OFF"
    pullup: yes    

Hardware Orange pi 3 lts

System: Home Assistant 2022.9.6 Supervisor 2022.09.1 Frontend 20220907.2 - latest

Integration MQTT IO Current version: 0.1.3

neatherweb commented 1 year ago

I was just trying to set this up with opi zero and it seems there is a few issues with this module. It adds board and mode to the config schema but also references old OrangePi.GPIO module as requirement - but uses OPi.GPIO. I can't see any use for the board option as there is no setboard for OPi.GPIO. mode needs to be one of [BCM, BOARD, SUNXI, CUSTOM]

Below patch removes the board setting and fixes requirement module - this works for me. I will try and do a PR later.

--- orangepi.py.orig    2022-10-10 09:44:28.139118027 +1100
+++ orangepi.py 2022-10-10 09:51:30.311322016 +1100
@@ -7,28 +7,9 @@
 from ...types import ConfigType, PinType
 from . import GenericGPIO, PinDirection, PinPUD

-ALLOWED_BOARDS = [
-    "zero",
-    "r1",
-    "zeroplus",
-    "zeroplus2h5",
-    "zeroplus2h3",
-    "pcpcplus",
-    "one",
-    "lite",
-    "plus2e",
-    "pc2",
-    "prime",
-]
 ALLOWED_MODES = ["bcm", "board", "mode_soc"]
-REQUIREMENTS = ("OrangePi.GPIO",)
+REQUIREMENTS = ("OPi.GPIO",)
 CONFIG_SCHEMA = {
-    "board": {
-        "type": "string",
-        "required": True,
-        "empty": False,
-        "allowed": ALLOWED_BOARDS + list(map(str.upper, ALLOWED_BOARDS)),
-    },
     "mode": {
         "type": "string",
         "required": True,
@@ -58,12 +39,7 @@
             PinPUD.UP: gpio.PUD_UP,
             PinPUD.DOWN: gpio.PUD_DOWN,
         }
-
-        board = self.config["board"].upper()
         mode = self.config["mode"].upper()
-        if not hasattr(gpio, board):
-            raise AssertionError("%s board not found" % board)
-        gpio.setboard(getattr(gpio, board))
         gpio.setmode(getattr(gpio, mode))

     def setup_pin(

And your config will need to specify mode (which essentially identifies the pin numbering)

gpio_modules:
  - name: orangepi
    module: orangepi
    mode: bcm