* inverter daemon now schedules itself to wake the next day before going to sleep

* pvoutput now uses today cumulative value in more convenient Wh units
This commit is contained in:
2012-12-02 13:02:03 +01:00
parent 25758dc18f
commit aa8d7d641f
3 changed files with 32 additions and 24 deletions

View File

@@ -14,10 +14,10 @@ define('DEFAULT_SLEEP', '19:00');
chdir(CWD); chdir(CWD);
/* Remove previous at entries */ /* Remove previous at entries */
foreach (explode("\n", trim(command('atq'))) as $sJob) { foreach (explode("\n", trim(command('atq 2> /dev/null'))) as $sJob) {
$sId = substr($sJob, 0, strpos($sJob, "\t")); $sId = substr($sJob, 0, strpos($sJob, "\t"));
$sJob = command(sprintf('at -c %s ' . "\n", $sId)); $sJob = command(sprintf('at -c %s 2> /dev/null' . "\n", $sId));
$aJob = explode("\n", trim(command(sprintf('at -c %s', $sId)))); $aJob = explode("\n", trim(command(sprintf('at -c %s 2> /dev/null', $sId))));
if (strpos(array_pop($aJob), NAME) !== false) { if (strpos(array_pop($aJob), NAME) !== false) {
command(sprintf('atrm %s', $sId)); command(sprintf('atrm %s', $sId));
} }
@@ -55,6 +55,7 @@ System_Daemon::info(sprintf('Be awake between %s and %s', $sWake, $sSleep));
/* Start deamon */ /* Start deamon */
System_Daemon::start(); System_Daemon::start();
$bStop = $bAlarm = false; $bStop = $bAlarm = false;
while (!$bStop && !System_Daemon::isDying()) { while (!$bStop && !System_Daemon::isDying()) {
/* Check for current need to be awake */ /* Check for current need to be awake */
$fNow = getHour(); $fNow = getHour();
@@ -77,13 +78,19 @@ while (!$bStop && !System_Daemon::isDying()) {
command(TASK); command(TASK);
System_Daemon::info('Task ended'); System_Daemon::info('Task ended');
} else { } else {
/* Schedule next wake time */ /* Schedule next wake time */
$sTime = date('H:i', strtotime($sWake)); // ignore slight deviation for next day schedule_wake();
command(sprintf('at -f %s %s 2> /dev/null', FILE_DAEMON_START, $sTime));
System_Daemon::info(sprintf('Waiting untill %s', $sTime));
$bStop = true; $bStop = true;
} }
} }
/* Stop daemon */ /* Stop daemon */
System_Daemon::stop(); System_Daemon::stop();
schedule_wake();
function schedule_wake() {
global $sWake;
$sTime = date('H:i', strtotime($sWake)); // ignore slight deviation for next day
System_Daemon::info(sprintf('Waiting untill %s', $sTime));
command(sprintf('at -f %s %s 2> /dev/null', FILE_DAEMON_START, $sTime));
}

View File

@@ -1573,8 +1573,8 @@ while (1) {
#print "PVOUTPUT as at " . getDateTime(time) . " ...\n"; #print "PVOUTPUT as at " . getDateTime(time) . " ...\n";
#print " ran: " . $config->scripts_pvoutput . " " . ($HoH{ETODAY}{VALUE} * 1000) . " $HoH{PAC}{VALUE} $HoH{VAC}{VALUE} $date $time $HASH{SERIAL}\n"; #print " ran: " . $config->scripts_pvoutput . " " . ($HoH{ETODAY}{VALUE} * 1000) . " $HoH{PAC}{VALUE} $HoH{VAC}{VALUE} $date $time $HASH{SERIAL}\n";
#system ($config->scripts_pvoutput . " " . ($HoH{ETODAY}{VALUE} * 1000) . " $HoH{PAC}{VALUE} $HoH{VAC}{VALUE} $date $time $HASH{SERIAL}" ); #system ($config->scripts_pvoutput . " " . ($HoH{ETODAY}{VALUE} * 1000) . " $HoH{PAC}{VALUE} $HoH{VAC}{VALUE} $date $time $HASH{SERIAL}" );
print " ran: " . $config->scripts_pvoutput_php . " $HoH{ETODAY}{VALUE} $HoH{PAC}{VALUE} $HoH{VAC}{VALUE} $HASH{SERIAL}\n"; print " ran: " . $config->scripts_pvoutput_php . " " . ($HoH{ETODAY}{VALUE} * 1000) . " $HoH{PAC}{VALUE} $HoH{VAC}{VALUE} $HASH{SERIAL}\n";
system ($config->scripts_pvoutput_php . " $HoH{ETODAY}{VALUE} $HoH{PAC}{VALUE} $HoH{VAC}{VALUE} $HASH{SERIAL}"); system ($config->scripts_pvoutput_php . " " . ($HoH{ETODAY}{VALUE} * 1000) . " $HoH{PAC}{VALUE} $HoH{VAC}{VALUE} $HASH{SERIAL} &");
$lastPvoutputTime = time; $lastPvoutputTime = time;
} }
} }

View File

@@ -10,8 +10,8 @@ define('PVOUTPUT_URL', 'http://pvoutput.org/service/r1/addstatus.jsp');
define('TODAY_FILE', 'data/today_%s.csv'); define('TODAY_FILE', 'data/today_%s.csv');
define('FIELD', 'PAC'); define('FIELD', 'PAC');
define('RESOLUTION', 5); define('RESOLUTION', 5);
define('MARGIN_ENERGY', 0.1); define('MARGIN_ENERGY', 0.5);
define('MARGIN_TEMPERATURE', 0.2); define('MARGIN_TEMPERATURE', 0.4);
$aSystems = array( $aSystems = array(
'1204DQ0116' => array('16e7a916d69656e354d00461a4da1d2e40cfa4f1', '12419') '1204DQ0116' => array('16e7a916d69656e354d00461a4da1d2e40cfa4f1', '12419')
); );
@@ -20,9 +20,9 @@ $aSystems = array(
//$argv = array(null, 1.5, 1234, 230, '1204DQ0116'); //$argv = array(null, 1.5, 1234, 230, '1204DQ0116');
/* Fetch command line arguments */ /* Fetch command line arguments */
$fToday = floatval($argv[1]); $fToday = floatval($argv[1]); // Wh
$fPower = floatval($argv[2]); $fPower = floatval($argv[2]); // W
$fVoltage = floatval($argv[3]); $fVoltage = floatval($argv[3]); // V
$sSerial = $argv[4]; $sSerial = $argv[4];
/* Fetch temperature */ /* Fetch temperature */
@@ -38,6 +38,7 @@ $sTodayFile = sprintf(TODAY_FILE, $sSerial);
$aToday = array(); $aToday = array();
if (file_exists($sTodayFile)) { if (file_exists($sTodayFile)) {
$aToday = explode(',', file_get_contents($sTodayFile)); $aToday = explode(',', file_get_contents($sTodayFile));
$aToday[1] = floatval($aToday[1]);
} }
if (count($aToday) != 3 || $aToday[0] != $iDay) { if (count($aToday) != 3 || $aToday[0] != $iDay) {
$aToday = array($iDay, 0, strtotime($aTwilight[1]), null); $aToday = array($iDay, 0, strtotime($aTwilight[1]), null);
@@ -62,15 +63,15 @@ if (isset($aFields[FIELD])) {
$aRow = explode(' ', $sRow); $aRow = explode(' ', $sRow);
$iDate = substr($aRow[0], 0, -1); $iDate = substr($aRow[0], 0, -1);
$iInterval = $bFirst ? (($bFirst = false) || RESOLUTION) : $iDate - $iLast; $iInterval = $bFirst ? (($bFirst = false) || RESOLUTION) : $iDate - $iLast;
if (($fValue = floatval($aRow[$iField])) > 0) { if (($fValue = floatval($aRow[$iField])) > 0) { // W
$fEnergy += $iInterval * $fValue; $fEnergy += $iInterval * $fValue; // Ws
} }
$iLast = $iDate; $iLast = $iDate;
} }
} }
/* Store today data */ /* Store today data */
$aToday[1] += $fEnergy / 1000 / 3600; $aToday[1] += $fEnergy / 3600; // Wh
$aToday[2] = $iTime; $aToday[2] = $iTime;
$aToday[3] = $fTemperature; $aToday[3] = $fTemperature;
file_put_contents($sTodayFile, implode(',', $aToday)); file_put_contents($sTodayFile, implode(',', $aToday));
@@ -82,9 +83,9 @@ $fToday = $fToday > ((1 + MARGIN_ENERGY) * $aToday[1]) ? $aToday[1] : $fToday;
$aData = array( $aData = array(
'd' => date('Ymd', $iTime), 'd' => date('Ymd', $iTime),
't' => date('H:i', $iTime), 't' => date('H:i', $iTime),
'v1' => 1000 * $fToday, // Wh 'v1' => $fToday, // Wh
'v2' => $fPower, 'v2' => $fPower, // W
'v6' => $fVoltage); 'v6' => $fVoltage); // V
/* Add (corrected) temperature when available */ /* Add (corrected) temperature when available */
if (isset($fTemperature)) { if (isset($fTemperature)) {
@@ -95,7 +96,7 @@ if (isset($fTemperature)) {
} }
/* Store debug data */ /* Store debug data */
file_put_contents('pvoutput.debug', array(json_encode($argv), json_encode($aData)) . "\n", FILE_APPEND); file_put_contents('pvoutput.debug', json_encode(array($argv, $aData)) . "\n", FILE_APPEND);
/* Send data to PVOutput */ /* Send data to PVOutput */
if (isset($aSystems[$sSerial])) { if (isset($aSystems[$sSerial])) {
@@ -108,4 +109,4 @@ if (isset($aSystems[$sSerial])) {
CURLOPT_POSTFIELDS => http_build_query($aData), CURLOPT_POSTFIELDS => http_build_query($aData),
CURLOPT_RETURNTRANSFER => true)); CURLOPT_RETURNTRANSFER => true));
$sResult = curl_exec($rCurl); $sResult = curl_exec($rCurl);
} }