Teleinfo papp jpgraph.php
De MicElectroLinGenMet.
Page : Démodulateur téléinformation_EDF
<?php // Génére un graphe en image PNG en focntion des donnée téléinfo PAPP de la base MySql. // Puissance apparente en watts HP et HC. // Par Domos. //Librairies JpGraph include ("/var/www/jpgraph/src/jpgraph.php"); include ("/var/www/jpgraph/src/jpgraph_line.php"); // Base de donnée Téléinfo: /* Format de la table: timestamp rec_date rec_time adco optarif isousc hchp hchc ptec inst1 inst2 inst3 imax1 imax2 imax3 pmax papp hhphc motdetat ppot adir1 adir2 adir3 1234998004 2009-02-19 00:00:04 700609361116 HC.. 20 11008467 10490214 HP 1 0 1 18 23 22 8780 400 E 000000 00 0 0 0 1234998065 2009-02-19 00:01:05 700609361116 HC.. 20 11008473 10490214 HP 1 0 1 18 23 22 8780 400 E 000000 00 0 0 0 1234998124 2009-02-19 00:02:04 700609361116 HC.. 20 11008479 10490214 HP 1 0 1 18 23 22 8780 390 E 000000 00 0 0 0 1234998185 2009-02-19 00:03:05 700609361116 HC.. 20 11008484 10490214 HP 1 0 0 18 23 22 8780 330 E 000000 00 0 0 0 1234998244 2009-02-19 00:04:04 700609361116 HC.. 20 11008489 10490214 HP 1 0 0 18 23 22 8780 330 E 000000 00 0 0 0 1234998304 2009-02-19 00:05:04 700609361116 HC.. 20 11008493 10490214 HP 1 0 0 18 23 22 8780 330 E 000000 00 0 0 0 1234998365 2009-02-19 00:06:05 700609361116 HC.. 20 11008498 10490214 HP 1 0 0 18 23 22 8780 320 E 000000 00 0 0 0 */ setlocale ( LC_ALL , "fr_FR" ); // Formatage Date. function TimeCallback($aVal) { return Date('H:i', $aVal); } $periodesecondes = 24*3600 ; // 24h. $heurecourante = date('H') ; // Heure courante. $timestampheure = mktime($heurecourante,0,0,date("m"),date("d"),date("Y")); // Timestamp courant à heure fixe (mn et s à 0). $timestampdebut = $timestampheure - $periodesecondes ; // Recule de 24h. //printf("datedebut : (%s) %s<br \>", $timestampdebut, date("YmdHis", $timestampdebut)) ; // Connexion MySql et requète. $serveur="localhost"; $login="root"; $base="maison"; $fd = fopen ("./mysql.txt", "r"); $pass = rtrim(fgets($fd, 4096)) ; // $pass contient password compte root MySql. fclose ($fd); mysql_connect($serveur, $login, $pass) or die("Erreur de connexion au serveur MySql"); mysql_select_db($base) or die("Erreur de connexion a la base de donnees $base"); $table="teleinfo"; $query="SELECT timestamp, rec_date, rec_time, ptec, papp FROM `$table` WHERE timestamp >= $timestampdebut ORDER BY timestamp DESC" ; $result=mysql_query($query) or die ("<b>Erreur</b> dans la requète <b>" . $query . "</b> : " . mysql_error() . " !<br>"); $num_rows = mysql_num_rows($result) ; $num_rows-- ; while ($row = mysql_fetch_array($result)) { //printf("Timestamp_unix: %s, Date: %s, Heure: %s, ptec: %s, papp: %s <br \>", $row[0], $row["rec_date"], $row["rec_time"], $row["ptec"], $row["papp"]); $timestp[$num_rows] = $row["timestamp"] ; if ( $row["ptec"] == "HP" ) // Test si heures pleines. { $papphp[$num_rows] = $row["papp"] ; $papphc[$num_rows ] = 0 ; } else { $papphp[$num_rows] = 0 ; $papphc[$num_rows] = $row["papp"] ; } $num_rows-- ; } mysql_free_result($result) ; mysql_close() ; //exit(0) ; $date = Date('d/m/Y, H:i', $timestp[count($timestp) -1]) ; // Get start time $start = $timestp[0] ; $end = $timestp[count($timestp) -1] ; // Génération du graphe. $graph = new Graph(800,400); $graph->SetMarginColor('black'); $graph->SetColor('gray1'); $graph->SetMargin(60,40,40,80); $graph->SetScale("intlin",0,$pmax,$start,$end); $graph->title->Set("Puissance électrique apparente le $date"); $graph->title->SetColor("gray7"); $graph->yaxis->title->Set("Watts"); $graph->yaxis->title->SetMargin(20); $graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD); $graph->yaxis->title->SetColor("gray7"); $graph->xaxis->title->Set("24h"); $graph->xaxis->title->SetMargin(30); $graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD); $graph->xaxis->title->SetColor("gray7"); $graph->yaxis->SetColor("gray5","gray7"); $graph->xaxis->SetColor("gray5","gray7"); $graph->ygrid->SetColor("gray5"); $graph->xgrid->Show(true) ; $graph->xgrid->SetColor("gray5"); // Setup the callback and adjust the angle of the labels $graph->xaxis->SetLabelFormatCallback('TimeCallback'); // Set the labels and minor ticks. $graph->xaxis->scale->ticks->Set(7200,1800); // Adjust the legend position $graph->legend->SetLayout(LEGEND_HOR); $graph->legend->Pos(0.05,0.97,"left","bottom"); $linehp = new LinePlot($papphp,$timestp); $linehp->SetColor('red'); $linehp->SetFillColor("red@0.4"); $linehp->SetLegend("HP"); $linehc = new LinePlot($papphc,$timestp); $linehc->SetColor('green'); $linehc->SetFillColor("green@0.4"); $linehc->SetLegend("HC"); $graph->Add($linehp); $graph->Add($linehc); $papp_actuelle=$papphp[count($papphp) -1] + $papphc[count($papphc) -1]; $txt=new Text("Puissance actuelle: $papp_actuelle Watts", 150, 370); $txt->SetColor("gray7"); $graph->AddText($txt); $graph->Stroke(); ?>
