This tutorial presents how Beebotte can be used to monitor temperature and humidity of your home or office. We will use a Raspberry Pi
to report data to Beebotte and a DHT11
sensor to detect humidity and temperature.
This tutorial assumes that you have successfully registered
to Beebotte and obtained your API and Secret keys
.
Tutorial contents:
We will connect a low cost DHT11 humidity and temperature sensor to a Raspberry Pi board and report readings to Beebotte using the Python SDK (REST API). We need the following:
Follow the following wiring diagram to setup your hardware:
Before sensding data to Beebotte, we need to create a Channel
. For this experiment, we need to create two resources for humidity and temperature.
In your account home page, click on Create New
and follow the instructions to create your channel.
We use Beebotte Python SDK to send sensor data to the created channel. We need to specify the API access and secret keys of our account, and to indicate the names of the created channel and resources.
In order to run the code, we need first to install the required packages:
Beebotte Python SDK
can be downloaded with:
Adafruit Python library
to read data from DHT11 sensor (among others) can be downloaded as described here.
#!/usr/bin/env python | |
############################################################ | |
# This code uses the Beebotte API, you must have an account. | |
# You can register here: http://beebotte.com/register | |
############################################################ | |
import time | |
import Adafruit_DHT | |
from beebotte import * | |
### Replace API_KEY and SECRET_KEY with those of your account | |
bbt = BBT('API_KEY', 'SECRET_KEY') | |
period = 60 ## Sensor data reporting period (1 minute) | |
pin = 4 ## Assuming the DHT11 sensor is connected to GPIO pin number 4 | |
### Change channel name and resource names as suits you | |
temp_resource = Resource(bbt, 'RaspberryPi', 'temperature') | |
humid_resource = Resource(bbt, 'RaspberryPi', 'humidity') | |
def run(): | |
while True: | |
### Assume | |
humidity, temperature = Adafruit_DHT.read_retry( Adafruit_DHT.DHT11, pin ) | |
if humidity is not None and temperature is not None: | |
print "Temp={0:f}*C Humidity={1:f}%".format(temperature, humidity) | |
try: | |
#Send temperature to Beebotte | |
temp_resource.write(temperature) | |
#Send humidity to Beebotte | |
humid_resource.write(humidity) | |
except Exception: | |
## Process exception here | |
print "Error while writing to Beebotte" | |
else: | |
print "Failed to get reading. Try again!" | |
#Sleep some time | |
time.sleep( period ) | |
run() |
In your account page, goto My Dashboards
and click Create Dashboard
; enter a friendly name and a short description of your dashboard then add 2 Attribute
Widgets and 2 Timeline
widgets. For every widget, indicate the channel and resource where data will be read from. Voilà.
If you wish, you can set your dashboard as public
.
In this tutorial we learned how to connect a Raspberry Pi to Beebotte. You can enhance your project by: