Cloud4RPi
Published

Humidity in the Cloud

The modern way to measure the most important parameters for human comfort: temperature and humidity.

BeginnerFull instructions provided1 hour813
Humidity in the Cloud

Things used in this project

Hardware components

Raspberry Pi 1 Model B+
Raspberry Pi 1 Model B+
or other compatible model
×1
DHT22 Temperature Sensor
DHT22 Temperature Sensor
or DHT11
×1

Software apps and online services

Raspbian
Raspberry Pi Raspbian
Cloud4RPi
Cloud4RPi

Story

Read more

Schematics

raspberry pi & dht11/22

Code

DHT11 readings

Python
Get temperature and humidity values from DHT11 sensor
import Adafruit_DHTtemp, hum = None, None

last_update = time.time() - 20

def update_data():
    global last_update, hum, temp
    if time.time() - last_update > 10:
        hum, temp = Adafruit_DHT.read_retry(Adafruit_DHT.DHT22, 4)
        last_update = time.time()

def get_t():
    update_data()
    return round(temp, 2) if temp is not None else None

def get_h():
    update_data()
    return round(hum, 2) if hum is not None else None

Cloud4RPi variables

Python
Variables declaration
variables = {    
    'DHT22 Temp': {
            'type': 'numeric',
            'bind': get_t
    },
    'DHT22 Humidity': {
            'type': 'numeric',
            'bind': get_h
    },
    'CPU Temp': {
            'type': 'numeric',
            'bind': cpu_temp
    }
}

Starting Cloud4RPi service

SH
Log information
pi@raspberrypi:~ $ sudo service cloud4rpi status -l● cloud4rpi.service - Cloud4RPi daemon
   Loaded: loaded (/lib/systemd/system/cloud4rpi.service; enabled)
   Active: active (running) since Wed 2017-05-17 20:22:48 UTC; 1min ago
 Main PID: 560 (python)
   CGroup: /system.slice/cloud4rpi.service
           └─560 /usr/bin/python /home/pi/cloud_dht22.pyMay 17 20:22:51 raspberrypi python[560]: Publishing iot-hub/messages: {'type': 'config', 'ts': '2017-05-17T20...y'}]}
May 17 20:22:53 raspberrypi python[560]: Publishing iot-hub/messages: {'type': 'data', 'ts': '2017-05-17T20:2...40'}}
May 17 20:22:53 raspberrypi python[560]: Publishing iot-hub/messages: {'type': 'system', 'ts': '2017-05-17T20....4'}}

Adafruit_Python_DHT repository

https://github.com/adafruit/Adafruit_Python_DHT

Adafruit_Python_DHT library fork

https://github.com/Himura2la/Adafruit_Python_DHT

Credits

Cloud4RPi
8 projects • 20 followers
Cloud control panel for your IoT projects. Use dashboard widgets to display device data in real-time. Control your IoT devices remotely.
Contact

Comments

Please log in or sign up to comment.