Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [inne][PHP] Raspberry pi wyświetlanie temperatury
traczu
post 10.02.2016, 11:10:40
Post #1





Grupa: Zarejestrowani
Postów: 19
Pomógł: 0
Dołączył: 15.01.2008
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


Mam mały problem dane z $temp_water niestety źle mi się wyświetlają tzn. wcale
ale w tabeli gdzie jest <td>Temperatura powietrza</td> wyświetla tekstowo tak jak powinno chciałem zaadoptować tą wartość nako temp_water do div-a tempgauge_water
czy powinienem to inaczej zrobić niż inne wartości questionmark.gif
Mógłby ktoś na to zerknąć questionmark.gif

  1. <html>
  2. <head>
  3. <title>AquaPI by Traczu</title>
  4. <meta charset="utf-8" />
  5. <link rel="stylesheet" href="assets/css/main2.css" />
  6. <link rel="stylesheet" href="stylesheets/main.css">
  7. <link rel="stylesheet" href="stylesheets/button.css">
  8. <script src="javascript/raphael.2.1.0.min.js"></script>
  9. <script src="javascript/justgage.1.0.1.min.js"></script>
  10.  
  11. <!--[if lte IE 8]><script src="assets/js/html5shiv.js"></script><![endif]-->
  12. <!--[if lte IE 9]><link rel="stylesheet" href="assets/css/ie9.css" /><![endif]-->
  13. <!--[if lte IE 8]><link rel="stylesheet" href="assets/css/ie8.css" /><![endif]-->
  14. </head>
  15. <body>
  16. <?php session_start();
  17. require_once('db.php');
  18. ?>
  19.  
  20. <?php
  21.  
  22. define(LANGUAGE, "english");
  23.  
  24. $temp_water = shell_exec(' /sys/bus/w1/devices/28-000006db5817/w1_slave');
  25. $temp_water = round($temp_water[1] / 1000, 1);
  26.  
  27. $tempcpu = shell_exec('cat /sys/class/thermal/thermal_zone*/temp');
  28. $tempcpu = round($tempcpu / 1000, 1);
  29.  
  30. $clock = shell_exec('cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq');
  31. $clock = round($clock / 1000);
  32.  
  33. $voltage = shell_exec('/opt/vc/bin/vcgencmd measure_volts');
  34. $voltage = explode("=", $voltage);
  35. $voltage = $voltage[1];
  36. $voltage = substr($voltage,0,-2);
  37.  
  38. $cpuusage = 100 - shell_exec("vmstat | tail -1 | awk '{print $15}'");
  39.  
  40. $uptimedata = shell_exec('uptime');
  41. $uptime = explode(' up ', $uptimedata);
  42. $uptime = explode(',', $uptime[1]);
  43. $uptime = $uptime[0].', '.$uptime[1];
  44.  
  45. include 'localization/'.LANGUAGE.'.lang.php';
  46.  
  47. ?>
  48. <script>
  49. function checkAction(action){
  50. if (confirm('<?php echo TXT_CONFIRM; ?> ' + action + '?'))
  51. {
  52. return true;
  53. }
  54. else
  55. {
  56. return false;
  57. }
  58. }
  59.  
  60. window.onload = doLoad;
  61.  
  62. function doLoad()
  63. {
  64. setTimeout( "refresh()", 30*1000 );
  65. }
  66.  
  67. function refresh()
  68. {
  69. window.location.reload( false );
  70. }
  71. </script>
  72. <!-- Wrapper -->
  73. <div id="wrapper">
  74.  
  75. <!-- Main -->
  76. <section id="main">
  77. <header>
  78. <span class="avatar"><img src="images/aquarium-icon.png" alt="" /></span>
  79.  
  80.  
  81.  
  82.  
  83. </header>
  84.  
  85. <div>
  86.  
  87.  
  88. <div id="lewy">
  89. <p><a href="info.php"><img src="images/info_off.png" alt="" border="0"/></a></p>
  90. <p><a href="light.php"><img src="images/light_off.png" alt="" border="0"/></a></p>
  91. </div>
  92.  
  93. <div id="srodek">
  94. <p><a href="setting.php"><img src="images/setting_off.png" alt="" border="0"/><a href="light.php"></a></p>
  95.  
  96. </div>
  97.  
  98. <div id="prawy">
  99. <p><a href="index.php?logout"><img src="images/power_off.png" alt="" /></a></p>
  100. </div>
  101. <br><br><br>
  102. <table border="0" cellspacing="10" align="center">
  103. <tr>
  104. <td>Temperatura powietrza</td>
  105. <td bgcolor="white">
  106. <?php
  107. //File to read
  108. $file = '/sys/bus/w1/devices/28-000006db5817/w1_slave';
  109.  
  110. //Read the file line by line
  111. $lines = file($file);
  112.  
  113. //Get the temp from second line
  114. $temp2 = explode('=', $lines[1]);
  115.  
  116. //Setup some nice formatting (i.e. 21,3)
  117. $temp2 = number_format($temp2[1] / 1000, 1, ',', '');
  118.  
  119. //And echo that temp
  120. echo $temp2 . " °C";
  121. ?>
  122. </td>
  123. </tr></table>
  124.  
  125. <?php if(isset($temp_water) && is_numeric($temp_water)){ ?>
  126. <div id="tempgauge_water"></div>
  127. <script>
  128. var t = new JustGage({
  129. id: "tempgauge_water",
  130. value: <?php echo $temp_water; ?>,
  131. min: 0,
  132. max: 100,
  133. title: "<?php echo TXT_TEMPERATURE_WATER; ?>",
  134. label: "°C"
  135. });
  136. </script>
  137. <?php } ?>
  138.  
  139.  
  140. <?php if(isset($tempcpu) && is_numeric($tempcpu)){ ?>
  141. <div id="tempgauge"></div>
  142. <script>
  143. var t = new JustGage({
  144. id: "tempgauge",
  145. value: <?php echo $tempcpu; ?>,
  146. min: 0,
  147. max: 100,
  148. title: "<?php echo TXT_TEMPERATURE_CPU; ?>",
  149. label: "°C"
  150. });
  151. </script>
  152. <?php } ?>
  153.  
  154. <?php if(isset($voltage) && is_numeric($voltage)){ ?>
  155. <div id="voltgauge"></div>
  156. <script>
  157. var v = new JustGage({
  158. id: "voltgauge",
  159. value: <?php echo $voltage; ?>,
  160. min: 0.8,
  161. max: 1.4,
  162. title: "<?php echo TXT_VOLTAGE; ?>",
  163. label: "V"
  164. });
  165. </script>
  166. <?php } ?>
  167.  
  168. <?php if(isset($cpuusage) && is_numeric($cpuusage)){ ?>
  169. <div id="cpugauge"></div>
  170. <script>
  171. var u = new JustGage({
  172. id: "cpugauge",
  173. value: <?php echo $cpuusage; ?>,
  174. min: 0,
  175. max: 100,
  176. title: "<?php echo TXT_USAGE; ?>",
  177. label: "%"
  178. });
  179. </script>
  180. <?php } ?>
  181.  
  182. <?php if(isset($clock) && is_numeric($clock)){ ?>
  183. <div id="clockgauge"></div>
  184. <script>
  185. var c = new JustGage({
  186. id: "clockgauge",
  187. value: <?php echo $clock; ?>,
  188. min: 0,
  189. max: 1000,
  190. title: "<?php echo TXT_CLOCK; ?>",
  191. label: "MHz"
  192. });
  193. </script>
  194. <?php } ?>
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201. <?php
  202. $timestamp = time();
  203. $datum = date("Y-m-d (D) H:i:s",$timestamp);
  204. echo "$datum <br>\n";
  205. ?>
  206.  
  207.  
  208.  
  209. </div>
  210.  
  211.  
  212. </div>
  213.  
  214. </div>
  215.  
  216.  
  217. <?php if ($_SESSION['auth'] == TRUE) {
  218. echo '';
  219. }
  220. else {
  221. echo '<meta http-equiv="refresh" content="0; URL=index.php">';
  222. }
  223. ?>
  224.  
  225. </body>
  226. </html>
Go to the top of the page
+Quote Post
mls
post 10.02.2016, 15:31:29
Post #2





Grupa: Zarejestrowani
Postów: 677
Pomógł: 89
Dołączył: 31.08.2003
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


Powinno być:
  1. $temp_water = shell_exec('cat /sys/bus/w1/devices/28-000006db5817/w1_slave');


...chociaż czytanie w ten sposób (poprzez shell_exec) jest moim zdaniem lekką przesadą... wink.gif


--------------------
Go to the top of the page
+Quote Post
traczu
post 10.02.2016, 16:01:08
Post #3





Grupa: Zarejestrowani
Postów: 19
Pomógł: 0
Dołączył: 15.01.2008
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


znalazłem rozwiązanie
trzeba wyciągnąć ostatnią wartość pliku gdzie zawartość jego to:

CODE
a5 01 4b 46 7f ff 0b 10 f7 : crc=f7 YES
a5 01 4b 46 7f ff 0b 10 f7 t=26312


aktualnie pracuję nad rozwiązaniem:

  1. $temp_water = shell_exec('cat /sys/bus/w1/devices/28-000006db5817/w1_slave | grep "t=" | awk '{FS = "t=" ;$0=$0; print $2}'');


Ten post edytował traczu 10.02.2016, 23:30:14
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 26.04.2024 - 06:57