mqtt-io icon indicating copy to clipboard operation
mqtt-io copied to clipboard

support adafruit-circuitpython-dht

Open heyhpython opened this issue 2 years ago • 1 comments

Please consider joining the Discord server in order to get support. This is likely to be the quickest way for somebody to help you.

If you'd still like to add your support request as a GitHub Issue, please fill in the following template as best you can:

Action description install requirement Adafruit_DHT fail for Could not detect if running on the Raspberry Pi or Beaglebone Black. If this failure is unexpected, you can run again with --force-pi or --force-bbb parameter to force using the Raspberry Pi or Beaglebone Black respectively. image

Previous attempts Describe what you've tried so far.

Error messages and traceback

Paste any error messages and Python traceback if applicable.

Config

# Sensors
sensor_modules:
  - name: dht11_sensor
    module: dht22
    type: dht11
    pin: 17

sensor_inputs:
  # The configuration of the specific sensor value to use (LM75 only has temperature)
  - name: temperature_humidity
    module: dht11_sensor
    interval: 1
    retain: false```

**Hardware**
 - Platform:  Raspberry Pi 4B 4G
 - Connected hardware: sensors

**System:**
 - OS: [e.g. Raspbian]
 - Python version:3.9.2
 - User you're running as: pi
 - Using a virtualenv?: yes

**Additional context**
Add any other context about the problem here.
https://stackoverflow.com/questions/63232072/cannot-import-name-beaglebone-black-driver-from-adafruit-dht
Adafruit_DHT had been archived and the authot changed to adafruit-circuitpython-dht
https://learn.adafruit.com/dht-humidity-sensing-on-raspberry-pi-with-gdocs-logging/python-setup

maybe this repo should support the new python libary

heyhpython avatar Dec 07 '21 13:12 heyhpython

Hi, some further information here. No actual solution at the moment though.

I am using a Raspberry Pi 1.

I manually installed the Adafruit library with pip install Adafruit_DHT --install-option="--force-pi" and I got failures relating back to this library's platform_detection.py file:

ImportError: cannot import name 'Raspberry_Pi_2_Driver' from 'Adafruit_DHT' (/venv/lib/python3.8/site-packages/Adafruit_DHT/__init__.py)

Specifically this part:

def pi_version():
    """Detect the version of the Raspberry Pi.  Returns either 1, 2, 3 or
    None depending on if it's a Raspberry Pi 1 (model A, B, A+, B+),
    Raspberry Pi 2 (model B+), Raspberry Pi 3,Raspberry Pi 3 (model B+), Raspberry Pi 4
    or not a Raspberry Pi.
    """
    # Check /proc/cpuinfo for the Hardware field value.
    # 2708 is pi 1
    # 2709 is pi 2
    # 2835 is pi 3 or pi 4
    # 2837 is pi 3b+
    # Anything else is not a pi.
    with open('/proc/cpuinfo', 'r') as infile:
        cpuinfo = infile.read()
    # Match a line like 'Hardware   : BCM2709'
    match = re.search('^Hardware\s+:\s+(\w+)$', cpuinfo,
                      flags=re.MULTILINE | re.IGNORECASE)
    if not match:
        # Couldn't find the hardware, assume it isn't a pi.
        return None
    if match.group(1) == 'BCM2708':
        # Pi 1
        return 1
    elif match.group(1) == 'BCM2709':
        # Pi 2
        return 2
    elif match.group(1) == 'BCM2835':
        # Pi 3 or Pi 4
        return 3
    elif match.group(1) == 'BCM2837':
        # Pi 3b+
        return 3
    else:
        # Something else, not a pi.
        return None

From google, there seems to have been upstream changes that cause cpuinfo to now return Hardware: BCM2835 for all Raspberry Pi 0/1/2/3, which in turn breaks this platform check.

As said in the original post, the Adafruit_DHT library has been deprecated in favour of their CircuitPython libraries, so we won't see a fix for this platform check.

dandantheflyingman avatar Jan 28 '22 03:01 dandantheflyingman