diff --git a/opt/inverter/inverter.php b/opt/inverter/inverter.php index c85ac05..2a27d6c 100644 --- a/opt/inverter/inverter.php +++ b/opt/inverter/inverter.php @@ -14,10 +14,10 @@ define('DEFAULT_SLEEP', '19:00'); chdir(CWD); /* 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")); - $sJob = command(sprintf('at -c %s ' . "\n", $sId)); - $aJob = explode("\n", trim(command(sprintf('at -c %s', $sId)))); + $sJob = command(sprintf('at -c %s 2> /dev/null' . "\n", $sId)); + $aJob = explode("\n", trim(command(sprintf('at -c %s 2> /dev/null', $sId)))); if (strpos(array_pop($aJob), NAME) !== false) { command(sprintf('atrm %s', $sId)); } @@ -55,6 +55,7 @@ System_Daemon::info(sprintf('Be awake between %s and %s', $sWake, $sSleep)); /* Start deamon */ System_Daemon::start(); $bStop = $bAlarm = false; + while (!$bStop && !System_Daemon::isDying()) { /* Check for current need to be awake */ $fNow = getHour(); @@ -77,13 +78,19 @@ while (!$bStop && !System_Daemon::isDying()) { command(TASK); System_Daemon::info('Task ended'); } else { - /* Schedule next wake time */ - $sTime = date('H:i', strtotime($sWake)); // ignore slight deviation for next day - command(sprintf('at -f %s %s 2> /dev/null', FILE_DAEMON_START, $sTime)); - System_Daemon::info(sprintf('Waiting untill %s', $sTime)); + /* Schedule next wake time */ + schedule_wake(); $bStop = true; } } /* Stop daemon */ -System_Daemon::stop(); \ No newline at end of file +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)); +} diff --git a/opt/inverter/inverter.pl b/opt/inverter/inverter.pl index ec7aae5..ab0d45d 100644 --- a/opt/inverter/inverter.pl +++ b/opt/inverter/inverter.pl @@ -1573,8 +1573,8 @@ while (1) { #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"; #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"; - system ($config->scripts_pvoutput_php . " $HoH{ETODAY}{VALUE} $HoH{PAC}{VALUE} $HoH{VAC}{VALUE} $HASH{SERIAL}"); + 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} * 1000) . " $HoH{PAC}{VALUE} $HoH{VAC}{VALUE} $HASH{SERIAL} &"); $lastPvoutputTime = time; } } diff --git a/opt/inverter/pvoutput.php b/opt/inverter/pvoutput.php index fa13cdf..f9a8128 100644 --- a/opt/inverter/pvoutput.php +++ b/opt/inverter/pvoutput.php @@ -10,8 +10,8 @@ define('PVOUTPUT_URL', 'http://pvoutput.org/service/r1/addstatus.jsp'); define('TODAY_FILE', 'data/today_%s.csv'); define('FIELD', 'PAC'); define('RESOLUTION', 5); -define('MARGIN_ENERGY', 0.1); -define('MARGIN_TEMPERATURE', 0.2); +define('MARGIN_ENERGY', 0.5); +define('MARGIN_TEMPERATURE', 0.4); $aSystems = array( '1204DQ0116' => array('16e7a916d69656e354d00461a4da1d2e40cfa4f1', '12419') ); @@ -20,9 +20,9 @@ $aSystems = array( //$argv = array(null, 1.5, 1234, 230, '1204DQ0116'); /* Fetch command line arguments */ -$fToday = floatval($argv[1]); -$fPower = floatval($argv[2]); -$fVoltage = floatval($argv[3]); +$fToday = floatval($argv[1]); // Wh +$fPower = floatval($argv[2]); // W +$fVoltage = floatval($argv[3]); // V $sSerial = $argv[4]; /* Fetch temperature */ @@ -38,6 +38,7 @@ $sTodayFile = sprintf(TODAY_FILE, $sSerial); $aToday = array(); if (file_exists($sTodayFile)) { $aToday = explode(',', file_get_contents($sTodayFile)); + $aToday[1] = floatval($aToday[1]); } if (count($aToday) != 3 || $aToday[0] != $iDay) { $aToday = array($iDay, 0, strtotime($aTwilight[1]), null); @@ -62,15 +63,15 @@ if (isset($aFields[FIELD])) { $aRow = explode(' ', $sRow); $iDate = substr($aRow[0], 0, -1); $iInterval = $bFirst ? (($bFirst = false) || RESOLUTION) : $iDate - $iLast; - if (($fValue = floatval($aRow[$iField])) > 0) { - $fEnergy += $iInterval * $fValue; + if (($fValue = floatval($aRow[$iField])) > 0) { // W + $fEnergy += $iInterval * $fValue; // Ws } $iLast = $iDate; - } + } } /* Store today data */ -$aToday[1] += $fEnergy / 1000 / 3600; +$aToday[1] += $fEnergy / 3600; // Wh $aToday[2] = $iTime; $aToday[3] = $fTemperature; file_put_contents($sTodayFile, implode(',', $aToday)); @@ -82,9 +83,9 @@ $fToday = $fToday > ((1 + MARGIN_ENERGY) * $aToday[1]) ? $aToday[1] : $fToday; $aData = array( 'd' => date('Ymd', $iTime), 't' => date('H:i', $iTime), - 'v1' => 1000 * $fToday, // Wh - 'v2' => $fPower, - 'v6' => $fVoltage); + 'v1' => $fToday, // Wh + 'v2' => $fPower, // W + 'v6' => $fVoltage); // V /* Add (corrected) temperature when available */ if (isset($fTemperature)) { @@ -95,7 +96,7 @@ if (isset($fTemperature)) { } /* 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 */ if (isset($aSystems[$sSerial])) { @@ -108,4 +109,4 @@ if (isset($aSystems[$sSerial])) { CURLOPT_POSTFIELDS => http_build_query($aData), CURLOPT_RETURNTRANSFER => true)); $sResult = curl_exec($rCurl); -} \ No newline at end of file +}