Messaggioda SiRe » 19/09/2018, 20:54
Dopo 6 giorni di assidua lettura dei file PHP e di test, sono riuscito a trovare una soluzione relativa al problema che generava errori sulle letture descritti in precedenza. Ora da due gg tutto gira perfettamente…. era tutta colpa del remotepooler fornitomi da JM che non gira ne con virtualmeter ne con eflow ne con pvoutput.
Il problema sta nella mancata compilazione nel file csv del MeterN del valore relativo alla produzione quando l'inverter è spento.
Pubblico qui il remotepooler per chi ne avesse necessità, ho adattato il modello Flanesi….. mi piacerebbe avere un parere da Flavio o da qualche esperto di PHP io non ho un'esperienza approfondita su questo linguaggio, magari ci sono soluzioni migliori….. ho lasciato tutte le righe del file originale commentate con // in modo da evidenziare che cosa ho variato.
#!/usr/bin/php
<?php
if (isset($_SERVER['REMOTE_ADDR'])) {
die('Direct access not permitted');
}
// This script will output a 123solar counter into a meterN compatible format
// Configure, then ln -s /var/www/comapps/pool123s.php /usr/local/bin/pool123s
// Request Main command with 'remotepool123s -energy' and live command 'remotepool123s -power'
// Mod:.............Flanesi
// Date:............10/09/2017
// Mod. Remote:.....Siega
// Date:............06/09/2018
// 123solar config
//$pathto123s = '/var/www/123solar';
$invtnum = 1; //123solar inverter number
// meterN config
$pathtomn = '/var/www/metern';
$METERID = '1';
$INVTmetnum = 1; // meter number
$KWHTC = 0; // Contatore iniziale in caso di azzeramento o sostituzione inverter (si somma al valore letto)
$remotedata = file_get_contents("http://192.XXX.XXX.XXX/123solar/programs/programlive.php?invtnum=$invtnum");
//echo $remotedata;
// No edit is needed below
if (isset($argv[1])) {
define('checkaccess', TRUE);
// include("http://192.XXX.XXX.XXX/123solar/config/config_main.php"); // DA ERRORE
// include("http://192.XXX.XXX.XXX/123solar/config/config_invt$invtnum.php"); // DA ERRORE
// include("http://192.XXX.XXX.XXX/123solar/config/memory.php"); // DA ERRORE
$DTZ='Europe/Rome'; // AGGIUNTA PER EVITARE ERRORE
date_default_timezone_set($DTZ);
$KWHT = null;
if (!empty($remotedata)) {
//$remotedata = file_get_contents($LIVEMEMORY);
$memarray = json_decode($remotedata, true);
$nowUTC = strtotime(date("Ymd H:i:s"));
if ($argv[1] == '-power') {
if ($nowUTC - $memarray["SDTE"] < 30) {
$GP = $memarray["G1P"] + $memarray["G2P"] + $memarray["G3P"];
$GP = round($GP, 0);
} else { // Too old
$GP = 0;
}
echo "$METERID($GP*W)\n";
} elseif ($argv[1] == '-energy') {
if ($nowUTC - $memarray["SDTE"] < 86400) { // (valore standard 600 - modificato a 86400)
$KWHT = round($memarray["KWHT"] * 1000); // Wh
} else {
die("Abording: Too late value\n");
}
/******************* SOSPESA MODELLO FLANESI ********************
if (empty($KWHT) || $KWHT == 0) { // 123s ain't running at night retrieve the value in csv
$dir = $pathto123s . '/data/invt' . $invtnum . '/csv';
$output = glob($dir . '/*.csv');
sort($output);
$xdays = count($output);
if ($xdays > 0) {
$lastlog = $output[$xdays - 1];
$lines = file($lastlog);
$contalines = count($lines);
$array_last = preg_split('/,/', $lines[$contalines - 1]);
$KWHT = round(($array_last[27] * ${'CORRECTFACTOR' . $invtnum} * 1000), 0); //in Wh
} else {
$KWHT = null;
}
}
********************************** FINE SOSPENSIONE ***************************************/
//************************************NUOVO LETTURA FILE REMOTO METERN *****************************
if (empty($KWHT) || $KWHT == 0) { // 123s ain't running at night retrieve the value in csv
$oggi = date("Ymd");
$filepath = ('http://192.XXX.XXX.XXX/metern/data/csv/' . $oggi . '.csv'); //LEGGE FILE CSV METERN REMOTO
function csvToArray($filepath){
setlocale(LC_ALL, 'en_US.UTF-8');
// apertura del file
if (($handle = fopen($filepath, "r")) !== FALSE) {
$nn = 0;
// legge una riga alla volta fino alla fine del file
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
// numero di elementi presenti nella riga letta
$num_elementi = count($data);
// popolamento dell'array
for ($x=0; $x<$num_elementi; $x++) {
$csvarray[$nn][$x] = $data[$x];
}
$nn++;
}
// Chiusura del file
fclose($handle);
} else {
die("File non trovato\n");
}
return $csvarray;
}
$array_csv = csvToArray($filepath);
foreach($array_csv as $numero_riga => $valori){
}
$KWHT = $valori[1];
}
//****************************************FINE NUOVO **************************************
$KWHT += $KWHTC;
if (!empty($KWHT)) {
file_put_contents("/dev/shm/produzione$METERID.txt", "$METERID($KWHT*Wh)\n");
echo "$METERID($KWHT*Wh)\n";
}
} else {
die("Abording: no valid argument given\n");
}
} else { // 123s ain't running
die("Abording: Empty SHM\n");
}
} else {
die("Usage: pool123s { power | energy }\n");
}
?>