temperature.plugin.enabled.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /*
  3. @name Temperature DS18B20
  4. @author Arnaud LESUEUR <arnaud.lesueur@gmail.com>
  5. @link https://github.com/alesueur
  6. @licence CC by nc sa
  7. @version 1.0.0
  8. @description Permet de recuperer la temperature d'un capteur de type DS18B20
  9. */
  10. function temperature_plugin_menu(&$menuItems){
  11. global $_;
  12. $menuItems[] = array('sort'=>10,'content'=>'<a href="index.php?module=temperature"><i class="icon-th-large"></i> Temperature</a>');
  13. }
  14. function temperature_plugin_page($_){
  15. if(isset($_['module']) && $_['module']=='temperature'){
  16. ?>
  17. <h1>Capteur de Temperature</h1>
  18. <p>Retourne la temperature d'un capteur DS18B20</p>
  19. <h2>
  20. <?php
  21. echo temperature_get();
  22. ?>
  23. 'C</h2>
  24. <p>Pour le montage a mettre en oeuvre : cela se passe <a href="http://learn.adafruit.com/adafruits-raspberry-pi-lesson-11-ds18b20-temperature-sensing/">ici<a>.</p>
  25. </div>
  26. <?php
  27. }
  28. }
  29. function temperature_vocal_command(&$response,$actionUrl){
  30. global $conf;
  31. $response['commands'][] = array('command'=>$conf->get('VOCAL_ENTITY_NAME').' temperature','url'=>$actionUrl.'?action=temperature_action','confidence'=>'0.88');
  32. }
  33. function temperature_action(){
  34. global $_,$conf;
  35. switch($_['action']){
  36. case 'temperature_action':
  37. global $_;
  38. $affirmation = 'Il fait '.temperature_get().' degres';
  39. $response = array('responses'=>array(array('type'=>'talk','sentence'=>$affirmation)));
  40. $json = json_encode($response);
  41. echo ($json=='[]'?'{}':$json);
  42. break;
  43. }
  44. }
  45. function temperature_get(){
  46. if ($handle = opendir('/sys/bus/w1/devices')) {
  47. while (false !== ($entry = readdir($handle))) {
  48. if(!strncmp($entry, "28-" , strlen("28-"))) {
  49. $filename = "/sys/bus/w1/devices/".$entry."/w1_slave" ;
  50. if (file_exists($filename)) {
  51. $lines = file($filename);
  52. $currenttemp = round ( substr($lines[1], strpos($lines[1], "t=")+2) / 1000 , 1) ;
  53. closedir($handle);
  54. return $currenttemp;
  55. }
  56. }
  57. }
  58. closedir($handle);
  59. }
  60. return "N/A";
  61. }
  62. Plugin::addCss("/css/style.css");
  63. //Plugin::addJs("/js/main.js");
  64. Plugin::addHook("menubar_pre_home", "temperature_plugin_menu");
  65. Plugin::addHook("home", "temperature_plugin_page");
  66. Plugin::addHook("vocal_command", "temperature_vocal_command");
  67. Plugin::addHook("action_post_case", "temperature_action");
  68. ?>