Archive

Posts Tagged ‘temperature’

Indoor environment parameters on Pachube

June 20, 2011 4 comments

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