Advertisement
Guest User

Untitled

a guest
Sep 27th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #!/usr/bin/php
  2. <?php
  3.  
  4. $temp = 0;
  5. $user = "admin";
  6. $pass = "password";
  7. $url = "http://192.168.179.65:8080/api/variables/AquaTemp30";
  8. //$path = "/sys/bus/w1/devices/28-031581ad77ff/w1_slave";
  9. $path = "/sys/bus/w1/devices/28-0316818876ff/w1_slave";
  10. $sensdata = fopen($path, "r") or die("Unable to get Sesnsor Data");
  11. while(!feof($sensdata)){
  12. $line = fgets($sensdata);
  13. //preg_match("/([0-9a-f]{2} ){9}: crc=[0-9a-f]{2} YES/", $line, $out_crc);
  14. preg_match("/([0-9a-f]{2} ){9}t=([+-]?[0-9]+)/", $line, $out_temp);
  15. if(!empty($out_temp[2])){
  16. $temp = round($out_temp[2]/1000,1);
  17. }
  18. }
  19. $headers = array('Content-Type: application/json');
  20. $data = '{"type": "value","valueOrExpression": "'.$temp.'"}';
  21. $ch = curl_init();
  22. curl_setopt($ch, CURLOPT_URL, $url);
  23. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  24. curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  25. curl_setopt($ch, CURLOPT_USERPWD, $user.":".$pass);
  26. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
  27. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  28. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  29. $out = curl_exec($ch);
  30. curl_close($ch);
  31. echo $out."\r";
  32.  
  33.  
  34. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement