
Devo rifare tutto. Dovete pazientare un pò.
Vi comunico appena la ricarico.
Comunque avevo solo aggiornato metern ed il sistema per avere la compatibilità con RPI3
Codice: Seleziona tutto
<?php
define('checkaccess', TRUE);
include('../config/config_main.php');
date_default_timezone_set($DTZ);
if (isset($_COOKIE['user_lang'])) {
$user_lang = $_COOKIE['user_lang'];
} else {
$user_lang = 'English';
}
include('../languages/' . $user_lang . '.php');
if (!empty($_GET['date1'])) {
$date1 = $_GET['date1'];
} else {
$date1 = FALSE;
}
$grid = array();
for ($i = 1; $i <= $NUMMETER; $i++) {
include("../config/config_met$i.php");
$check[$i] = $_GET["check$i"];
if (${'TYPE' . $i} == 'Elect' && ${'PROD' . $i} != 0 && !isset($grid[${'PHASE' . $i}])) {
$grid[${'PHASE' . $i}] = ${'PHASE' . $i};
}
}
sort($grid);
$cnt = count($grid);
$sscnt = 0;
$efcnt = 0;
for ($i = 0; $i < $cnt; $i++) {
if (!empty($_GET["ss$i"])) { // Self-sufficiency
$ss[$i] = $_GET["ss$i"];
if ($ss[$i] != 0) {
$selfsuff[$sscnt] = $ss[$i];
$sscnt++;
}
}
if (!empty($_GET["ef$i"])) { // Energy-flow
$ef[$i] = $_GET["ef$i"];
if ($ef[$i] != 0) {
$energf[$efcnt] = $ef[$i];
$efcnt++;
}
}
}
$log = "../data/csv/$date1";
if (file_exists($log)) {
$file = file($log);
$contalines = count($file);
$year = substr($date1, 0, 4);
$month = substr($date1, 4, 2);
$day = substr($date1, 6, 2);
$unitlist = array();
$metlist = array();
$nbrstack = 0;
for ($i = 1; $i <= $NUMMETER; $i++) {
if ($check[$i] == 'on') {
array_push($metlist, $i);
$stackname[$nbrstack] = "${'METNAME'.$i}";
$color[$nbrstack] = "#${'COLOR'.$i}";
if (!in_array(${'UNIT' . $i}, $unitlist)) {
array_push($unitlist, ${'UNIT' . $i});
}
$nbrstack++;
}
}
if ($sscnt > 0 && !in_array('%', $unitlist)) {
array_push($unitlist, '%');
}
if ($efcnt > 0 && !in_array('Wh', $unitlist)) {
array_push($unitlist, 'Wh');
}
$stack = array(
array()
);
$EPtot = array(
array()
);
$ECtot = array(
array()
);
$ESStot = 0;
for ($line_num = 2; $line_num < $contalines; $line_num++) {
$pastline_num = $line_num - 1;
$prevarray = preg_split("/,/", $file[$pastline_num]);
$array = preg_split("/,/", $file[$line_num]);
$prevhour = substr($prevarray[0], 0, 2);
$prevmin = substr($prevarray[0], 3, 2);
$prevUTCdate = strtotime($year . '-' . $month . '-' . $day . ' ' . $prevhour . ':' . $prevmin);
$prevUTCdate *= 1000;
$SDTE = $array[0];
$hour = substr($SDTE, 0, 2);
$minute = substr($SDTE, 3, 2);
if ($line_num == ($contalines - 1) && $minute == '00' && $hour == '00') {
$epochdate = strtotime(date("$year$month$day")) + 86400;
} else {
$epochdate = strtotime($year . '-' . $month . '-' . $day . ' ' . $hour . ':' . $minute);
}
$epochdate *= 1000;
$nbrstack = 0;
for ($i = 1; $i <= $NUMMETER; $i++) {
if ($check[$i] == 'on') {
$val_first = null;
$val_last = null;
if (isset($array[$i])) {
$val_first = trim($prevarray[$i]);
}
if (isset($prevarray[$i])) {
$val_last = trim($array[$i]);
}
if (${'TYPE' . $i} != 'Sensor' && !empty($val_first) && !empty($val_last) && $line_num > 1 && $epochdate - $prevUTCdate == 300000) { // meter
settype($val_first, 'float');
settype($val_last, 'float');
if ($val_first <= $val_last) {
$val_last -= $val_first;
} else { // counter pass over
$val_last += ${'PASSO' . $i} - $val_first;
}
$val_last = round($val_last, ${'PRECI' . $i});
$stack[$nbrstack][$line_num] = array(
$epochdate,
$val_last
);
$nbrstack++;
} elseif (${'TYPE' . $i} == 'Sensor' && $line_num > 1 && !empty($val_last)) { // sensor
settype($val_last, 'float');
$val_last = round($val_last, ${'PRECI' . $i});
$stack[$nbrstack][$line_num] = array(
$epochdate,
$val_last
);
$nbrstack++;
}
}
if ($sscnt > 0 || $efcnt > 0 && ${'TYPE' . $i} == 'Elect' && ${'PROD' . $i} != 0 && $epochdate - $prevUTCdate == 300000) {
if (!empty($array[$i]) && !empty($prevarray[$i])) {
if ($prevarray[$i] > $array[$i]) {
$value = $array[$i] + ${'PASSO' . $i} - $prevarray[$i];
} else {
$value = $array[$i] - $prevarray[$i];
}
} else {
$value = 0;
}
$ph = ${'PHASE' . $i}; // ?
if (${'PROD' . $i} == 1) {
if (!isset($EPtot[$ph][$line_num])) {
$EPtot[$ph][$line_num] = 0;
}
$EPtot[$ph][$line_num] += $value;
} else {
if (!isset($ECtot[$ph][$line_num])) {
$ECtot[$ph][$line_num] = 0;
}
$ECtot[$ph][$line_num] += $value;
}
}
} // each meters
$ssstack = 0;
$efstack = 0;
if ($sscnt > 0 || $efcnt > 0 && $line_num > 1) {
for ($i = 0; $i < $sscnt; $i++) { // Self-sufficiency
$ph = (int) $selfsuff[$i];
$EP5m = $EPtot[$ph][$line_num];
$EC5m = $ECtot[$ph][$line_num];
if (!isset($CONSOtot)) {
$CONSOtot = 0;
}
$CONSOtot += $EC5m;
if ($EP5m > 0 && $EC5m > 0) {
$EGR5tot = round((($EP5m / $EC5m) * 100), 1);
} else {
$EGR5tot = 0;
}
if ($EGR5tot > 100) {
$EGR5tot = 100;
}
if ($EP5m > 0) {
if ($EP5m > $EC5m) {
$ESStot += $EC5m;
} else {
$ESStot += $EP5m;
}
}
$stack[$ssstack + $nbrstack][$line_num] = array(
$epochdate,
$EGR5tot
);
$stackname[$ssstack + $nbrstack] = "$lgSELFS$selfsuff[$i]";
$color[$ssstack + $nbrstack] = "#AA4643";
$ssstack++;
} // each phase
for ($i = 0; $i < $efcnt; $i++) { // Energy-flow
$ph = (int) $energf[$i];
$flow = $EPtot[$ph][$line_num] - $ECtot[$ph][$line_num];
$stack[$efstack + $ssstack + $nbrstack][$line_num] = array(
$epochdate,
$flow
);
$stackname[$efstack + $ssstack + $nbrstack] = "$lgENERGYF$energf[$i]";
$color[$efstack + $ssstack + $nbrstack] = "#AA4643";
$efstack++;
}
}
} // End of foreach
$dday = date($DATEFORMAT, mktime(0, 0, 0, $month, $day, $year));
settype($titledate, "string");
$title = "$lgDETAILEDOFTITLE $dday $titledate";
if ($sscnt > 0) {
$CONSOtot = round($CONSOtot / 1000, 3);
$ESStot = round($ESStot / 1000, 3);
$ESSratio = round((($ESStot / $CONSOtot) * 100), 1);
$title .= "($ESSratio% $lgAUTONOM $ESStot/$CONSOtot kWh)";
}
$data = array();
$cntunit = count($unitlist);
# // Return datas via json
$j = 0;
for ($i = 1; $i <= $NUMMETER; $i++) {
if ($check[$i] == 'on') {
sort($stack[$j]);
for ($h = 0; $h < $cntunit; $h++) {
if ($unitlist[$h] == ${'UNIT' . $i}) {
$thisyaxis = $h;
}
}
$data[$j] = array(
'name' => $stackname[$j],
'data' => $stack[$j],
'yAxis' => $thisyaxis,
'type' => 'areaspline',
'color' => $color[$j],
'dashStyle' => 'Solid'
);
$j++;
}
}
$cnttotstck = $nbrstack + $ssstack;
if ($sscnt > 0) {
for ($h = 0; $h < $cntunit; $h++) {
if ($unitlist[$h] == '%') {
$thisyaxis = $h;
}
}
for ($i = $nbrstack; $i < $cnttotstck; $i++) {
sort($stack[$i]);
$data[$i] = array(
'name' => $stackname[$i],
'data' => $stack[$i],
'yAxis' => $thisyaxis,
'type' => 'spline',
'color' => '#0B610B',
'dashStyle' => 'Dash'
);
}
}
$cnttotstck2 = $cnttotstck + $efstack;
if ($efcnt > 0) {
for ($h = 0; $h < $cntunit; $h++) {
if ($unitlist[$h] == 'Wh') {
$thisyaxis = $h;
}
}
for ($i = $cnttotstck; $i < $cnttotstck2; $i++) {
sort($stack[$i]);
$data[$i] = array(
'name' => $stackname[$i],
'data' => $stack[$i],
'yAxis' => $thisyaxis,
'type' => 'spline',
'color' => '#BBAA00',
'dashStyle' => 'Dash'
);
}
}
$jsonreturn = array(
'data' => $data,
'title' => $title
);
} else {
$jsonreturn = array(
'data' => null,
'title' => 'No Data'
);
}
header("Content-type: text/json");
echo json_encode($jsonreturn);
?>
Codice: Seleziona tutto
ps aux | grep pooler485
ps aux | grep sdm120c
Codice: Seleziona tutto
sdm120c -a 2 -P N -b 2400 -w10 -z3 -j5 /dev/ttyUSB0
Visitano il forum: Nessuno e 1 ospite