Current Cost Support Forum

Raspberry Pi
Page 1 of 2

Author:  Bogget [ Mon Jul 30, 2012 7:15 pm ]
Post subject:  Raspberry Pi

I have a raspberry Pi anyone got one running with a current cost yet to upload data instead of the bridge.


Author:  ghubsch [ Mon Aug 06, 2012 9:58 am ]
Post subject:  Re: Raspberry Pi

Hi Bogget,

I have already managed to put my Raspberry Pi to work, uploading data from an EnviR to (pachube), via a perl script.

I got some ideas from this blog:
Initially, I had some problems to install Device::SerialPort perl module, and I ended up compiling it manually, but I think you can install it easily via apt-get, but I discovered that just after managed to install manually. I think the command should be:
sudo apt-get install libdevice-serialport-perl

The Envi USB to serial cable is automatically recognized by the Raspberry, but, I had a problem with the script returning a "Permission Denied" on the serial port (/dev/ttyUSB0), so, I had to execute:
sudo chmod 666 /dev/ttyUSB0

After that, everything ran fine.
I'm sending my final script attached, and you can see my feed at:
(I just started uploading with the Raspberry from yesterday, 9PM)
As the Envi sends readings every 6 seconds, I decided to make an average from 10 readings, and send the average value to Cosm, so, I'm sending data every minute or so.
Don't forget to change the script, and put your API-Key, and your Feed ID.

Hope you manage to make it work too.



Attachments: [730 Bytes]
Downloaded 1572 times

Author:  galaxynik [ Tue Aug 07, 2012 8:30 am ]
Post subject:  Re: Raspberry Pi

Just spent a few days getting this working on my Pi :D
I am using it primarily as a media server - PI + WD 2Tb usb disc - uses 3w when disc spun down and about 10w when active low enought to leave on 24/7

I'm a complete Linux noob so its taken me a while to sort this - have a slightly different approach to ghubsch but like him I got the basic script from (+credit)

My Pi is running squeezeplug (based on debian wheezy IIRC)
This is a headless setup and so I ssh in using putty
Minidlna (serving videos mainly for the 3 kids tablets - using bubbleupnp + vplayer and their computers - using VLC)
Apach2 + PHP5

I use a perl script to read the device and save the data to a RRD (round robin database) every 5 secs or so (total file size for 10 years data ~ about 1.5Mb ;), the script also writes a little html file with the current power and temp to the webserver so I can check its running (changes every 5 secs).
I have some cron jobs creating png graphs on the server (10min.3hr,6hr,12hr,daily) every minute or so.
The data is also sent to cosm using the Net::Pachube module although its a lot less trouble using the wget method :D (Net::Pachube was a pig to install for a noob with loads of dependencies that neeeds manually installing - even though I had cpanminus installed)

Was interested to notice that once the data flowed to cosm it started appearing in the currentcost dashboard again, noit sure whether sending the data to cosm every 5 sec is going to work long term but I will see

can post script if you are interested

I am having a few issues keeping the script running in the background - sometimes when I terminate the putty session it decides to end - still investigating that

Author:  ghubsch [ Tue Aug 07, 2012 9:03 am ]
Post subject:  Re: Raspberry Pi

Hi Galaxynik,

I have also added to my script an update to a RRD database, but, I'm not generating graphs yet.
I was thinking about to create a PHP web page to generate graphs on demand (just when I access the web page), because I thought that generating graphs frequently via a cron job would make an unnecessary load on the Raspberry. Do you notice the load of generating the graphs ?

I'm running raspbian, also with a webserver (lighttpd, mysql and PHP), headless, to serve basically as my web server for my photoblog (as photography is my 'other' hobby!), and for currentcost.

I have also a shell script to upload system information to (cpu load, free memory, net in/out traffic, etc.)
I can post the script also if anyone is interested. I'm running it from a crontab, just every 5 min (i think is enough!)

As for running the perl script on the background, even after closing the putty session, i just use:
> perl &
(add an '&' after the command, to execute it in the background)
Hope this helps with your problem.



Author:  Andygodber [ Thu Aug 09, 2012 9:03 am ]
Post subject:  Re: Raspberry Pi

Hi Nik - I'd like to see your script please.

Author:  nommo [ Mon Aug 13, 2012 11:39 am ]
Post subject:  Re: Raspberry Pi

ghubsch wrote:
I'm sending my final script attached, and you can see my feed at:
(I just started uploading with the Raspberry from yesterday, 9PM)

Thank you for posting this! I managed to get it working yesterday - but at first I was getting an error:

Global symbol "$response" requires explicit package name at ./ line 40.
Execution of ./ aborted due to compilation errors.

I posted on a thread over on RasberryPi forums about CurrentCost Envi-> Cosm thinking that someone might be able to help me troubleshoot the error (in light of the fact that I saw a message about new members being moderated during working hours I didn't think it would be worth trying here!), but as it happens I managed to suss it out myself (took me a while to get there - I can program as well as I can fly!) :)

You need to add 'my' to the beginning of line 40:

my $response = `$wget`;

I then added it to /etc/rc.local so that it would run at startup:

su -c "./home/pi/ start --quiet" pi &

Seems to be working fine after a reboot :)

Thanks again

Author:  galaxynik [ Mon Aug 13, 2012 4:11 pm ]
Post subject:  Re: Raspberry Pi

here you go


use strict;
use lib '/usr/lib/perl5/Device';
use RRD::Simple ();
use Device::SerialPort qw(:PARAM :STAT 0.07);
use Net::Pachube ;

my $APIkey ="**********************************************";
my $devid="12483";
my $pachube = Net::Pachube->new( key=>$APIkey);
my $feed=$pachube->feed($devid);
my $rrd = RRD::Simple->new( file => "/home/cc/powertemp.rrd" );
my $PORT = "/dev/ttyUSB0";
my $sumW = 0;
my $sumT = 0;
my $num = 0 ;
my $cosW = 0;
my $cosT = 0;

my $ob = Device::SerialPort->new($PORT);

open(SERIAL, "+>$PORT");
while (my $line = <SERIAL>) {
   if ($line =~ m!<tmpr>([\-\d.]+).*<watts>0*(\d+)</watts>!) {
      my $watts = $2;
      my $temp = $1;
      my $t = localtime();
      open (mypower,'>/var/www/cc/lasteng.html');
      print mypower "<!DOCTYPE html>\n";
      print mypower "<html>\n";
      print mypower "<body>\n";
      print mypower "<h1>Last Power reading $2 watts</h1\n>";
                print mypower "<h1>Temperature  $1 degrees</h1\n\n>";
      print mypower "Sent Cosm $cosW W - $cosT -- $num<br \>\n ";
      print mypower $t . " \n";
      print mypower "</body>\n";
      print mypower "</html>\n";
      $sumW += $watts;
      $sumT += $temp;
      if ($num >= 72) {# send reading to cosm
         $cosW = int(($sumW/72)+0.5);
         $cosT = int($sumT/72*10)/10;
         $feed->update(data => [$cosT,$cosW]) ;
         $num = $sumT = $sumW = 0 ;

slightly modified so that the current cost dashboard doesnt gag on the amount of data - now posts to cosm every 6 mins - RR databases still store data every 5 secs

Found the issue with the script stopping - RRD::Simple sometimes throws a fatal error - may upgrade and use instaed which doesnt throw a fatal error. For the time being I have a script which checks to see if the monitor script is running, if its not it restarts it - run as a cron job every 5 mins - if the server reboots then it automatically restarts the monitor


open(PS,"/bin/ps x|") || die "Cant open PS";
while (<PS>)   {
#print $_;
   if ($_ = m/ ) {
      close PS;
#      print localtime() . "--->";
#             print "Envimonit running\n";
                print suclog localtime() . "--->";
                print suclog "Envimonit running<br />\n";
close PS;
print failog localtime() . "--->";
print failog "Envimonit not found - tryng to restart<br />\n";

#print localtime() . "--->";
#print "Envimonit not found - tryng to restart\n";
system("/home/cc/ &");

it writs to 2 log files (on the appach2 server also running on the PI) so I know how often it needs restarting - and can check via the internet

Author:  nommo [ Thu Sep 06, 2012 11:30 am ]
Post subject:  Re: Raspberry Pi

Hiya - just an update regarding running scripts in the background...

I noticed that even with --quiet and an ampersand - I still had the wget notifications appearing on my tellybox. I consulted someone who knows their way around command line and he suggested adding the following to /etc/rc.local

su -c "./home/pi/ start --quiet" pi >/dev/null 2>&1 &

Author:  Bogget [ Thu Sep 20, 2012 6:00 pm ]
Post subject:  Re: Raspberry Pi

Wow, you have made great progress, maybe it can be packed as a download ready to go on a formatted SD card with OS as my programming is very very rusty.

It would be nice to just have the Pi as a stand alone unit as they are cheap enough (cheaper than the bridge) so is the Pi stable doing this?

I actually have a weather station as well wonder if it would support this as well, my weather station uploads every min to the site?


Author:  Bogget [ Sun May 05, 2013 9:09 pm ]
Post subject:  Re: Raspberry Pi

Is anyone still using this , it stable

any more developments?

I would love to hear of progress.


Page 1 of 2 All times are UTC [ DST ]
Powered by phpBB® Forum Software © phpBB Group