Himura Kazuto
Published © MIT

Humidity in the Cloud

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

EasyFull instructions provided1 hour982
Humidity in the Cloud

Things used in this project

Hardware components

Raspberry Pi 1 Model B+
Raspberry Pi 1 Model B+
Or other single-board PC
×1
DHT22 Temperature Sensor
DHT22 Temperature Sensor
Or DHT11
×1

Software apps and online services

Cloud4RPi
Cloud4RPi
Python

Story

Read more

Schematics

How to connect DHT22 to RPi

1 1ofbcy2nyowann1jfoz0nw n0mu9piwb6

Code

Dummy Functions to Remove

Python
def cpu_temp():
    return 70
def ip_address():
    return '8.8.8.8'
def hostname():
    return 'hostname'
def osname():
    return 'osx'

Getting Temperature and Humidity

Python
import Adafruit_DHT

temp, 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 '%.2f' % temp

def get_h():
    update_data()
    return '%.2f' % hum

Cloud4RPi Variables

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

Service Status and Log

Plain text
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.py

May 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'}}

Cloud4RPi Minimal Example

My Fork of Adafruit Python DHT

Credits

Himura Kazuto

Himura Kazuto

0 projects • 0 followers

Comments