Jannes Peter - 2019-01-24

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.

<!DOCTYPE html>
<html>
<body background="Sturm.jpg">
<head>
<title>Gesamt&uumlbersicht</title>
<meta http-equiv="refresh" content="300;                
URL=http://localhost/index.html"/>
</head>
<p><h1 style="color:white";>Umweltdatenerfassung</h1></p>
<br><br>

<form action="index.php" method="post">
<h style="color:white;">&#8627 Auswahl des Klimaparameters:
<input type="radio"     name="Temp"     value="$Temp"   > Temperatur
<input type="radio"     name="Feuchte"  value="$Feuchte"> Luftfeuchte
<input type="radio"     name="Druck"    value="$Druck"  > Luftdruck
<br><br><br>


<form action="index.php" method="post">
<h style="color:white;">&#8627 Auswahl der R&aumlume:
<select name="Raum">
<option value=" "   >-Bitte Ausw&aumlhlen-</option>
<option value="R103"    >R103</option>
<option value="R104"    >R104</option>
</select><br>
<br></from><br>


<form action="index.php" method="post">
<h style="color:black;">&#8627  Messwerte der letzten:<input   name="Hour"> Stunden</h>
<input type="submit" value="Absenden"><br>
</from>

<?php

//Es wird erst getestet ob die Nachricht verschickt wurde.
Wenn ja wird die If Schleife ausgeführt
if(!empty($_POST))
{
    echo <<<END
<hr>
<p>
<br>
<p><h2 style="color:black">Temperatur und Luftfeuchtigkeit &#9748 im Raum 104</h2></p>

<img src="indexT.php">
<img src="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 LINIENDIAGRAMM
    require 'phplot.php';
    require 'rgb.inc.php';

    //Herstellen der MYSQL-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 = new PHPlot(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 LINIENDIAGRAMM
    require 'phplot.php';
    require 'rgb.inc.php';

    //Herstellen der MYSQL 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_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 = new PHPlot(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 LINIENDIAGRAMM
    require 'phplot.php';
    require 'rgb.inc.php';

    //Herstellen der MYSQL 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_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 = new PHPlot(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();
}

?>
 

Last edit: Jannes Peter 2019-01-24