Hallo und Guten Abend,
ich verzweifle derzeit ein wenig, da ich meine Visualisierung des Windmessers nicht zum laufen bekomme. Ich hoffe hier kann mir einer helfen bzw. Denk-/Umsetzungsanstöße geben.
Vorne weg als "Einweisung".
Ich besitze einen Windmesser TX20 welche Windgeschwindigkeit und Windrichtung misst.
Diese Werte werden von einem Wemos D1 mini alle 10 Sekunden (der dann derzeitige IST-Wert) abgegriffen und per WLAN an ein PHP-Script übergeben welches die Werte "umrechnet" und in eine MySQL-Datenbank Schreibt.
Das alles funktioniert jetzt seit knapp 5 Wochen Anstandslos (ich habe ~320.000 Datensätze).
Die Werte die in der Datenbank ankommen sind:
Nun möchte ich zur Visualisierung die "Wind rose" von Highcharts verwenden.
Doch leider sind in der "Beispieldatei" nur fixe Werte eingetragen und kein Beispiel wie man es aus SQL rausbekommt...
ich hatte mit jemandem Kontakt der davon Ahnung hatte, derjenige hat mir seine Konfig geschickt, welche ich angepasst habe, aber irgendwie nicht richtig, es funktioniert ja nicht...
im Prinzip möchte ich in der Chart die Werte "ms" = Meter die Sekunde und "namewindrichtung" = Windrichtung sehen.
datamysql.php - in rose.php (s.u.) per include eingebunden
rose.php - welche im Prinzip aufgerufen wird
Kann mir jemand helfen und sagen warum keine Werte rauspurzeln?
kurzer Auszug aus den Fehlern:
Vielen Dank und einen schönen Abend!
ich verzweifle derzeit ein wenig, da ich meine Visualisierung des Windmessers nicht zum laufen bekomme. Ich hoffe hier kann mir einer helfen bzw. Denk-/Umsetzungsanstöße geben.
Vorne weg als "Einweisung".
Ich besitze einen Windmesser TX20 welche Windgeschwindigkeit und Windrichtung misst.
Diese Werte werden von einem Wemos D1 mini alle 10 Sekunden (der dann derzeitige IST-Wert) abgegriffen und per WLAN an ein PHP-Script übergeben welches die Werte "umrechnet" und in eine MySQL-Datenbank Schreibt.
Das alles funktioniert jetzt seit knapp 5 Wochen Anstandslos (ich habe ~320.000 Datensätze).
Die Werte die in der Datenbank ankommen sind:
- Zeit [Format: JJJJ-MM-DD hh:mm:ss]
- ms [Format: Numerisch von 0.0 - 51.1]
- kmh [Format: Numerisch 0.00 - 183.96]
- namewindrichtung [Format: 1-3 Buchstaben z.B. S,SW,SSW)
Nun möchte ich zur Visualisierung die "Wind rose" von Highcharts verwenden.
Doch leider sind in der "Beispieldatei" nur fixe Werte eingetragen und kein Beispiel wie man es aus SQL rausbekommt...
ich hatte mit jemandem Kontakt der davon Ahnung hatte, derjenige hat mir seine Konfig geschickt, welche ich angepasst habe, aber irgendwie nicht richtig, es funktioniert ja nicht...
im Prinzip möchte ich in der Chart die Werte "ms" = Meter die Sekunde und "namewindrichtung" = Windrichtung sehen.
datamysql.php - in rose.php (s.u.) per include eingebunden
Code:
<?php // ################################################################## // MYSQL // ################################################################## //connection information //address of the server where db is installed $servername = "localhost"; //username to connect to the db //the default value is root $username = "NameDesBenutzers"; //password to connect to the db //this is the value you specified during installation of WAMP stack $password = "Passwort"; //name of the db under which the table is created $dbName = "tx20"; //name of the port where we have sqldb $port = 3306; //establishing the connection to the db. $conn = new mysqli($servername, $username, $password, $dbName, $port); //checking if there were any error during the last connection attempt if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // ################################################################## // alle messungen // ################################################################## $sql = "SELECT COUNT(*) as count from windsensor WHERE (rec_date = curdate()) "; $result = $conn->query($sql); if ($result->num_rows>0){ while($row=$result->fetch_assoc()){ $countalle = $row["count"]; } } $array = array(" N","NNO"," NO","ONO"," O","OSO"," SO","SSO"," S","SSW"," SW","WSW"," W","WNW"," NW","NNW"); foreach($array AS $richtung) { if ($richtung == "NNO" or $richtung == "ONO" or $richtung == "WNW" or $richtung == "NNW" or $richtung == "WSW"or $richtung == "OSO"or $richtung == "SSO" or $richtung == "SSW" ) { echo "<tr nowrap bgcolor=\"#DDDDDD\">\n"; } else { echo "<tr nowrap>\n"; } echo "<td class=\"dir\">",str_replace(' ','',$richtung),"</td>\n"; // ################################################################## // count < 2km // ################################################################## $sql = "SELECT COUNT(*) as count from windsensor WHERE (rec_date = curdate()) and (namewindrichtung = '$richtung') and (ms < '2') "; $result = $conn->query($sql); if ($result->num_rows>0){ while($row=$result->fetch_assoc()){ $count = $row["count"]; } $percent = sprintf("%4.2f", (($count/$countalle)*100)); echo "<td class=\"data\">",$percent,"</td> \n"; } // ################################################################## // count >2km <5km // ################################################################## $sql = "SELECT COUNT(*) as count from windsensor WHERE (rec_date = curdate()) and (namewindrichtung = '$richtung') and (ms >= '2')and (ms < '5')" ; $result = $conn->query($sql); if ($result->num_rows>0){ while($row=$result->fetch_assoc()){ $count = $row["count"]; } $percent = sprintf("%4.2f", (($count/$countalle)*100)); echo "<td class=\"data\">",$percent,"</td> \n"; } // ################################################################## // count >5km <10km // ################################################################## $sql = "SELECT COUNT(*) as count from windsensor WHERE (rec_date = curdate()) and (namewindrichtung = '$richtung') and (ms >= '5')and (ms < '10')" ; $result = $conn->query($sql); if ($result->num_rows>0){ while($row=$result->fetch_assoc()){ $count = $row["count"]; } $percent = sprintf("%4.2f", (($count/$countalle)*100)); echo "<td class=\"data\">",$percent,"</td> \n"; } // ################################################################## // count >10km <15km // ################################################################## $sql = "SELECT COUNT(*) as count from windsensor WHERE (rec_date = curdate()) and (namewindrichtung = '$richtung') and (ms >= '10')and (ms < '15')" ; $result = $conn->query($sql); if ($result->num_rows>0){ while($row=$result->fetch_assoc()){ $count = $row["count"]; } } $percent = sprintf("%4.2f", (($count/$countalle)*100)); echo "<td class=\"data\">",$percent,"</td> \n"; // ################################################################## // count >15km <20km // ################################################################## $sql = "SELECT COUNT(*) as count from windsensor WHERE (rec_date = curdate()) and (namewindrichtung = '$richtung') and (ms >= '15')and (ms < '20')" ; $result = $conn->query($sql); if ($result->num_rows>0){ while($row=$result->fetch_assoc()){ $count = $row["count"]; } } $percent = sprintf("%4.2f", (($count/$countalle)*100)); echo "<td class=\"data\">",$percent,"</td> \n"; // ################################################################## // count >20km <30km // ################################################################## $sql = "SELECT COUNT(*) as count from windsensor WHERE (rec_date = curdate()) and (namewindrichtung = '$richtung') and (ms >= '20')and (ms < '30')" ; $result = $conn->query($sql); if ($result->num_rows>0){ while($row=$result->fetch_assoc()){ $count = $row["count"]; } } $percent = sprintf("%4.2f", (($count/$countalle)*100)); echo "<td class=\"data\">",$percent,"</td> \n"; // ################################################################## // count >30km // ################################################################## $sql = "SELECT COUNT(*) as count from windsensor WHERE (rec_date = curdate()) and (namewindrichtung = '$richtung') and (ms >= '30')" ; $result = $conn->query($sql); if ($result->num_rows>0){ while($row=$result->fetch_assoc()){ $count = $row["count"]; } } $percent = sprintf("%4.2f", (($count/$countalle)*100)); echo "<td class=\"data\">",$percent,"</td> \n"; // ################################################################## // count alle messungen der richtung // ################################################################## $sql = "SELECT COUNT(*) as count from windsensor WHERE (rec_date = curdate()) and (namewindrichtung = '$richtung' )"; $result = $conn->query($sql); if ($result->num_rows>0){ while($row=$result->fetch_assoc()){ $count = $row["count"]; } $percent = sprintf("%4.2f", (($count/$countalle)*100)); echo "<td class=\"data\">",$percent,"</td> \n"; echo "</tr>\n"; } } ?>
Code:
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Wind Rose</title> <style type="text/css"> </style> </head> <body> <script src="/code/highcharts.js"></script> <script src="/code/highcharts-more.js"></script> <script src="/code/modules/data.js"></script> <script src="/code/modules/exporting.js"></script> <!-- <div id="container" style="min-width: 420px; max-width: 600px; height: 400px; margin: 0 auto"></div> --> <div id="container" style="min-width: 520px; max-width: 800px; height: 500px; margin: 0 auto"></div> <div style="display:none"> <!-- Source: http://or.water.usgs.gov/cgi-bin/grapher/graph_windrose.pl --> <table id="freq" border="0" cellspacing="0" cellpadding="0"> <tr nowrap bgcolor="#CCCCFF"> <th colspan="9" class="hdr">Tabelle der Windhäufigkeiten in %</th> </tr> <tr nowrap bgcolor="#CCCCFF"> <th class="freq">Direction</th> <th class="freq">< 0.5 m/s</th> <th class="freq">0.5-2 m/s</th> <th class="freq">2-4 m/s</th> <th class="freq">4-6 m/s</th> <th class="freq">6-8 m/s</th> <th class="freq">8-10 m/s</th> <th class="freq">> 10 m/s</th> <th class="freq">Total</th> </tr> <?php include ("datamysql.php"); ?> <tr nowrap> <td class="totals">Total</td> <td class="totals">25.53</td> <td class="totals">44.54</td> <td class="totals">15.07</td> <td class="totals">8.52</td> <td class="totals">4.31</td> <td class="totals">1.81</td> <td class="totals">0.23</td> <td class="totals"> </td> </tr> </table> </div> <script type="text/javascript"> // Parse the data from an inline table using the Highcharts Data plugin Highcharts.chart('container', { data: { table: 'freq', startRow: 1, endRow: 17, endColumn: 7 }, chart: { polar: true, type: 'column', renderTo: 'rose', reflow: false }, title: { text: 'Windanalyse der Wetterstation Berlin Alt-Glienicke' }, subtitle: { text: 'heutige Daten ab 0h' }, pane: { size: '85%' }, loading: { labelStyle: {top: '25%'} }, legend: { reversed: true, align: 'right', verticalAlign: 'top', y: 100, layout: 'vertical' }, yAxis: { // min: 0, endOnTick: true, showLastLabel: true, title: { text: 'Häufigkeit (%)' }, labels: { formatter: function () { return this.value + '%'; } }, reversedStacks: false }, yAxis: { min: -3, minRange: 20, endOnTick: false, startOnTick: false, showLastLabel: true, showFirstLabel: true, title: { text: 'Häufigkeit (%)' }, labels: { formatter: function () { return this.value + '%'; }, distance: 0 }, plotBands: { from: -99, to: 0, color: '#FCFFC5', zIndex: 3 } }, tooltip: { positioner: function () { return { x: 620, y: 300 }; }, useHTML: true, headerFormat: '{point.key}<table>', pointFormat: '<tr><td style="background: #fff"><span style="color:{series.color}">\u25CF</span>{series.name}:</td>' + '<td style="text-align: right; background: #fff"><b>{point.y}%</b></td></tr>', footerFormat: '</table>', shared: true, valueDecimals: 0 }, plotOptions: { series: { stacking: 'normal', shadow: false, groupPadding: 0, pointPlacement: 'on', borderWidth: 0 } } }); </script> </body> </html>
kurzer Auszug aus den Fehlern:
Code:
Trying to get property 'num_rows' of non-object in C:\xampp\htdocs\TX20\datamysql.php on line 32 Undefined variable: count in C:\xampp\htdocs\TX20\datamysql.php on line 115 Undefined variable: countalle in C:\xampp\htdocs\TX20\datamysql.php on line 115 Division by zero in C:\xampp\htdocs\TX20\datamysql.php on line 115
Kommentar