Log and visualize your sensors with WeIO and emoncms.

emoncms_dashboard

Thanks to the DHT22 sensor (temperature and humidity sensor) and a nice collaboration with a contributor to debug and add support for this sensor in WeIO, I discovered emoncms.

emoncms is an open source web app made to log and visualize environment data. Easy to use, it log your environmental sensors, like temperature, humidity, light, etc. with a minimum of code on your side.

This short post will explain how to use it.

The first step is to create an account. Once this is done, you’ll see your API keys. There’s two API keys : one to write, and one to read. What interests us here is the Write API key. Find it, it’ll be needed after.

The second step consists of creating the code to read the sensor(s). Below, a small example for the DHT22 sensor :

from weioLib.weio import *
import datetime

def setup():
    attach.process(myProcess)

def myProcess():
    pinDHT22 = 8
    
    while True:
        data = dhtRead(pinDHT22)
        checksum = (data[0] + data[1] + data[2] + data[3]) & 0xFF
        humidity = (data[0]*256+data[1])/10.0
        temperature = ((data[2] & 0x80)*256+data[3])/10.0
        print "Temperature : ", temperature
        print "Humidity : ", humidity
        delay(10000)

Once you have a code able to read your sensor data, you can transform the code to send the data to emoncms. In my example, the code is transformed that way :

from weioLib.weio import *
import datetime
import urllib2

def setup():
    attach.process(myProcess)

def myProcess():
    pinDHT22 = 8
    emoncms_url = "emoncms.org"
    emonApiKey="xxxxxxxxxx" # Put your Write API here
    
    while True:
        data = dhtRead(pinDHT22)
        checksum = (data[0] + data[1] + data[2] + data[3]) & 0xFF
        humidity = (data[0]*256+data[1])/10.0
        temperature = ((data[2] & 0x80)*256+data[3])/10.0
        print "Temperature : ", temperature
        print "Humidity : ", humidity

        # Prepare the data
        json = "{temp:" + "%.2f"%temperature
        json += ",humidity:" + "%.2f"%humidity + "}"

        # Prepare the URL 
        url  ="http://" + emonHostname + "/" +  "input/post.json?node=1&apikey=" + emonApiKey + "&json=" + urllib2.quote(json)
     
        # Send the data to emoncms
        urllib2.urlopen(url)

        delay(10000)

 

This code will send, every 10s, the temperature and humidity value. These values will be received in emoncms, as an input sources.

emoncms_inputs

All input source can be logged to feeds, which will allows to display graphs of the data. You can also create a dashboard with all the data you want to display. For example, I’ve created a multigraph view of two temperature sensors (one in my lab, one at home) :

emoncms_dashboard
And that’s it ! I can now monitor the temperature of my home and my lab from everywhere.

Paul Rathgeb posted this.

02, May

About Paul Rathgeb

hacker, maker, dreamer ...

Comments (1)

Did this answer your question? If not, send us a message?