mstenta / atmospi

Atmospheric monitoring app for logging and graphing temperatures and humidities over time using a Raspberry Pi and DS18B20, DHT11, DHT22, and AM2302 sensor(s).
31 stars 9 forks source link

DHT22 sensor #15

Closed aukeboskma closed 9 years ago

aukeboskma commented 10 years ago

Hi,

I'm trying to add a DHT22 sensor. But I got an error and I have no idea how to fix this. Hope you can help.

pi@raspberrypi ~/atmospi/Atmospi $ sudo ./measure-dht.py Traceback (most recent call last): File "./measure-dht.py", line 52, in readings = read_sensors() File "./measure-dht.py", line 33, in read_sensors tc, h = dhtreader.read(sensor_types[device['type']], device['pin']) TypeError: 'NoneType' object is not iterable

Settings.py looks like this

Atmospi settings.

settings = {

# Absolute path to the SQLite database file.
'db': '/home/pi/atmospi/log.db',

# Define the DHT devices and the GPIO pin they are connected to.
    'dht_devices': {
            'Humidity1': {
                    'type': 'DHT22',
                    'pin': 29
            }
    }

}

mstenta commented 10 years ago

Hmm, it looks ok, but it definitely seems like the 'dht_devices' variable is not being interpreted correctly.

Is your settings file called "settings.py" or "Settings.py". You mentioned it with a capital S, so I wanted to make sure. I think that it is case sensitive.

The error indicates that the 'dht_devices' variable is empty (not iterable), so I wonder if it's trying to use the default_settings.py instead, which has an empty 'dht_devices' variable. You could try putting your device information directly in default_settings.py instead of settings.py, to see if that's what's happening.

aukeboskma commented 10 years ago

Ok, I did what you said. I also deleted settings.py (it was with s not capital). but I get the same error message. Any other thoughts?

EDIT: Damn I think I see the problem. I have an AM2302 sensor instead of a DHT22. So I need to remove the resistor beacuse a AM2302 has his own resistor. I will let you know if this solved my problem :)

mstenta commented 10 years ago

Ah ok. So maybe it was a hardware issue then?

Still, the error you pasted did sound like it was an issue with the dht_devices variable in the settings. If you deleted the settings.py, then the script will fall back on default_settings.py, which has an empty dht_devices variable... so be sure to fill that in with your device settings like you did in settings.py.

Also... I don't remember, but you may need to restart Apache for the changes in settings.py to take affect. So maybe give that a try too.

Good luck!

aukeboskma commented 10 years ago

Still the same problem. Like you said. It is not a hardware error. What is the best thing to try? Hardcode measure-dht.py? Or if you have time acces my pi via putty.

mstenta commented 10 years ago

Can you paste your full default_settings.py file verbatim? (Or settings.py, if you're using that.)

aukeboskma commented 10 years ago

I deleted settings.py. And only have default_settings.py. I have a Raspbery Pi B+ so that is why I use pin 37.

default_settings.py GNU nano 2.2.6 File: default_settings.py

Atmospi settings.

settings = {

# Absolute path to the SQLite database file.
'db': '/home/pi/atmospi/log.db',

# Define the DHT devices and the GPIO pin they are connected to.
#
# dht_devices should be a dictionary of dictionaries. The name of each
# dictionary will be used as the device's unique ID.
#
# For example:
#
# 'dht_devices': {
#     'Name of sensor': {
#         'type': 'DHT22',
#         'pin': 22
#     }
# }
#
# Available device types: DHT11, DHT22, AM2302
    'dht_devices': {
            'DHT22': {
                    'type': 'DHT22',
                    'pin': 37
            }
    }

}

mstenta commented 10 years ago

I'm stumped. And I don't remember how to SSH into your Pi. Can you email me the login again?

aukeboskma commented 10 years ago

I have sent you a message via your website.

mstenta commented 10 years ago

Thanks.

FYI I made the following changes in your Pi:

Then I googled, and found this: http://www.raspberrypi.org/forums/viewtopic.php?t=60932&p=455119

It sounds like the issue might actually be coming from the dhtlibrary itself, not from atmospi. But, atmospi is not handling the error, and crashes. I don't think that really matters, though, since this is just a script that runs on cron, unlike the init.py which needs to continue running.

The issue described in the link above sounds like it happens intermittently for them... but it's happening all the time for you.

Are you sure you have the right PIN? And are you sure it's wired correctly? Could you post a photo perhaps?

aukeboskma commented 10 years ago

First, thanks for helping me with this.

photo_2014-11-06_22-40-25

This is how I wired it up. I have the sensor connected to 5V, I also tried 3V3 same result. Blue is data, red is +5 and white is -. Data(blue) is connected to PIN 37.

aukeboskma commented 10 years ago

F*CK.. I know the problem.... I just thought lets try GPIO26 instead of pin 37 and I it is working now. stupid that i didn't tried this before. Thanks for helping.

mstenta commented 10 years ago

Awesome! I had a feeling it would be something simple. Glad it's working!

aukeboskma commented 10 years ago

Last question for now, how to add a second DHT22

'dht_devices': {
    'DHT22': {
        'type': 'DHT22',
        'pin': 26
    }
    'DHT22_outside': {
        'type': 'DHT22',
        'pin': 19
    }
}

What am I doing wrong in this. Sorry with my python skills I can't solve this one.

mstenta commented 10 years ago

It looks OK to me. What is happening when you run it?

To be honest, I've never tried with multiple DHT sensors... so this will be the first real test of that.

aukeboskma commented 10 years ago

This is the error when I run it. dht22

full code:

Atmospi settings.

settings = {

# Absolute path to the SQLite database file.
'db': '/home/pi/atmospi/log.db',

# Define the DHT devices and the GPIO pin they are connected to.
#
# dht_devices should be a dictionary of dictionaries. The name of each
# dictionary will be used as the device's unique ID.
#
# For example:
#
# 'dht_devices': {
#     'Name of sensor': {
#         'type': 'DHT22',
#         'pin': 22
#     }
# }
#
# Available device types: DHT11, DHT22, AM2302
'dht_devices': {
    'DHT22': {
        'type': 'DHT22',
        'pin': 26
    }

'DHT22_outside': {
    'type': 'DHT22',
    'pin': 19
    }
}

}

mstenta commented 10 years ago

Oh you're missing a comment after the closing bracket of the 'DHT22' device (the first one). It should be:

'dht_devices': {
    'DHT22': {
        'type': 'DHT22',
        'pin': 26
    },
    'DHT22_outside': {
        'type': 'DHT22',
        'pin': 19
    }
}
aukeboskma commented 10 years ago

Awesome it is working fine now :+1: Thank you so much.

What you said here https://github.com/mstenta/atmospi/issues/15#issuecomment-61984941 I see it happening sometimes when I run measure-dht.py manually. So sometimes I will have some missing data in my graph, but that's not really a problem.

mstenta commented 9 years ago

Closing this issue, because you got it working! :-)