User avatar
some_evil
Posts: 205
Joined: Thu Dec 18, 2014 3:16 am
Location: Albury, Australia

Off-Net Temperature Graphing

Wed Mar 18, 2015 10:22 pm

hi Guys,

I have a '1 wire thermometer' setup with 3 thermometers logging data from different rooms in my house back to the pi. Currently the output is just taking a reading every 5mins and entering this into a CSV something like:
Therm1, Therm2, Therm3, Date Time
24.235, 22.001, 23.123, 2015-03-19 05:23:45
24.245, 22.111, 23.121, 2015-03-19 05:28:47
etc....

I am wondering if anyone knows of a tutorial I should google to setup an automatic graph that I can read from time to time to make use of all this data I am collecting?

When I google this issue I get dozens of results of tutorials on how to upload this to google docs and create graphs online etc, but as this Pi is offline I need the pi to do all my work.

Has anyone had a similar experience they could point me to?

Thanks for reading.
PiZeroW - May 2017
Pi 3 - Oct 2016
PiZero - June 2016
Pi 2 - Jan 2016
Pi B+ - Dec 25 2014

User avatar
some_evil
Posts: 205
Joined: Thu Dec 18, 2014 3:16 am
Location: Albury, Australia

Re: Off-Net Temperature Graphing

Wed Mar 18, 2015 10:29 pm

Sorry I should have mentioned I have read about mathplotlib and it seems a little advanced in comparison to gnuplot.

Is this other peoples opinions? I would like to make it as simple as possible as I am still new to all this.
PiZeroW - May 2017
Pi 3 - Oct 2016
PiZero - June 2016
Pi 2 - Jan 2016
Pi B+ - Dec 25 2014

User avatar
DougieLawson
Posts: 36158
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Off-Net Temperature Graphing

Wed Mar 18, 2015 10:39 pm

http://plot.ly is the thing I'm using.

I've got temp/air pressure data coming from an i2c bmp180 sensor. I store that in an sqlite database then every twelve minutes I push that data to plotly.

Their python API is sane and simple.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
some_evil
Posts: 205
Joined: Thu Dec 18, 2014 3:16 am
Location: Albury, Australia

Re: Off-Net Temperature Graphing

Wed Mar 18, 2015 10:50 pm

DougieLawson wrote:http://plot.ly is the thing I'm using.
After a 2min glance, it appears to be a web based setup, can this be setup stand-alone on my Pi? Or will it need internet access for this to work?
PiZeroW - May 2017
Pi 3 - Oct 2016
PiZero - June 2016
Pi 2 - Jan 2016
Pi B+ - Dec 25 2014

User avatar
DougieLawson
Posts: 36158
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Off-Net Temperature Graphing

Wed Mar 18, 2015 11:59 pm

some_evil wrote:
DougieLawson wrote:http://plot.ly is the thing I'm using.
After a 2min glance, it appears to be a web based setup, can this be setup stand-alone on my Pi? Or will it need internet access for this to work?
Needs internet access. There's no offline option for plotly.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: Korea

Re: Off-Net Temperature Graphing

Thu Mar 19, 2015 12:09 am

I use ploticus. You can run it locally and it can produce a png image file of the graph. You can do what you like with the image, such as view it locally, or let a webserver serve it up, or ftp it somewhere else for viewing.

The syntax is a little tricky, but the results are nice.

danjperron
Posts: 3402
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Off-Net Temperature Graphing

Thu Mar 19, 2015 2:40 am

I'm using rrdtool and high chart.


It is not on the internet but use your local network to display the chart.

Localhost mode , 127.0.0.1, will work.

I put a step by step instruction using a DHT11 sensor. But later in the post I put code for the DS18B20.

Code: Select all

http://www.raspberrypi.org/forums/viewtopic.php?p=672453#p672453

Daniel

prairietech
Posts: 28
Joined: Wed Mar 20, 2013 9:22 pm

Re: Off-Net Temperature Graphing

Thu Mar 19, 2015 2:46 am

I've been using xively for years which is web based. But like you, wanted something confined to my local network.

I found this on-line book and it appears to be what I am looking for. Maybe it will work for you?

https://leanpub.com/RPiMRE

User avatar
Greg Erskine
Posts: 115
Joined: Sat Sep 15, 2012 4:20 am

Re: Off-Net Temperature Graphing

Thu Mar 19, 2015 5:04 am

some_evil wrote:hi Guys,

I have a '1 wire thermometer' setup with 3 thermometers logging data from different rooms in my house back to the pi. Currently the output is just taking a reading every 5mins and entering this into a CSV something like:
Therm1, Therm2, Therm3, Date Time
24.235, 22.001, 23.123, 2015-03-19 05:23:45
24.245, 22.111, 23.121, 2015-03-19 05:28:47
etc....

I am wondering if anyone knows of a tutorial I should google to setup an automatic graph that I can read from time to time to make use of all this data I am collecting?

When I google this issue I get dozens of results of tutorials on how to upload this to google docs and create graphs online etc, but as this Pi is offline I need the pi to do all my work.

Has anyone had a similar experience they could point me to?

Thanks for reading.
hi some_evil,

An alternative approach is to use scripting to generate a svg formatted graph. Doesn't require any additional tools but does require a bit of scripting skills. I chose to use standard shell, but you could use bash, python, perl, .... whatever.

regards
Greg
* Raspberry Pi is a trademark of the Raspberry Pi Foundation

User avatar
SteveDee
Posts: 343
Joined: Thu Dec 29, 2011 2:18 pm
Location: Sunny Southern England
Contact: Website

Re: Off-Net Temperature Graphing

Thu Mar 19, 2015 9:12 pm

some_evil wrote:...I have a '1 wire thermometer' setup with 3 thermometers logging data from different rooms in my house back to the pi. Currently the output is just taking a reading every 5mins and entering this into a CSV ...
Do you want to write some code to do this?

I have a similar setup (3 x DS18B20 to a csv file) and use some simple PHP code to plot temperatures for the last 5 days.
Temp21Jan15.png
Temp21Jan15.png (20.01 KiB) Viewed 3930 times
This graph can be viewed on a local web browser.

To get an idea how simple this is, see my notes on creating images: http://captainbodgit.blogspot.co.uk/201 ... rrypi.html

User avatar
some_evil
Posts: 205
Joined: Thu Dec 18, 2014 3:16 am
Location: Albury, Australia

Re: Off-Net Temperature Graphing

Fri Mar 20, 2015 4:50 am

great ideas everyone, you have now filled my weekend with Pi related tasks :) Looking forward to getting a result.

Cheers
PiZeroW - May 2017
Pi 3 - Oct 2016
PiZero - June 2016
Pi 2 - Jan 2016
Pi B+ - Dec 25 2014

User avatar
some_evil
Posts: 205
Joined: Thu Dec 18, 2014 3:16 am
Location: Albury, Australia

Re: Off-Net Temperature Graphing

Tue Mar 31, 2015 12:41 am

SteveDee wrote:
some_evil wrote:...I have a '1 wire thermometer' setup with 3 thermometers logging data from different rooms in my house back to the pi. Currently the output is just taking a reading every 5mins and entering this into a CSV ...
Do you want to write some code to do this?
Hi Steve,

I already have a py script that logs the temperature automatically to the CSV, I am now trying to setup a simple graph that I can view to see temp changes between rooms.

I haven't had much time to try anything on my Pi, but I have been researching the suggestions from this thread.

Cheers
PiZeroW - May 2017
Pi 3 - Oct 2016
PiZero - June 2016
Pi 2 - Jan 2016
Pi B+ - Dec 25 2014

User avatar
SteveDee
Posts: 343
Joined: Thu Dec 29, 2011 2:18 pm
Location: Sunny Southern England
Contact: Website

Re: Off-Net Temperature Graphing

Thu Apr 09, 2015 5:53 pm

some_evil wrote:I have a quick question, I am currently logging data to a sqlite3 database readings from all 6 sensors connected to my pi, I am hoping you can confirm that the examples you have provided will be able to handle more than one data line at a time. Eg. can all 6 sensors be plotted over the top of one another for readability? It looks as though this is possible, I just can not see an explicit example in your blogs of this in you graph example....
Sorry, I've posted your PM question here because if it turns out to be useful to you, it may be of interest to others.

Yes, you can plot several data series at the same time, as you are just working with a basic drawing area. If you draw crossing lines (as shown in my blog) the second line will not rub out the first. However, if you draw a second line with the same coordinates as the first line, it will cover the first line.

My code for the 4 series plot shown above is very ugly, as I'm not a PHP Fundi. But if you scrape the code off the page and put it into an editor like gEdit (which uses colour coded syntax) it may look a little ctearer and be some help.

Code: Select all

<?php
# Read temperatures from file & display each
# series on a simple chart
# SteveDee
# Nov 2014
#===========================================

# create chart area
$Image = imagecreate( 1050, 550 );
#1st colour allocated is used for the image background
$backColour = imagecolorallocate( $Image, 255, 255, 150 );

#line/text colours
$colRed = imagecolorallocate( $Image, 250, 0, 0 );
$colGreen = imagecolorallocate( $Image, 0, 100, 0 );
$colBlue = imagecolorallocate( $Image, 0, 0, 250 );
$colPurple = imagecolorallocate( $Image, 100, 0, 100 );
$colBlueDark = imagecolorallocate( $Image, 0, 0, 150 );
$colGreyDark = imagecolorallocate( $Image, 50, 50, 50 );
$colGreyLight = imagecolorallocate( $Image, 200, 200, 200 );

$yPoint = 25;		# offset y
$xPoint = 40;		# offset x
$xinterval = 2;		# plot point spacing
$readings = 480;	# Data readings every 15mins x 24hrs x 5days = 480 points
$DayReadings = 96;	# readings per day
$yScaler = 500/30;	# scale y over 30'C

# draw x & y axis
imageline( $Image, $xPoint, 500, 1000, 500, $colGreyDark);
imageline( $Image, $xPoint, 500, $xPoint, $yPoint, $colGreyDark);

# gridlines: y
# y scale baseline is -5'C, but plots on the image area from top downwards
#$deg25 = $yScaler * 0;		# the 25'C y-gridline would be at the top of the drawing area
$deg20 = $yScaler * 5;		
$deg15 = $yScaler * 10;		
$deg10 = $yScaler * 15;	
$deg5 = $yScaler * 20;		
$deg0 = $yScaler * 25;		#the 0'C gridline is 5/6th down the drawing area

imageline( $Image, $xPoint, $deg0, 1000, $deg0, $colGreyLight );
imageline( $Image, $xPoint, $deg5, 1000, $deg5, $colGreyLight );
imageline( $Image, $xPoint, $deg10, 1000, $deg10, $colGreyLight );
imageline( $Image, $xPoint, $deg15, 1000, $deg15, $colGreyLight );
imageline( $Image, $xPoint, $deg20, 1000, $deg20, $colGreyLight );

# gridelines: x
$xDay1 = $xPoint + ($xinterval * $DayReadings * 1);
$xDay2 = $xPoint + ($xinterval * $DayReadings * 2);
$xDay3 = $xPoint + ($xinterval * $DayReadings * 3);
$xDay4 = $xPoint + ($xinterval * $DayReadings * 4);
imageline( $Image, $xDay1, 500, $xDay1, 25, $colGreyLight );
imageline( $Image, $xDay2, 500, $xDay2, 50, $colGreyLight );
imageline( $Image, $xDay3, 500, $xDay3, 50, $colGreyLight );
imageline( $Image, $xDay4, 500, $xDay4, 25, $colGreyLight );

# chart text
imagestring( $Image, 5, 400, 25, "PiStat Temperature Monitor", $colGreyDark);
imagestring( $Image, 4, 500, 510, "days", $colBlueDark);
imagestring( $Image, 4, 950, 510, "5 days ago", $colBlueDark);
#imagestring( $Image, 3, 10, 5, "30'C", $colBlue);
imagestring( $Image, 4, 5, 80, "20'C", $colBlueDark);
imagestring( $Image, 4, 5, 163, "15'C", $colBlueDark);
imagestring( $Image, 4, 5, 246, "10'C", $colBlueDark);
imagestring( $Image, 4, 5, 329, "5'C", $colBlueDark);
imagestring( $Image, 4, 5, 412, "0'C", $colBlueDark);
imagestring( $Image, 4, 820, 18, "KEY:-", $colGreyDark);
imagestring( $Image, 4, 820, 35, "lounge: upper sensor", $colRed);
imagestring( $Image, 4, 820, 50, "lounge: lower sensor", $colGreen);
imagestring( $Image, 4, 820, 65, "lounge: under floor", $colBlue);
imagestring( $Image, 4, 820, 82, "Horsham temperature", $colPurple);

# Get temperature readings
$file = file_get_contents('/var/www/data/latestTemps.csv');
# Extract data
$marker = strpos($file, ',');
$timestamp = substr( $file, 0, $marker);
#change timestamp format from hh:mm:ss to hh:mm
$timestamp = substr($timestamp, 0, strrpos($timestamp, ':'));
imagestring( $Image, 4, 20, 510, $timestamp, $colBlueDark);
$file = substr($file, $marker + 1);
$marker = strpos($file, ',');
$temp1p1 = substr( $file, 0, $marker);
# Reverse y-axis
$temp1p1 = 500 - (($temp1p1 + 5) * $yScaler);
$file = substr($file, $marker + 1);
$marker = strpos($file, ',');
$temp2p1 = substr( $file, 0, $marker);
$temp2p1 = 500 - (($temp2p1 + 5) * $yScaler);
$file = substr($file, $marker + 1);
$marker = strpos($file, ',');
$temp3p1 = substr( $file, 0, $marker);
$temp3p1 = 500 - (($temp3p1 + 5) * $yScaler);

$file = substr($file, $marker + 1);
$marker = strpos($file, "\r");
$temp4p1 = substr( $file, 0, $marker);
$temp4p1 = 500 - (($temp4p1 + 5) * $yScaler);
$file = substr($file, $marker + 1);

# Draw lines between adjacent data points (p1 & p2)
for ( $i = 1; $i <= $readings; $i++ ) {
	$xPoint = $xPoint + $xinterval;
	#extract data
	$marker = strpos($file, ',');
	$timestamp = substr( $file, $marker);
	$file = substr($file, $marker + 1);
	$marker = strpos($file, ',');
	$temp1p2 = substr( $file, 0, $marker);
	$temp1p2 = 500 - (($temp1p2 + 5) * $yScaler); 
	
	$file = substr($file, $marker + 1);
	$marker = strpos($file, ',');
	$temp2p2 = substr( $file, 0, $marker);
	$temp2p2 = 500 - (($temp2p2 + 5) * $yScaler);  

	$file = substr($file, $marker + 1);
	$marker = strpos($file, ',');
	$temp3p2 = substr( $file, 0, $marker);
	$temp3p2 = 500 - (($temp3p2 + 5) * $yScaler);  

	$file = substr($file, $marker + 1);
	$marker = strpos($file, "\r");
	$temp4p2 = substr( $file, 0, $marker);
	$temp4p2 = 500 - (($temp4p2 + 5) * $yScaler); 
	$file = substr($file, $marker + 1);

	# Draw a line for each data pair, for each of 3 sensors (temp1, 2 & 3) & local temp (4)
	imageline( $Image, $xPoint, $temp1p1, ($xPoint + $xinterval), $temp1p2, $colBlue );
	imageline( $Image, $xPoint, $temp2p1, ($xPoint + $xinterval), $temp2p2, $colGreen );
	imageline( $Image, $xPoint, $temp3p1, ($xPoint + $xinterval), $temp3p2, $colRed );
	imageline( $Image, $xPoint, $temp4p1, ($xPoint + $xinterval), $temp4p2, $colPurple );	
	# copy p2 back to p1 ready for next line
	$temp1p1 = $temp1p2;
	$temp2p1 = $temp2p2;
	$temp3p1 = $temp3p2;
	$temp4p1 = $temp4p2;
}

header( "Content-type: image/png" );
imagepng( $Image );
imagedestroy( $Image );
?>

One of the things that makes it so ugly is that the drawing area co-ords start at 0,0 top-left. So lines like:-

Code: Select all

$temp1p1 = 500 - (($temp1p1 + 5) * $yScaler);
...are attempting to reverse the Y axis.

I hope this helps.

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: Korea

Re: Off-Net Temperature Graphing

Fri Apr 10, 2015 12:33 pm

ploticus is much easier than that.

Return to “Automation, sensing and robotics”