Current Cost Support Forum

A support forum for Current Cost users, partners and developers. Covering hardware, software and web.
Site Announcements

The support forum is moderated Monday to Friday, UK time. To submit a support ticket, please email: helpme [at] currentcost .com

It is currently Fri Oct 24, 2014 7:00 pm

All times are UTC [ DST ]




Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 15 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Raspberry Pi
PostPosted: Mon Jul 30, 2012 7:15 pm 
Offline

Joined: Tue Jul 24, 2012 8:43 pm
Posts: 12
I have a raspberry Pi anyone got one running with a current cost yet to upload data instead of the bridge.

Bogget


Top
 Profile  
 
 Post subject: Re: Raspberry Pi
PostPosted: Mon Aug 06, 2012 9:58 am 
Offline

Joined: Mon Aug 06, 2012 9:13 am
Posts: 2
Location: Portugal
Hi Bogget,

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

I got some ideas from this blog: http://www.jibble.org/currentcost/
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:
Code:
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:
Code:
sudo chmod 666 /dev/ttyUSB0


After that, everything ran fine.
I'm sending my final script attached, and you can see my feed at: https://cosm.com/feeds/56652
(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.

Regards,

GHubsch


Attachments:
envi.zip [730 Bytes]
Downloaded 701 times
Top
 Profile  
 
 Post subject: Re: Raspberry Pi
PostPosted: Tue Aug 07, 2012 8:30 am 
Offline
User avatar

Joined: Tue May 31, 2011 9:24 pm
Posts: 38
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 jibble.org (+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 https://cosm.com/feeds/12483

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

_________________
(º•.¸(¨*•.¸ ¸.•*¨)¸.•º)
<<<.•°•. NIK .•°•.>>>
(¸.•º(¸.•¨* *¨•.¸)º•.¸)


Top
 Profile  
 
 Post subject: Re: Raspberry Pi
PostPosted: Tue Aug 07, 2012 9:03 am 
Offline

Joined: Mon Aug 06, 2012 9:13 am
Posts: 2
Location: Portugal
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 Cosm.com (cpu load, free memory, net in/out traffic, etc.)
https://cosm.com/feeds/69589
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 script.pl &
(add an '&' after the command, to execute it in the background)
Hope this helps with your problem.

Regards,

GHubsch


Top
 Profile  
 
 Post subject: Re: Raspberry Pi
PostPosted: Thu Aug 09, 2012 9:03 am 
Offline

Joined: Tue Aug 16, 2011 7:59 pm
Posts: 71
Hi Nik - I'd like to see your script please.
Tia


Top
 Profile  
 
 Post subject: Re: Raspberry Pi
PostPosted: Mon Aug 13, 2012 11:39 am 
Offline

Joined: Sun Aug 12, 2012 8:13 pm
Posts: 2
ghubsch wrote:
I'm sending my final script attached, and you can see my feed at: https://cosm.com/feeds/56652
(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:

Quote:
Global symbol "$response" requires explicit package name at ./envi.pl line 40.
Execution of ./envi.pl 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:

Code:
my $response = `$wget`;


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

Code:
su -c "./home/pi/envi.pl start --quiet" pi &


Seems to be working fine after a reboot :)

Thanks again


Last edited by nommo on Sun Aug 19, 2012 4:17 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Raspberry Pi
PostPosted: Mon Aug 13, 2012 4:11 pm 
Offline
User avatar

Joined: Tue May 31, 2011 9:24 pm
Posts: 38
here you go

Code:
#!/usr/bin/perl

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);
$ob->baudrate(57600);
$ob->write_settings;

open(SERIAL, "+>$PORT");
while (my $line = <SERIAL>) {
   if ($line =~ m!<tmpr>([\-\d.]+).*<watts>0*(\d+)</watts>!) {
      my $watts = $2;
      my $temp = $1;
      $rrd->update(power=>$watts,temperature=>$temp);
      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";
      close(mypower);
      $num++;
      $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 RRDs.pm 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

Code:
#!/usr/bin/perl

open(PS,"/bin/ps x|") || die "Cant open PS";
while (<PS>)   {
#print $_;
   if ($_ = m/envimonit.pl/ ) {
      close PS;
#      print localtime() . "--->";
#             print "Envimonit running\n";
      open(suclog,'>>/var/www/cc/runenvi.html');
                print suclog localtime() . "--->";
                print suclog "Envimonit running<br />\n";
      close(suclog);
       exit;}
      }
close PS;
open(failog,'>>/var/www/cc/stopenvi.html');
print failog localtime() . "--->";
print failog "Envimonit not found - tryng to restart<br />\n";
close(failog);

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


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

_________________
(º•.¸(¨*•.¸ ¸.•*¨)¸.•º)
<<<.•°•. NIK .•°•.>>>
(¸.•º(¸.•¨* *¨•.¸)º•.¸)


Top
 Profile  
 
 Post subject: Re: Raspberry Pi
PostPosted: Thu Sep 06, 2012 11:30 am 
Offline

Joined: Sun Aug 12, 2012 8:13 pm
Posts: 2
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

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


Top
 Profile  
 
 Post subject: Re: Raspberry Pi
PostPosted: Thu Sep 20, 2012 6:00 pm 
Offline

Joined: Tue Jul 24, 2012 8:43 pm
Posts: 12
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?

Bogget


Top
 Profile  
 
 Post subject: Re: Raspberry Pi
PostPosted: Sun May 05, 2013 9:09 pm 
Offline

Joined: Tue Jul 24, 2012 8:43 pm
Posts: 12
Is anyone still using this , ....is it stable

any more developments?


I would love to hear of progress.

Bogget


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 15 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group