03.06
Behold the graphy goodness…
I have wanted to, for a long time, display, graph, and control various aspects of the home environment. Temperatures, status of appliances, lights, water heater, furnace, and so on. Looks like this is finally becoming a reality.
Inspired by the work done at the OpenEnergyMonitor site, I adapted their code to make the above realtime graph of temperature. I will add more as inspiration hits.
But the steps were basically this.
ARDUINO TEMPERATURE MONITOR:
A very simple Arduino temperature monitor and data reporter was constructed with a Duemilanove, Ethernet Shield and a Modern Circuits TMP-421 temperature sensor. The code is very simple, with no error detection or correction (for now) {sensitive bits redacted}.
#include “Wire.h”
#include <LibTemperature.h>
#include <Ethernet.h>//Sets the unique mac address for the ethernet board
byte mac[] = {0xDE,0xAD,0xBE,0xEF,0xFE,0xED};
byte ip[] = {192,168,2,51};
byte gateway[] = {192,168,2,1};
byte server[] = {—,—,—,—};//Setup a client
Client client(server, 80);LibTemperature temp = LibTemperature(0);
void setup()
{
Serial.begin(9600);Ethernet.begin(mac, ip, gateway);
delay(1000);
}void loop()
{
Serial.print(“Temp: “);
Serial.print(temp.GetTemperature());
Serial.println(” degC”);
delay(100);//Send the data
if (client.connect())
{//Accessing a shared server requires the server domain name in here as there
//is no fixed ip address. If your accessing a shared server you need to add
//your URL “GET http://—–.—/xxxxxxx/????.pl?T=”client.print(“GET http://—–.—/xxxxxxx/????.pl?T=”);
client.print(temp.GetTemperature());
client.println();
client.stop();
}
else
{
Serial.println(“Failed to connect to client”);
}
delay(10000);
}
PERL SCRIPT ON MY SERVER:
A rather simple perl script was added to my server. This was rather tough as my server did not allow cgi-bin script execution out of the box. I won’t go into what it took to get working, as your mileage will vary (sensitive bits have been redacted). I’ll be spending some time with my perl book and construct an all encompasing, scalable, script that will allow me to write to any database table and field, at any time. For now things are hard coded.
#!/usr/bin/perl -w
use CGI::Carp qw( fatalsToBrowser );# PERL MODULES WE WILL BE USING
use Data::Dumper;
use CGI qw/:standard/;use DBI;
use DBD::mysql;# HTTP HEADER
print “Content-type: text/html \n\n”;
print header;my $currentvalue = param(‘T’) or die “Value1 not in parameter list”;
# CONFIG VARIABLES
$platform = “mysql”;
$database = “home_monitor”;
$host = “localhost”;
$port = “—-”;
$tablename = “DATA”;
$user = “—-_———–”;
$pw = “—-_———–”;# DATA SOURCE NAME
$dsn = “dbi:$platform:$database:$host:$port”;# PERL DBI CONNECT
$connect = DBI->connect($dsn, $user, $pw) or die “Unable to connect: $DBI::errstr\n”;$vtime = time()*1000;
# PREPARE THE QUERY
$query = “INSERT INTO DATA (TEMP_001, Time) VALUES ($currentvalue,$vtime)”;
$query_handle = $connect->prepare($query);# EXECUTE THE QUERY
$query_handle->execute();
And finally, a PHP script to access the database and graph the results. The graphic package in use is Flot, a very slick open source, MIT Licensed, library perfect for what we need to do.
Flot is a pure Javascript plotting library for jQuery. It produces graphical plots of arbitrary datasets on-the-fly client-side.
The focus is on simple usage (all settings are optional), attractive looks and interactive features like zooming and mouse tracking.
The plugin works with Internet Explorer 6/7/8, Firefox 2.x+, Safari 3.0+, Opera 9.5+ and Konqueror 4.x+ with the HTML canvas tag (the excanvas Javascript emulation helper is used for IE).
So, there you have it… I will be adding things in the days to come, trying different configurations, fixing up the perl script and tidying up the graphics. I will couple this with the Jeenodes as outlined earlier, and adding the graphing functionality to whatever platform I use to aggregate the Jeenode data. The possibilities are endless.
Share on Facebook
[...] finally, I simply made another copy of my flot php script to display the temperature data in a browser. Share on Facebook var button = [...]