flyte/mqtt-io

Chip has no attribute 'OPEN_BY_NAME' - Orange Pi Zero

jon-daemon opened this issue · 2 comments

Orange Pi Zero
Armbian
Python 3.9.0 in irtual environment

I use a gpio pin on my board which works fine with this config:

mqtt:
  host: localhost
  port: 1883
  user: ***
  password: ***
  topic_prefix: home
  ha_discovery:
    enabled: yes

# GPIO
gpio_modules:
  - name: opi
    module: orangepi
    mode: board

I want to add a ADS1015. I'm not sure if the config is correct but I have added these lines:

sensor_modules:
  - name: adc_sensor
    module: ads1x15
    type: ADS1015
    pins: [0]

sensor_inputs:
  - name: ups_batt_voltage
    module: adc_sensor

I installed libgpiod2 python3-libgpiod and in the virtual environment I installed gpiod with pip3 install gpiod

When I start mqtt-io I get this error:

AttributeError: type object 'Chip' has no attribute 'OPEN_BY_NAME'

Where am I missing?

I fixed my config using the example here, so my config is now this:

sensor_modules:
  - name: ads
    module: ads1x15
    type: ADS1015
    pins:
      - 0
      - 1
    chip_addr: 0x48

sensor_inputs:
  - name: voltage_a0
    module: ads
    type: voltage
    pin: 0
    interval: 120
    digits: 2

  - name: voltage_a1
    module: ads
    type: voltage
    pin: 1
    interval: 120
    digits: 2

I checked the code at the bottom here and I discovered that I cannot run the blinkatest.py example in my virtual environment. I get a permissions issue on these two lines:

import board
import digitalio

This code runs outside of my virtual environment but only if I use sudo.

So I reinstalled mqtt-io with sudo and tried to run with: sudo python3 -m mqtt_io mqttio/config.yml
but I get this:

/usr/local/lib/python3.9/dist-packages/mqtt_io/modules/gpio/orangepi.py:63: UserWarning: Pull up/down setting are not (yet) fully supported, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
  self.io.setup(pin, direction, pull_up_down=pullup, initial=initial_int)
/usr/local/lib/python3.9/dist-packages/mqtt_io/modules/gpio/orangepi.py:63: UserWarning: Channel 7 is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
  self.io.setup(pin, direction, pull_up_down=pullup, initial=initial_int)
Traceback (most recent call last):
  File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.9/dist-packages/mqtt_io/__main__.py", line 85, in <module>
    main()
  File "/usr/local/lib/python3.9/dist-packages/mqtt_io/__main__.py", line 80, in main
    mqtt_gpio.run()
  File "/usr/local/lib/python3.9/dist-packages/mqtt_io/server.py", line 1136, in run
    self._init_sensor_modules()
  File "/usr/local/lib/python3.9/dist-packages/mqtt_io/server.py", line 244, in _init_sensor_modules
    self.sensor_modules[sens_config["name"]] = _init_module(sens_config, "sensor")
  File "/usr/local/lib/python3.9/dist-packages/mqtt_io/server.py", line 107, in _init_module
    module = import_module(
  File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'mqtt_io.modules.sensor.ads1x15'

What's the correct way to install and run? What am I doing wrong?

I found that it was a permissions issue and I describe here the fix.