Advertisement
sergiocntr

Untitled

Dec 30th, 2024
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 14.64 KB | None | 0 0
  1. <?php
  2. require("config.php");
  3.  
  4. $link = mysqli_connect($server, $user, $pwd, $db);
  5. if (mysqli_connect_errno()) {
  6.   printf("Connect failed: %s\n", mysqli_connect_error());
  7.   exit();
  8. }
  9.  
  10. // Function to get min, max, and corresponding time for a specific column
  11. function getMinMaxTime($link, $column, $value)
  12. {
  13.   $sql = "SELECT time(`TIMESTAMP_LOCAL`) AS mytime FROM METEO WHERE `$column` = ? ORDER BY `TIMESTAMP_LOCAL` DESC LIMIT 1";
  14.   $stmt = mysqli_prepare($link, $sql);
  15.   mysqli_stmt_bind_param($stmt, 's', $value);
  16.   mysqli_stmt_execute($stmt);
  17.   $result = mysqli_stmt_get_result($stmt);
  18.   $row = mysqli_fetch_array($result, MYSQLI_ASSOC);
  19.   mysqli_free_result($result);
  20.   return $row ? $row['mytime'] : null;
  21. }
  22.  
  23. // Get last measurement
  24. $sql = "SELECT * FROM METEO ORDER BY `TIMESTAMP_LOCAL` DESC LIMIT 1";
  25. $result = mysqli_query($link, $sql);
  26. $row = mysqli_fetch_array($result, MYSQLI_ASSOC);
  27. mysqli_free_result($result);
  28. $last_measure = $row['TIMESTAMP_LOCAL'];
  29. $temp_out = $row['TEMP'];
  30. $pressure = $row['PRESSURE'];
  31. $umidity = $row['HUM'];
  32. $dew_point = $row['DEW_POINT'];
  33. $hdex = $row['HDEX'];
  34. $voltage = $row['voltage'];
  35.  
  36. // Get min/max values for the day
  37. $sql = "SELECT
  38.            MIN(TEMP) AS min_temp, MAX(TEMP) AS max_temp,
  39.            MIN(PRESSURE) AS min_press, MAX(PRESSURE) AS max_press,
  40.            MIN(DEW_POINT) AS min_dp, MAX(DEW_POINT) AS max_dp,
  41.            MIN(HUM) AS min_hum, MAX(HUM) AS max_hum,
  42.            MIN(HDEX) AS min_humidex, MAX(HDEX) AS max_humidex
  43.        FROM METEO WHERE timestamp_local >= CURDATE()";
  44. $result = mysqli_query($link, $sql);
  45. $row = mysqli_fetch_array($result, MYSQLI_ASSOC);
  46. mysqli_free_result($result);
  47.  
  48. $TempOutMin = $row['min_temp'];
  49. $TempOutMax = $row['max_temp'];
  50. $UmOutMin = $row['min_hum'];
  51. $UmOutMax = $row['max_hum'];
  52. $PressureMin = $row['min_press'];
  53. $PressureMax = $row['max_press'];
  54. $dp_min = $row['min_dp'];
  55. $dp_max = $row['max_dp'];
  56. $hd_min = $row['min_humidex'];
  57. $hd_max = $row['max_humidex'];
  58.  
  59. // Get times for min/max values using the function
  60. $ttimelow = getMinMaxTime($link, 'TEMP', $TempOutMin);
  61. $ttimemax = getMinMaxTime($link, 'TEMP', $TempOutMax);
  62. $ptimelow = getMinMaxTime($link, 'PRESSURE', $PressureMin);
  63. $ptimemax = getMinMaxTime($link, 'PRESSURE', $PressureMax);
  64. $htimelow = getMinMaxTime($link, 'HUM', $UmOutMin);
  65. $htimemax = getMinMaxTime($link, 'HUM', $UmOutMax);
  66. $dptimelow = getMinMaxTime($link, 'DEW_POINT', $dp_min);
  67. $dptimemax = getMinMaxTime($link, 'DEW_POINT', $dp_max);
  68. $hxtimelow = getMinMaxTime($link, 'HDEX', $hd_min);
  69. $hxtimemax = getMinMaxTime($link, 'HDEX', $hd_max);
  70.  
  71. mysqli_close($link);
  72. ?>
  73.  
  74. <!DOCTYPE html>
  75.  
  76. <head>
  77.   <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  78.   <link href="https://fonts.googleapis.com/css?family=Indie+Flower" rel="stylesheet">
  79.   <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  80.   <link rel="stylesheet" type="text/css" href="css/ddimgtooltip.css" />
  81.   <link rel="stylesheet" href="css/gauges-ss.1.css">
  82.   <style type="text/css">
  83.     a.button {
  84.       appearance: button;
  85.       text-decoration: none;
  86.       color: initial;
  87.     }
  88.  
  89.     .tg {
  90.     border-collapse: collapse;
  91.     background-color: #f0f0f0; /* Imposta uno sfondo chiaro */
  92. }
  93.  
  94.     .tg td,
  95.     .tg th {
  96.       font-family: 'Indie Flower', cursive;
  97.       font-size: 24px;
  98.       padding: 7px 5px;
  99.       border-style: solid;
  100.       border-width: 3px;
  101.     }
  102.  
  103.     .tg .tg-8n5p {
  104.       font-size: 20px;
  105.       background-color: #656565;
  106.     }
  107.  
  108.     .container {
  109.       display: flex;
  110.       justify-content: space-between;
  111.     }
  112.   </style>
  113.   <title>MeteoFeletto Dashboard</title>
  114. </head>
  115.  
  116. <body onload="init()">
  117.   <h3 style="color:white"><?php echo "Last measure - " . $last_measure; ?></h3>
  118.   <div class="container">
  119.     <table class="tg">
  120.       <tr>
  121.         <th class="tg-8n5p"></th>
  122.         <th class="tg-8n5p">MIN</th>
  123.         <th class="tg-8n5p">MAX</th>
  124.       </tr>
  125.       <tr>
  126.         <td class="tg-ndw9" rowspan="2">Temp. °C</td>
  127.         <td class="tg-ndw9"><?php echo $TempOutMin; ?></td>
  128.         <td class="tg-ndw9"><?php echo $TempOutMax; ?></td>
  129.       </tr>
  130.       <tr>
  131.         <td class="tg-4na0"><?php echo $ttimelow; ?></td>
  132.         <td class="tg-4na0"><?php echo $ttimemax; ?></td>
  133.       </tr>
  134.       <tr>
  135.         <td class="tg-ndw9" rowspan="2">Humidity RH%</td>
  136.         <td class="tg-ndw9"><?php echo $UmOutMin; ?></td>
  137.         <td class="tg-ndw9"><?php echo $UmOutMax; ?></td>
  138.       </tr>
  139.       <tr>
  140.         <td class="tg-4na0"><?php echo $htimelow; ?></td>
  141.         <td class="tg-4na0"><?php echo $htimemax; ?></td>
  142.       </tr>
  143.       <tr>
  144.         <td class="tg-ndw9" rowspan="2">Pressure hPa</td>
  145.         <td class="tg-ndw9"><?php echo $PressureMin; ?></td>
  146.         <td class="tg-ndw9"><?php echo $PressureMax; ?></td>
  147.       </tr>
  148.       <tr>
  149.         <td class="tg-4na0"><?php echo $ptimelow; ?></td>
  150.         <td class="tg-4na0"><?php echo $ptimemax; ?></td>
  151.       </tr>
  152.       <tr>
  153.         <td class="tg-ndw9" rowspan="2">Dew Point °C</td>
  154.         <td class="tg-ndw9"><?php echo $dp_min; ?></td>
  155.         <td class="tg-ndw9"><?php echo $dp_max; ?></td>
  156.       </tr>
  157.       <tr>
  158.         <td class="tg-4na0"><?php echo $dptimelow; ?></td>
  159.         <td class="tg-4na0"><?php echo $dptimemax; ?></td>
  160.       </tr>
  161.       <tr>
  162.         <td class="tg-ndw9" rowspan="2">App.Temp °C</td>
  163.         <td class="tg-ndw9"><?php echo $hd_min; ?></td>
  164.         <td class="tg-ndw9"><?php echo $hd_max; ?></td>
  165.       </tr>
  166.       <tr>
  167.         <td class="tg-4na0"><?php echo $hxtimelow; ?></td>
  168.         <td class="tg-4na0"><?php echo $hxtimemax; ?></td>
  169.       </tr>
  170.     </table>
  171.     <div class="row">
  172.  
  173.       <div id="tip_0" class="gauge" rel="imgtip[0]">
  174.         <canvas id="canvas_temp" class="gaugeSizeStd"></canvas>
  175.       </div>
  176.       <div id="tip_1" class="gauge" rel="imgtip[1]">
  177.         <canvas id="canvas_hum" class="gaugeSizeStd"></canvas>
  178.       </div>
  179.       <div id="tip_2" class="gauge" rel="imgtip[2]">
  180.         <canvas id="canvas_dew" class="gaugeSizeStd"></canvas>
  181.       </div>
  182.     </div>
  183.  
  184.     <div class="row">
  185.       <div id="tip_3" class="gauge" rel="imgtip[3]">
  186.         <canvas id="canvas_hdex" class="gaugeSizeStd"></canvas>
  187.       </div>
  188.       <div id="tip_4" class="gauge" rel="imgtip[4]">
  189.         <canvas id="canvas_baro" class="gaugeSizeStd"></canvas>
  190.       </div>
  191.       <div id="tip_2" class="gauge" rel="imgtip[5]">
  192.         <canvas id="canvas_volt" class="gaugeSizeStd"></canvas>
  193.       </div>
  194.     </div>
  195.   </div>
  196.   <div class="row">
  197.     <a href="meteograph.php?grafico=pressure" class="btn btn-primary">week pressure</a>
  198.     <a href="meteograph.php?grafico=humidity" class="btn btn-primary">week humidity</a>
  199.     <a href="meteograph.php?grafico=temperature" class="btn btn-primary">week temp</a>
  200.     <a href="meteograph.php?grafico=voltage" class="btn btn-primary">week volt</a>
  201.   </div>
  202.   <div class="row">
  203.     <a href="swpi_plot_energy.php" class="btn btn-primary">today power</a>
  204.  
  205.     <a href="swpi_plot_amp.php" class="btn btn-primary">today amp</a>
  206.     <a href="swpi_plot_volt.php" class="btn btn-primary">today volt</a>
  207.     <a href="swpi_plot_cospi.php" class="btn btn-primary">today cospi</a>
  208.  
  209.   </div>
  210.  
  211.   <?php
  212.   if (empty($_POST['DATE'])) {
  213.     $data = date("d-m-Y");
  214.   } else {
  215.     $data = $_POST['DATE'];
  216.   }
  217.   //echo "reqdate = '".$data."';";
  218.  
  219.   ?>
  220.  
  221.   <script>
  222.     var scroll = false;
  223.     var tempGauge;
  224.     var pressureGauge;
  225.     var umidityGauge;
  226.     var dewGauge;
  227.     var hdexGauge;
  228.  
  229.     function init() {
  230.       const voltsections = [
  231.         steelseries.Section(3900, 4050, 'rgba(255, 0, 0, 0.9)'),
  232.         steelseries.Section(4050, 4300, 'rgba(0, 255, 0, 0.6)'),
  233.         steelseries.Section(4300, 4600, 'rgba(34,139,34, 0.6)')
  234.       ];
  235.       const tempsections = [steelseries.Section(-20, -5, 'rgba(0, 0, 220, 0.6)'),
  236.         steelseries.Section(-5, 15, 'rgba(153, 255, 255, 0.6)'),
  237.         steelseries.Section(15, 25, 'rgba(0, 220, 0, 0.6)'),
  238.         steelseries.Section(25, 35, 'rgba(255, 128, 0, 0.6)'),
  239.         steelseries.Section(35, 50, 'rgba(255, 0, 0, 0.9)')
  240.       ];
  241.       const dewsections = [steelseries.Section(-20, -5, 'rgba(0, 0, 220, 0.6)'),
  242.         steelseries.Section(-5, 10, 'rgba(153, 255, 255, 0.6)'),
  243.         steelseries.Section(10, 12, 'rgba(0, 220, 0, 0.6)'),
  244.         steelseries.Section(12, 16, 'rgba(255, 128, 0, 0.6)'),
  245.         steelseries.Section(16, 18, 'rgba(255, 0, 0, 0.9)'),
  246.         steelseries.Section(18, 21, 'rgba(153, 255, 255, 0.6)'),
  247.         steelseries.Section(21, 24, 'rgba(0, 220, 0, 0.6)'),
  248.         steelseries.Section(24, 26, 'rgba(255, 128, 0, 0.6)'),
  249.         steelseries.Section(26, 28, 'rgba(255, 0, 0, 0.9)')
  250.       ];
  251.       const humiditysections = [steelseries.Section(0, 20, 'rgba(255, 0, 0, 0.6)'),
  252.         steelseries.Section(20, 40, 'rgba(255, 128, 0, 0.6)'),
  253.         steelseries.Section(40, 60, 'rgba(0, 220, 0, 0.6)'),
  254.  
  255.         steelseries.Section(60, 80, 'rgba(153, 255, 255, 0.6)'),
  256.         steelseries.Section(80, 100, 'rgba(0, 0, 220, 0.9)')
  257.       ];
  258.       const humsections = [steelseries.Section(15, 20, 'rgba(153, 255, 255, 0.6)'),
  259.         steelseries.Section(20, 30, 'rgba(0, 220, 0, 0.6)'),
  260.         steelseries.Section(30, 40, 'rgba(255, 125, 125, 0.6)'),
  261.         steelseries.Section(40, 45, 'rgba(255, 128, 0, 0.6)'),
  262.         steelseries.Section(45, 50, 'rgba(255, 0, 0, 0.6)')
  263.       ];
  264.       const sectionsPressute = [steelseries.Section(970, 990, 'rgba(0, 0, 220, 0.6)'),
  265.         steelseries.Section(990, 1000, 'rgba(0, 110, 110, 0.6)'),
  266.         steelseries.Section(1000, 1013, 'rgba(0, 155, 75, 0.6)'),
  267.         steelseries.Section(1013, 1020, 'rgba(0, 255, 0, 0.6)'),
  268.         steelseries.Section(1020, 1030, 'rgba(220, 220, 0, 0.6)'),
  269.         steelseries.Section(1030, 1040, 'rgba(255, 128, 0, 0.6)')
  270.       ];
  271.       umidityGauge = new steelseries.Radial('canvas_hum', {
  272.         gaugeType: steelseries.GaugeType.TYPE4,
  273.         size: 210,
  274.         section: humiditysections,
  275.         minMeasuredValueVisible: true,
  276.         maxMeasuredValueVisible: true,
  277.         thresholdVisible: false,
  278.         titleString: 'Umidity',
  279.         unitString: '%',
  280.         lcdVisible: true
  281.       });
  282.       pressureGauge = new steelseries.Radial('canvas_baro', {
  283.         gaugeType: steelseries.GaugeType.TYPE4,
  284.         minMeasuredValueVisible: true,
  285.         maxMeasuredValueVisible: true,
  286.         size: 201,
  287.         section: sectionsPressute,
  288.         useSectionColors: true,
  289.         titleString: 'Pressure',
  290.         unitString: 'hPa',
  291.         lcdVisible: true,
  292.         minValue: 970,
  293.         maxValue: 1040
  294.       });
  295.       tempGauge = new steelseries.Radial('canvas_temp', {
  296.         size: 210,
  297.         minValue: -15,
  298.         maxValue: 50,
  299.         section: tempsections,
  300.         gaugeType: steelseries.GaugeType.TYPE4,
  301.         minMeasuredValueVisible: true,
  302.         maxMeasuredValueVisible: true,
  303.         thresholdVisible: false,
  304.         titleString: "Temperature",
  305.         unitString: "C",
  306.         lcdVisible: true
  307.       });
  308.       hdexGauge = new steelseries.Radial('canvas_hdex', {
  309.         size: 210,
  310.         minValue: -15,
  311.         maxValue: 50,
  312.         section: tempsections,
  313.         gaugeType: steelseries.GaugeType.TYPE4,
  314.         minMeasuredValueVisible: true,
  315.         maxMeasuredValueVisible: true,
  316.         thresholdVisible: false,
  317.         titleString: "Humidex",
  318.         unitString: "",
  319.         lcdVisible: true
  320.       });
  321.       dewGauge = new steelseries.Radial('canvas_dew', {
  322.         size: 210,
  323.         minValue: -15,
  324.         maxValue: 30,
  325.         section: dewsections,
  326.         gaugeType: steelseries.GaugeType.TYPE4,
  327.         setFrameDesign: steelseries.FrameDesign.TILTED_GRAY,
  328.         minMeasuredValueVisible: true,
  329.         maxMeasuredValueVisible: true,
  330.         thresholdVisible: false,
  331.         titleString: "Dew Point",
  332.         unitString: "C",
  333.         lcdVisible: true
  334.       });
  335.       voltGauge = new steelseries.Radial('canvas_volt', {
  336.         size: 210,
  337.         minValue: 3950,
  338.         maxValue: 4600,
  339.         section: voltsections,
  340.         gaugeType: steelseries.GaugeType.TYPE4,
  341.         setFrameDesign: steelseries.FrameDesign.TILTED_GRAY,
  342.         minMeasuredValueVisible: true,
  343.         maxMeasuredValueVisible: true,
  344.         thresholdVisible: false,
  345.         titleString: "Battery",
  346.         unitString: "mV",
  347.         lcdVisible: true
  348.       });
  349.       tempGauge.setFrameDesign(steelseries.FrameDesign.TILTED_GRAY);
  350.       pressureGauge.setFrameDesign(steelseries.FrameDesign.TILTED_GRAY);
  351.       umidityGauge.setFrameDesign(steelseries.FrameDesign.TILTED_GRAY);
  352.       //dewGauge.setFrameDesign(steelseries.FrameDesign.TILTED_GRAY);
  353.       hdexGauge.setFrameDesign(steelseries.FrameDesign.TILTED_GRAY);
  354.  
  355.       tempGauge.setBackgroundColor(steelseries.BackgroundColor.LIGHT_GRAY);
  356.       pressureGauge.setBackgroundColor(steelseries.BackgroundColor.LIGHT_GRAY);
  357.       umidityGauge.setBackgroundColor(steelseries.BackgroundColor.LIGHT_GRAY);
  358.       dewGauge.setBackgroundColor(steelseries.BackgroundColor.LIGHT_GRAY);
  359.       hdexGauge.setBackgroundColor(steelseries.BackgroundColor.LIGHT_GRAY);
  360.       voltGauge.setBackgroundColor(steelseries.BackgroundColor.LIGHT_GRAY);
  361.  
  362.       tempGauge.setValueAnimated(<?php echo $temp_out; ?>);
  363.       tempGauge.setMinMeasuredValue(<?php echo $TempOutMin; ?>);
  364.       tempGauge.setMaxMeasuredValue(<?php echo $TempOutMax; ?>);
  365.  
  366.       pressureGauge.setValueAnimated(<?php echo $pressure; ?>);
  367.       pressureGauge.setMinMeasuredValue(<?php echo $PressureMin; ?>);
  368.       pressureGauge.setMaxMeasuredValue(<?php echo $PressureMax; ?>);
  369.  
  370.       umidityGauge.setValueAnimated(<?php echo $umidity; ?>);
  371.       umidityGauge.setMinMeasuredValue(<?php echo $UmOutMin; ?>);
  372.       umidityGauge.setMaxMeasuredValue(<?php echo $UmOutMax; ?>);
  373.  
  374.       dewGauge.setValueAnimated(<?php echo $dew_point; ?>);
  375.       dewGauge.setMinMeasuredValue(<?php echo $dp_min; ?>);
  376.       dewGauge.setMaxMeasuredValue(<?php echo $dp_max; ?>);
  377.  
  378.       hdexGauge.setValueAnimated(<?php echo $hdex; ?>);
  379.       hdexGauge.setMinMeasuredValue(<?php echo $hd_min; ?>);
  380.       hdexGauge.setMaxMeasuredValue(<?php echo $hd_max; ?>);
  381.  
  382.       voltGauge.setValueAnimated(<?php echo $voltage; ?>);
  383.     }
  384.   </script>
  385.   <script src="http://code.jquery.com/jquery-1.3.2.min.js"></script>
  386.   <script src="js/gauges.js"></script>
  387.   <script src="js/tween-min.js"></script>
  388.   <script src="js/steelseries-min.js"></script>
  389.   <script type="text/javascript" src="js/ddimgtooltip1.js"></script>
  390.   <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
  391.   <script type="text/javascript" src="js/jquery-ui-1.7.2.custom.min.js"></script>
  392.  
  393. </body>
  394. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement