My Code works perfekt. My "C-Code" print all 5 minuts in my SQL-Database datetime, / temperature, / humidity, / air pressure. I have only one problem.
If i asked to many Hours in my SQL Query, take PHPlot all datetime data and plot them down. Can I handle it?
That is my HTML Code for my Webinterface.
<!DOCTYPE html><html><bodybackground="Sturm.jpg"><head><title>Gesamtübersicht</title><metahttp-equiv="refresh"content="300; URL=http://localhost/index.html"/></head><p><h1style="color:white";>Umweltdatenerfassung</h1></p><br><br><formaction="index.php"method="post"><hstyle="color:white;">↳ Auswahl des Klimaparameters:
<inputtype="radio"name="Temp"value="$Temp"> Temperatur
<inputtype="radio"name="Feuchte"value="$Feuchte"> Luftfeuchte
<inputtype="radio"name="Druck"value="$Druck"> Luftdruck
<br><br><br><formaction="index.php"method="post"><hstyle="color:white;">↳ Auswahl der Räume:
<selectname="Raum"><optionvalue=" ">-Bitte Auswählen-</option><optionvalue="R103">R103</option><optionvalue="R104">R104</option></select><br><br></from><br><formaction="index.php"method="post"><hstyle="color:black;">↳ Messwerte der letzten:<inputname="Hour"> Stunden</h><inputtype="submit"value="Absenden"><br></from><?php//Es wird erst getestet ob die Nachricht verschickt wurde.WennjawirddieIfSchleifeausgeführtif(!empty($_POST)){echo<<<END<hr><p><br><p><h2style="color:black">TemperaturundLuftfeuchtigkeit☔ im Raum 104</h2></p><imgsrc="indexT.php"><imgsrc="indexF.php"></body></html>>
That is my PHP Code.
<?php//EINGABEN__________________________________________________________________$Temp=$_POST["Temp"];$Feuchte=$_POST["Feuchte"];$Druck=$_POST["Druck"];if($Temp){$Room=$_POST["Raum"];$Hour=$_POST["Hour"];#TEMPERATUR LINIENDIAGRAMMrequire'phplot.php';require'rgb.inc.php';//HerstellenderMYSQL-Datenverbindung______________________$conn=mysql_connect("localhost","root","******");if(!$conn){echo"Keine Verbindung zur Datenbank möglich: ".mysql_error();exit;}if(!mysql_select_db("UsiEnvironment")){echo"Konnte UsiEnvironment nicht auswählen: ".mysql_error();exit;}//Abfrage_MYSQLDatenbank__________________________________________$sql="SELECT dt,`Temp` FROM `$Room` WHERE DATE_SUB(NOW(),INTERVAL '".$Hour."' HOUR) <=dt ";$data=array();$result=mysql_query($sql,$conn);if(!$result){echo"Konnte Abfrage ($sql) nicht erfolgreich ausführen: ".mysql_error();exit;}if(mysql_num_rows($result)==0){echo"Diese Eingabe war keine Zahl, bitte gehen Sie eine Seite zurück und geben Sie dieses mal eine Zahl ein!";exit;}while($line=mysql_fetch_array($result,MYSQL_ASSOC)){$data[]=array($line['dt'],$line['Temp']);}mysql_free_result($result);#Plot Befehle$plot=newPHPlot(1200,800);$plot->SetImageBorderType('plain');$plot->SetFontGD('x_label',3,1);$plot->SetFontGD('y_label',3,1);$plot->SetFontGD('x_title',5,1);$plot->SetFontGD('y_title',5,1);$plot->SetXScaleType('linear');$plot->SetLineWidths(3);$plot->SetPlotType('lines');$plot->SetDataType('text-data');$plot->SetXLabelAngle(90);$plot->SetDataValues($data);# Main plot title:$plot->SetTitle('Temperatur in Celsius');$plot->SetXTitle('Datum/Uhrzeit');$plot->SetYTitle('Gradzahl');$plot->SetLegend(array('Temperatur'));$plot->SetDataColors(array('SlateBlue','magenta'));# Make sure Y axis starts at 0:$plot->SetPlotAreaWorld(NULL,NULL,NULL,NULL);$plot->DrawGraph();}___________________________________________________________________________if($Feuchte){$Room=$_POST["Raum"];$Hour=$_POST["Hour"];#TEMPERATUR LINIENDIAGRAMMrequire'phplot.php';require'rgb.inc.php';//HerstellenderMYSQLDatenverbindung___________________________$conn=mysql_connect("localhost","root","******");if(!$conn){echo"Keine Verbindung zur Datenbank möglich: ".mysql_error();exit;}if(!mysql_select_db("UsiEnvironment")){echo"Konnte UsiEnvironment nicht auswählen: ".mysql_error();exit;}//Abfrage_MYSQL-Datenbank_________________________________________$sql="SELECT dt,`Feuchte` FROM `$Room` WHERE DATE_SUB(NOW(),INTERVAL '".$Hour."' HOUR) <=dt ";$data=array();$result=mysql_query($sql,$conn);if(!$result){echo"Konnte Abfrage ($sql) nicht erfolgreich ausführen: ".mysql_error();exit;}if(mysql_num_rows($result)==0){echo"Diese Eingabe war keine Zahl, bitte gehen Sie eine Seite zurück und geben Sie dieses Mal eine Zahl ein!";exit;}while($line=mysql_fetch_array($result,MYSQL_ASSOC)){$data[]=array($line['dt'],$line['Feuchte']);}mysql_free_result($result);#Plot Befehle$plot=newPHPlot(1200,800);$plot->SetImageBorderType('plain');$plot->SetFontGD('x_label',3,1);$plot->SetFontGD('y_label',3,1);$plot->SetFontGD('x_title',5,1);$plot->SetFontGD('y_title',5,1);$plot->SetLineWidths(3);$plot->SetPlotType('lines');$plot->SetXDataLabelPos('plotdown');$plot->SetDataType('text-data');$plot->SetXLabelAngle(90);$plot->SetDataValues($data);# Main plot title:$plot->SetTitle('Relative Luftfeuchtigkeit in Prozent');$plot->SetXTitle('Datum/Uhrzeit');$plot->SetYTitle('Prozentzahl');$plot->SetLegend(array('Feuchtigkeit'));$plot->SetDataColors(array('green','magenta'));# Make sure Y axis starts at 0:$plot->SetPlotAreaWorld(NULL,NULL,NULL,NULL);$plot->DrawGraph();}___________________________________________________________________________if($Druck){$Room=$_POST["Raum"];$Hour=$_POST["Hour"];#TEMPERATUR LINIENDIAGRAMMrequire'phplot.php';require'rgb.inc.php';//HerstellenderMYSQLDatenverbindung___________________________$conn=mysql_connect("localhost","root","******");if(!$conn){echo"Keine Verbindung zur Datenbank möglich: ".mysql_error();exit;}if(!mysql_select_db("UsiEnvironment")){echo"Konnte UsiEnvironment nicht auswählen: ".mysql_error();exit;}//Abfrage_MYSQL-Datenbank_________________________________________$sql="SELECT dt,`Druck` FROM `$Room` WHERE DATE_SUB(NOW(),INTERVAL '".$Hour."' HOUR) <=dt ";$data=array();$result=mysql_query($sql,$conn);if(!$result){echo"Konnte Abfrage ($sql) nicht erfolgreich ausführen: ".mysql_error();exit;}if(mysql_num_rows($result)==0){echo"Diese Eingabe war keine Zahl, bitte gehen Sie eine Seite zurück und geben Sie dieses Mal eine Zahl ein!";exit;}while($line=mysql_fetch_array($result,MYSQL_ASSOC)){$data[]=array($line['dt'],$line['Druck']);}mysql_free_result($result);#Plot Befehle$plot=newPHPlot(1200,800);$plot->SetImageBorderType('plain');$plot->SetFontGD('x_label',3,1);$plot->SetFontGD('y_label',3,1);$plot->SetFontGD('x_title',5,1);$plot->SetFontGD('y_title',5,1);$plot->SetLineWidths(3);$plot->SetPlotType('lines');$plot->SetXDataLabelPos('plotdown');$plot->SetDataType('text-data');$plot->SetXLabelAngle(90);$plot->SetDataValues($data);# Main plot title:$plot->SetTitle('Luftdruck in Pascal');$plot->SetXTitle('Datum/Uhrzeit');$plot->SetYTitle('Pascal');$plot->SetLegend(array('Luftdruck'));$plot->SetDataColors(array('magenta','blue'));# Make sure Y axis starts at 0:$plot->SetPlotAreaWorld(NULL,NULL,NULL,NULL);$plot->DrawGraph();}?>
Hello,
My Code works perfekt. My "C-Code" print all 5 minuts in my SQL-Database datetime, / temperature, / humidity, / air pressure. I have only one problem.
If i asked to many Hours in my SQL Query, take PHPlot all datetime data and plot them down. Can I handle it?
That is my HTML Code for my Webinterface.
That is my PHP Code.
Last edit: Jannes Peter 2019-01-24