Get Data via script from /programs/programday.php ...

Talks about solar stuff
Post Reply
Sven
Posts: 5
Joined: Fri Aug 30, 2013 9:41 am

Get Data via script from /programs/programday.php ...

Post by Sven » Sun Sep 15, 2013 3:01 pm

Hello,

is it possible to use http://ip/programs/programday.php or something else
to get some data to another php script.
Is there an Wikki or something else what data is there and how can i catch it with a script?

Data like "today kwh, yesterday kwh, max power today, production of month etc."

actual power etc. i get from scripts/debugmem_read.php at the moment.

The backgroud for the question is, to get all usable data vom PV and Electric Meter and heating system in one php script. Then put all results into a comma separated string and catch the String from arduino mega with 3.2" TFT Touch. Then you can see all data in the living room via WIFI or ethernet :D

Best Regards
Sven

jeanmarc
Posts: 2022
Joined: Thu Aug 29, 2013 7:16 am

Re: Get Data via script from /programs/programday.php ...

Post by jeanmarc » Sun Sep 15, 2013 5:47 pm

Hi,

Well no documentation, all is in my brain :lol:
Seriously, the data parsed by php programs are return in JSON format structure. And, if it need an argument, it is usually the inverter number (eg programs/programday.php?invtnum=1)

I like the idea of getting all infos in one page or in a TFT.. and that's the aim of meterN 8-)

Pongo
Posts: 30
Joined: Thu Sep 19, 2013 1:18 pm

Re: Get Data via script from /programs/programday.php ...

Post by Pongo » Thu Sep 19, 2013 1:24 pm

Hello,
see my example, the relvant part is before $PDC_FORCE = get_status();
put it into scripts folder

Code: Select all

#!/usr/bin/php

<?php
include('read_maincfg.php');
include_once('pdc.php');
include_once('pdc_db.php');

for ($invt_num = 1; $invt_num <= $NUMINV; $invt_num++) {
    $invtnum = $invt_num;
    include("read_invtcfg.php");
    $systemid = "1231" . $invt_num;
    @$shmid = shmop_open($systemid, "a", 0444, 256);
    if (!empty($shmid)) {
        $livedash[0] = shmop_read($shmid, 0, 256);
        shmop_close($shmid);
    } else {
        $nowUTC      = strtotime(date("Ymd H:i:s"));
        $livedash[0] = "$nowUTC,0,0,0,0,0,0,0,0,0,0,0,0,0,0";
    }
    $array = preg_split("/,/", $livedash[0]);

    if (!isset($GPTOT)) {
        $GPTOT = 0;
    }
    $array[9] *= $CORRECTFACTOR;
    $GPTOT += $array[9];
}

if ($GPTOT > 1000) {
    $GPTOT = round($GPTOT, 0);
} else {
    $GPTOT = round($GPTOT, 1);
}

$PDC_FORCE = get_status();
$PDC_STATUS = read_pdc($PDC_URL);
$PDC_LAST_ON = get_laston();

$date = date('Ymd_His');
$now = time();
echo "$date - Production: $GPTOT, PDC force = $PDC_FORCE, PDC status = $PDC_STATUS, PDC_MIN = $PDC_MIN, last on = " . ($PDC_LAST_ON > 0 ? gmdate("Y-m-d H:i:s", $PDC_LAST_ON) : "0") . "\n";

if ($PDC_FORCE == STATUS_FV) {
	if ($GPTOT < ($PDC_LIM - $PDC_HIS) && strcmp($PDC_STATUS, STATUS_ON) == 0) {
		$diff = round(abs($now - $PDC_LAST_ON) / 60, 2);
		if ($diff >= $PDC_MIN) {
			echo "Turning off\n";
			change_pdc($PDC_URL, STATUS_OFF);
			save_laston(0);
			save_data($date, $GPTOT, $PDC_STATUS, STATUS_OFF, $PDC_FORCE);
		} else {
			echo "Waiting at least $PDC_MIN min before turning off. Now $diff\n";
		}
	} else if ($GPTOT >= $PDC_LIM && strcmp($PDC_STATUS, STATUS_OFF) == 0) {
		echo "Turning on\n";
		change_pdc($PDC_URL, STATUS_ON);
		save_laston($now);
		save_data($date, $GPTOT, $PDC_STATUS, STATUS_ON, $PDC_FORCE);
	} else {
		save_data($date, $GPTOT, $PDC_STATUS, $PDC_STATUS, $PDC_FORCE);
	}
} else {
	save_data($date, $GPTOT, $PDC_STATUS, $PDC_STATUS, $PDC_FORCE);
}

?>
EDIT: sorry, I was thinking at live data. I use it's energy value to turn on/off an Air Source Heat Pump (ASHP = PDC)

Walter62
Posts: 32
Joined: Thu Aug 29, 2013 11:40 am
Location: Italia
Contact:

Re: Get Data via script from /programs/programday.php ...

Post by Walter62 » Sat Apr 12, 2014 7:31 pm

Hi jeanmarc great job,

in your previous version 1.5.5 I have reused part of your code, to read data from memory, to exchange with OpenEnergyMonitor:

Code: Select all

if ($nowUTC > ($sun_info['sunrise'] - 300) && $nowUTC < ($sun_info['sunset'] + 300)) {
	for ($invt_num = 1; $invt_num <= $NUMINV; $invt_num++) {
		$invtnum = $invt_num;
		include("/var/www/123solar/scripts/read_invtcfg.php");
		$systemid = "1231" . $invt_num;
		@$shmid = shmop_open($systemid, "a", 0444, 256);
			if (!empty($shmid)) {
				$livedash[0] = shmop_read($shmid, 0, 256);
				shmop_close($shmid);
			} else {
				$nowUTC      = strtotime(date("Ymd H:i:s"));
				$livedash[0] = "$nowUTC,0,0,0,0,0,0,0,0,0,0,0,0,0,0";
			}
		$valore = preg_split("/,/", $livedash[0]);
in version 1.6.5.2 what is the way to read the same data?

Thanks in advance

jeanmarc
Posts: 2022
Joined: Thu Aug 29, 2013 7:16 am

Re: Get Data via script from /programs/programday.php ...

Post by jeanmarc » Sat Apr 12, 2014 7:40 pm

Hi Walter,

In 1.6 all the datas are stored in one place and in json format. Take a look on 'programlive', the only memory space is config/memory.php and you just need to json_decode the data.

You can see all data in Shared memory via admin/help.php

Btw: nice Raspi guide :)

Walter62
Posts: 32
Joined: Thu Aug 29, 2013 11:40 am
Location: Italia
Contact:

Re: Get Data via script from /programs/programday.php ...

Post by Walter62 » Sat Apr 12, 2014 8:14 pm

Thanks, I try to work on it tomorrow ;)

jeanmarc
Posts: 2022
Joined: Thu Aug 29, 2013 7:16 am

Re: Get Data via script from /programs/programday.php ...

Post by jeanmarc » Sun Apr 13, 2014 11:07 am

You may take a look on "pool123s" example of meterN, i believe it does what you want..

Walter62
Posts: 32
Joined: Thu Aug 29, 2013 11:40 am
Location: Italia
Contact:

Re: Get Data via script from /programs/programday.php ...

Post by Walter62 » Sun Apr 13, 2014 7:39 pm

Yes, this is what I wanted.
I have changed my files and now all works fine. :D

Thanks very much

Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests