I am developing a weather station. I use a Raspberry Pi 2 as well as a DHT22 sensor. I use Adafruit to read the sensor's data. I installed it like described in their Readme. I tried both ways but unfortunately non of them worked.
Reading the data works sometimes, but it does never work when I try to read it in my Flask application
Here is my code:
import Adafruit_DHT
app = Flask(__name__)
sensor = Adafruit_DHT.DHT22
gpio = 4
@app.route('/')
def index():
return "This is the index page"
@app.route('/humidity', methods=['GET'])
def get_humidity():
humidity, temperature = Adafruit_DHT.read_retry(sensor, gpio)
return humidity
@app.route('/temperature', methods=['GET'])
def get_humidity():
humidity, temperature = Adafruit_DHT.read_retry(sensor, gpio)
return temperature
@app.route('/all', methods=['GET'])
def get_humidity():
humidity, temperature = Adafruit_DHT.read_retry(sensor, gpio)
return 'humidity='+humidity+';temperature='+temperature
if __name__ == 'main':
app.run()
Additionally, I had a look at the following answers on Stackoverflow.com:
I appreciate your help!
Update Adafruit works well if I disable the virtual environment