Post EMONCMS value to PVOUTPUT

Hi all, I had a bit of a play around with some PHP yesterday and came up with a very basic script that reads to current value from EMONCMS and uploads it to your PVOUTPUT system. I just run it using cron on my NAS every 5 minutes. I tried to run it from my shared hosting but they have blocked shell_exec and I ended up going crosseyed trying to get curl to do the same thing. Even thought the values aren't averaged over the 5 minute period the results are very similar between Emoncms and PVOutput. 

Just add the info as required and give it a go. Please note that this doens't include any error checking or debugging. It's my first attempt :)

My system is here http://www.pvoutput.org/intraday.jsp?id=12278&sid=10211

https://www.dropbox.com/s/s8qvbqkhi3g3ko9/pvoutput_total_power_public.php

If anybody can help with an alternative to shell_exec it would be greatly appreciated.

Bill Thomson's picture

Re: Post EMONCMS value to PVOUTPUT

Hi Nerdy,

Here's what I use. It's a rework of a script originally written by forum member nothing clever.

The rewrite was done by ngbod. Although I didn't modify my rc.local startup script, it works as it's supposed to. (for me anyway) It's a modified raspberrypi_run.php file, and is a drop-in replacement.

The file is in the thread here: http://openenergymonitor.org/emon/node/2293

Search for:

raspberrypi_run.php_.txt

(that's how it's named in the post)

 

regards,

Bill

ngbod's picture

Re: Post EMONCMS value to PVOUTPUT

Nerdy, thanks for posting this.

I think your way of uploading to pvoutput will be preferable to the way I have been doing it as it doesn't mess with core emoncms files like raspberry_run.php.  

Your way should survive a major update to emoncms or at least be trivial to add back in after an update.

Maybe this could be added as an emoncms "Module"?

 

Bill Thomson's picture

Re: Post EMONCMS value to PVOUTPUT

Nerdy,

Gave your script a go, and it worked OK for me with the 'exec' call (instead of shell_exec).

The only other thing I did was use the -s switch with curl.

-s (silent mode) keeps it from sending any output to the console.

Definitely agree with ngbod though, it'll be a lot easier to re-implement after an upgrade.

 

EDIT:

I added

if ($tpower < 20)

  exit;

to stop the script from sending data when PV output falls below 20 Watts.

nerdy's picture

Re: Post EMONCMS value to PVOUTPUT

Excellent, glad people find it at least a little useful. Mine has been running great. The module sounds like a great idea. 

I will try replace shell_exec with exec Bill and give it a go on my shared hosting instead of my NAS. 

I was just browsing through some of the posts on this forum and was wondering if I could incorporate Trystan's post here to try and get 5 min averages send instead of instantaneous values.

http://openenergymonitor.org/emon/node/3666

Is this achievable?

ngbod's picture

Re: Post EMONCMS value to PVOUTPUT

Nerdy, I have edited your script to add in other feeds to send to pvoutput as well. I've been using this script for the last couple of days and it seems to be working well so far.

With regards to averaging, I am now sending Wh/d energy generated figures to pvoutput V1 feed. This way V1uses an averaged emoncms feed value instead of allowing pvoutput to calculate the daily energy generated from the 5 minute spot power feed.  

IMO as long as the daily energy generated is accurately derived, then the 5 minute spot power figures are more than good enough to  depict the power graphically.

Bill Thomson's picture

Re: Post EMONCMS value to PVOUTPUT

I modified ngbod's pvoutput upload script by replacing the exec(curl...) line with the code snippet below.

This shortens the line and simplifies the quoting. Additional variables, e.g. temperature are easily added by including them in the CURLOPT_POSTFIELDS string.

$ch = curl_init();// curl handle
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // same as -s (silent) option
curl_setopt($ch, CURLOPT_URL, 'http://pvoutput.org/service/r2/addstatus.jsp');
curl_setopt($ch, CURLOPT_POSTFIELDS, "d=$date&t=$time&v2=$GENERATED&v4=$CONSUMPTION&v6=$VOLTAGE");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Pvoutput-Apikey:$pvo_api","X-Pvoutput-SystemId:$pvo_sysid"));
curl_setopt($ch, CURLOPT_POST, 1);
curl_exec  ($ch);
curl_close ($ch);

normosb's picture

Re: Post EMONCMS value to PVOUTPUT

I edited the php file with my pvoutput key, system id and url for local emoncms instance etc and placed it in/var/www/emoncms/ 

I tested with php /var/www/emoncms/pvoutput.php command. executed with no errors, no output  and did not add the temperature to pvoutput. Temperature was the only feed i enabled in the php file.

Am i missing somethere here? should i get any output if i execute php as above? 

Thanks

warlock's picture

Re: Post EMONCMS value to PVOUTPUT

if I am not mistaken you need to pass the option -f  like this

 

php -f /var/www/emoncms/pvoutput.php

 

Wombatsev's picture

Re: Post EMONCMS value to PVOUTPUT

Hi All

Thanks to all that have contributed to this thread and the development of the PVoutput.org script.

I thought I would just add a note regarding an issue I had whilst implementing it. The data would not load in the variables and returned with "false". It turned out the only feeds that would work were ones that were public.

I found that adding "&apikey=MY_EMONCMS_READ_API_KEY" to the json request fixed the issue. Like this

       http ://url_of_EMONCMS/emoncms/feed/value.json?id=8&apikey=MY_EMONCMS_READ_API_KEY

I was hitting my local EMON install.

Hope this helps and that is not too confusing.

Cheers

Mark 7

 

Robert Wall's picture

Re: Post EMONCMS value to PVOUTPUT

You need the API key for any writes to the database that originate outside the machine that physically holds the data. (Else anyone and his dog could send data to your database!)
And similarly to read from it (privacy? - you don't want anyone to be able to infer what you're doing and when).

grantwatson's picture

Re: Post EMONCMS value to PVOUTPUT

Hi All,

I have managed to get a script working great from the command line, however it does not appear to work from Crontab.

I have added it into root's crontab to run every 5 minutes. nothing updates on the pv output website.

Thoughts?

///Double post deleted - Paul\\\

Bill Thomson's picture

Re: Post EMONCMS value to PVOUTPUT

Hello Grant,

Have you tried using the fully qualified path name to your script, in your crontab?

Are you running your cron job as the system user, or as the root user?

 

grantwatson's picture

Re: Post EMONCMS value to PVOUTPUT

Hi,

crontab entry is as follows

0,5,10,15,20,25,30,35,40,45,50,55 * * * *  root    /usr/bin/php -f /var/www/emoncms/pvoutput.php

Running it as root.
 an entry appears in syslog to say its run.

grantwatson's picture

Re: Post EMONCMS value to PVOUTPUT

now i print the crontab out i see the error, fixed thanks.

Toberwine's picture

Re: Post EMONCMS value to PVOUTPUT

Hi can someone tell me exactly how to get my Emonpi to upload data to pvoutput? I have no idea what to do with scripts, I just access the Emonpi using my web browser.

Update - I have now figured out how to get data from my Emonpi uploaded to emoncms.org. I'd love to have the functionality of being able to automate data uploading to pvoutput.org!

Peter Galbavy's picture

Re: Post EMONCMS value to PVOUTPUT

My very quick and dirty perl script is attached. You need to edit the API keys, the system ID and the feeds and as I use my own emoncms server the root URL of the emoncms system to get the data from.

Comments welcome, but this is very hacky. I run it every 5 minutes from cron and that's it. Works for me.

Note that cumulative values (which this script uses for the consumption kWh) only really start working from the next midnight as the pvoutput system uses the first value of the day as the starting point for the consumption.

I tried using "live" consumption but that would have required keeping track of power consumed between posting intervals. It was easier to let them calculate it.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.