Come sempre un grandissimo lavoro fatto da Jean Marc.

Le novità sono:
- Remove daily report
- Config version with check, you'll need to save the configuration for each of your meters
- Complete rewrite of notification
- Added rpinotify notification
- Update is now fully automatic with backup and in one click !
- Bug start/stop daemon (beware to update com_daemon if you use it from comapps_examples)
- Bug bootmn
- Others clean up and bug fixes
In particolare potete notare l'integrazione del nuovo sistema di notifica tutto italiano RPINotify che utilizza Telegram per le notifiche.
Una proposta di integrazione che avevo lanciato a JM e che ha prontamente accettato.
Ho testato questa versione e devo evidenziare che per poterla utilizzare non basta eseguire solo l'aggiornamento semiautomatico previsto, ma risulta necessario intervenire manualmente anche su alcuni file.
1) bootmn.php
Causa un bug presente nell'aggiornamento, la variabile $pid presente nel file pool123s.php ora diventa $PID
E' quindi necessario modificare la variabile $pid in $PID anche nel file /var/www/metern/scripts/bootmn.php che quindi diventa:
Codice: Seleziona tutto
<?php
if ($_SERVER['SERVER_ADDR'] != '127.0.0.1' && $_SERVER['SERVER_ADDR'] != '::1') {
die('Direct access not permitted');
}
define('checkaccess', TRUE);
include('../config/config_main.php');
date_default_timezone_set($DTZ);
$SCRDIR = dirname(__FILE__);
$PID = null;
$now = date($DATEFORMAT . ' H:i:s');
if (file_exists('metern.pid')) {
exec('pkill -f metern.php> /dev/null 2>&1 &'); //make sure there is only one instance
usleep(500000);
unlink('metern.pid');
}
if ($DEBUG) {
$command = 'php metern.php' . ' >> ../data/metern.err 2>&1 & echo $!; ';
$PID = exec($command);
file_put_contents('metern.pid', $PID);
$stringData = "$now\tStarting meterN on boot debug ($PID)\n\n";
$myFile = dirname($SCRDIR) . '/data/metern.err';
file_put_contents($myFile, $stringData, FILE_APPEND);
} else {
$command = 'php metern.php' . ' > /dev/null 2>&1 & echo $!;';
$PID = exec($command);
file_put_contents('metern.pid', $PID);
$stringData = "$now\tStarting meterN on boot ($PID)\n\n";
}
include('../config/config_daemon.php');
$DATADIR = dirname($SCRDIR) . '/data';
$stringData .= file_get_contents($DATADIR . '/events.txt');
file_put_contents($DATADIR . '/events.txt', $stringData);
?>
2) pool123s.php
Per il bug indicato sopra è necessario utilizzare il nuovo pool123s.php.
Ho quindi provveduto a modificare ed integrare il file pool123s.php fornito da JM con quanto necessario per il corretto funzionamento con l'immagine Solajessie. Il file /var/www/comapps/pool123s.php diventa quindi:
Codice: Seleziona tutto
#!/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/bin/pool123s
// Request Main command with 'pool123s energy' and live command 'pool123s power'
// Mod:.............Flanesi
// Date:............10/09/2017
// 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)
// No edit is needed below
if (isset($argv[1])) {
define('checkaccess', TRUE);
include("$pathto123s/config/config_main.php");
include("$pathto123s/config/config_invt$invtnum.php");
include("$pathto123s/config/memory.php");
date_default_timezone_set($DTZ);
$KWHT = null;
if (file_exists($LIVEMEMORY)) {
$data = file_get_contents($LIVEMEMORY);
$memarray = json_decode($data, true);
$nowUTC = strtotime(date("Ymd H:i:s"));
if ($argv[1] == 'power') {
if ($nowUTC - $memarray["SDTE$invtnum"] < 30) {
$GP = $memarray["G1P$invtnum"] + $memarray["G2P$invtnum"] + $memarray["G3P$invtnum"];
$GP = round($GP, 0);
} else { // Too old
$GP = 0;
}
echo "$METERID($GP*W)\n";
} elseif ($argv[1] == 'energy') {
if ($nowUTC - $memarray["SDTE$invtnum"] < 86400) { // (valore standard 600 - modificato a 86400)
$KWHT = round($memarray["KWHT$invtnum"] * 1000); // Wh
} else {
die("Abording: Too late value\n");
}
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;
}
}
$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");
}
?>
3) config_daemon.php
In questa nuova versione è prevista una diversa sinstassi dei comandi in config_daemon.php, oltre al problema del bug della variabile $PID
Il file /var/www/metern/config/config_daemon.php diventa quindi:
Codice: Seleziona tutto
<?php
if(!defined('checkaccess')){die('Direct access not permitted');}
// Manage com. apps daemon as 'http' user if needed
if (is_null($PID)) { // Stop Daemon
exec("pkill -f pooler485 > /dev/null 2>&1 &");
} else { //Start
exec("pooler485 2 9600 /dev/ttyUSB0 > /dev/null 2>/dev/null &");
}
?>
Ovviamente dovrete modificare la riga di avvio del pooler485 in base all'indirizzo e numero dei vostri contatori da leggere, porta e velocità da utilizzare.

Provvedo al allegare anche i tre file da modificare.
Nel caso andiate a sostituirli invece che modificarle, fate attenzione che siano mantenuti permessi e proprietari dei file.