Home > Others related to the project > Indoor environment parameters on Pachube

Indoor environment parameters on Pachube


The Pachube website has become famous since it permits to software applications (developed with different kind of languages – Java, C, Processing, etc.) to connect to an online storage and presentation system. Using specific procedures a software application is able to save essential information, at each half a minute (or longer time interval). In fact, the website is dedicated to monitoring systems, which measure the same parameters  values at defined periods of time, and need to save the information somewhere or transmit it for other applications input.

Our example is based on using the Seduino SHT11 sensor, connected to an Arduino Duemilanove board. The development board read the information from the sensor (temperature, relative humidity and dew point; the last parameter is calculated based on the first 2 parameters values) and transmit it to Pachube website. The architecture of the system and the connections between the components is presented into the figure below.

On Pachube website, charts with the evolution of the parameters values could be displayed and the status of the device is visible (if it is still transmiting information or not). All neccessary documentation for interacting with the website environment is presented with easy  understandable examples.

The Arduino application is:

#include “Sensirion.h”
#define VERSION “1.0”

//INSIDE SHT11 SENSOR
int sht11DataPin = 8;
int sht11ClockPin = 9;
float officeTemperature = 0;
float officeHumidity = 0;
float officeDewPoint = 0;

Sensirion sht11Sensor = Sensirion(sht11DataPin, sht11ClockPin);

void setup()
{
Serial.begin(9600);
}

void loop()
{
//****************************
// INSIDE SHT11 SENSOR
//****************************
sht11Sensor.measure(&officeTemperature, &officeHumidity, &officeDewPoint);

Serial.print(‘a’);
Serial.print((int)(officeTemperature * 100), DEC);

//the delay should be at least 0.5 minutes
for(int i = 0; i < 30; i++)
delay(1000);

Serial.print(‘b’);
Serial.print((int)(officeHumidity * 100), DEC);

//the delay should be at least 0.5 minutes
for(int i = 0; i < 30; i++)
delay(1000);

Serial.print(‘c’);
Serial.print((int)(officeDewPoint * 100), DEC);

//the delay should be at least 0.5 minutes
for(int i = 0; i < 30; i++)
delay(1000);

Serial.print(‘d’); //end of telegram
}

For sending the values from Arduino board, through serial communication, to Processing environment the next telegram format have been used:

‘a’ temperature value ‘b’ relative humidity value ‘c’ dew point value ‘d’

where all values are represented on 4 bytes. On Processing each serial written character is read as the coresponding ASCII code, and a transformation to the real value had to be done.

 

… and Processing application:

/*
* Office Temperature, Relative Humidity and Dew Point monitoring
* and post the measured information on Patcube website

import eeml.*;
import processing.serial.*;

Serial serialPort;  // Create object from Serial class
int serialValue = 0;
byte parameterType = 0; // 0 – no parameter; 1 – temperature; 2 – relative humidity; 3 – dew point
int parameterValue = 0;

String mySerialPort = “your_COM_name“;
String apiKey = “your_api_key;
String feedURL = “your_feed_url“;
DataOut pachubeDataOut;

float officeTemperature = 0;
float officeHumidity = 0;
float officeDewPoint = 0;

void setup()
{
size(200, 200);
smooth();
frameRate(10);

// Open the port that the board is connected to and use the same speed (9600 bps)
serialPort = new Serial(this, mySerialPort, 9600);

// set up DataOut object; requires URL of the EEML you are updating, and your Pachube API key
pachubeDataOut = new DataOut(this, feedURL, apiKey);

//and add and tag a datastream
//pachubeDataOut.addData(0,”temperature, relative humidity, dew point”);
pachubeDataOut.addData(0, “temperature”, 0, 50);
pachubeDataOut.addData(1, “relative humidity”, 0, 100);
pachubeDataOut.addData(2, “dew point”, 0, 50);

pachubeDataOut.setUnits(0, “Celsius”, “C”, “basicSI”);
pachubeDataOut.setUnits(1, “Percent”, “%”, “basicSI”);
pachubeDataOut.setUnits(2, “Celsius”, “C”, “basicSI”);
}

void draw()
{

if (serialPort.available() > 0)
{
serialValue = serialPort.read();

//verify if it one identifier (‘a’, ‘b’, ‘c’ or ‘d’)
if(serialValue == 97) //’a’
{
SetParameterValue(parameterType, parameterValue);

parameterType = 1;
parameterValue = 0;
}
else
{
if(serialValue == 98) //’b’
{
SetParameterValue(parameterType, parameterValue);

parameterType = 2;
parameterValue = 0;
}
else
{
if(serialValue == 99) //’c’
{
SetParameterValue(parameterType, parameterValue);

parameterType = 3;
parameterValue = 0;
}
else
{
if(serialValue == 100) //’d’
{
SetParameterValue(parameterType, parameterValue);

parameterType = 0;
parameterValue = 0;
}
else
{
if(parameterType != 0)
parameterValue = parameterValue * 10 + (serialValue – 48);
}
}
}
}

}
}

void SetParameterValue(byte parameterType, int parameterValue)
{
if(parameterType == 1)
{
officeTemperature = (float)parameterValue / 100;
println(“temperature = ” + officeTemperature);

postDataOnPachube(parameterType);
}

if(parameterType == 2)
{
officeHumidity = (float)parameterValue / 100;
println(“relative humidity = ” + officeHumidity);

postDataOnPachube(parameterType);
}

if(parameterType == 3)
{
officeDewPoint = (float)parameterValue / 100;
println(“dew point = ” + officeDewPoint);

postDataOnPachube(parameterType);
}
}

void postDataOnPachube(byte parameterType)
{
println(“ready to POST: “);

if(parameterType == 1)
pachubeDataOut.update(0, officeTemperature);

if(parameterType == 2)
pachubeDataOut.update(1, officeHumidity);

if(parameterType == 3)
pachubeDataOut.update(2, officeDewPoint);

int response = pachubeDataOut.updatePachube(); // updatePachube() updates by an authenticated PUT HTTP request
println(“response from Pachube: ” + response); // should be 200 if successful; 401 if unauthorized; 404 if feed doesn’t exist
}

For using the Pachube services you need to have an account created on their website. The bolded code should be replaced with your data (serial port name, api key and feed provided using your Pachube account).

The Sensirion class, created by Markus Schatzl, have been used for communicate with the sensor.

Advertisements
  1. kiilo
    April 27, 2012 at 6:41 am

    If you want to send and receive pachube data direct with an arduino ¨ ethernet shield you may have a look here http://wiki.sgmk-ssam.ch/index.php/Kiilo-ArduinoEthernetShield-Read/Write working code samples

  2. Rutger
    February 10, 2013 at 11:54 pm

    Hi,
    I am succesfully using your code to send data of my greenhouse to Cosm. I am currently updating the code a bit, and trying to understand it. I come across the following part that doesnt make sense to me. It is however needed, because the send value becomes zero when I delete it. Could you explain why this code is needed?

    if(parameterType != 0)
    parameterValue = parameterValue * 10 + (serialValue – 48);

    • February 11, 2013 at 1:09 am

      Hi,

      thats simple, he is converting the ascii characters to a a integer value – example lets say you have a temperature of “456” the data is read as sequence of
      “4” “5” “6”
      the ascii values for this cahrachters are (ggogle for ascii table)
      52 53 54

      so lets say value is first zero value = 0

      “4” is coming in
      valaue = value * 10 + 52 – 48 = 4

      “5” is coming in
      valaue = value * 10 + 53 – 48 = 45

      “6” is coming in
      valaue = value * 10 + 54 – 48 = 456

      why 48? its the ascii code for the character “0” – so to simply convert from deciaml digit characters (“1” “2” “3” …) simply substract “0” which is 48

      • Rutger
        February 11, 2013 at 9:49 pm

        Hi Kiilo,

        Thanks, that makes the whole code much clearer to me. I am using this code to send 8 types of data to cosm. The if else if else if else coding becomes very difficult to read with so many datatypes (my program ends with 11 “}” ). Therefore I wanted to replace the if/else’s with a simple switch code.

        Thanks to your explanation, I now understand the meaning of all the if/else’s. It will become a bit more work to completely rewrite it, so I think I will leave it as it is (it works in the end :))

        regards, Rutger

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: