SHARE
TWEET

Untitled

a guest Oct 21st, 2019 130 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /*
  3. Usage:
  4.   - platform: command_line
  5.     name: foo
  6.     command: "php -f /home/homeassistant/vzapi.php 1"
  7.     unit_of_measurement: "W"
  8.  
  9. Todo:
  10.   - Rewrite in Python
  11.   - Use UUID instead of ID
  12. */
  13.  
  14. if($argc != 2) die('id?');
  15. $sensor = (int)$argv[1];
  16.  
  17. error_reporting(E_ALL);
  18.  
  19. $mysql_serv = 'localhost';
  20. $mysql_user = 'vz-read';
  21. $mysql_pass = '*****';
  22. $mysql_datb = 'volkszaehler';
  23.  
  24. $sql = new mysqli($mysql_serv, $mysql_user, $mysql_pass, $mysql_datb);
  25.  
  26. //Yes, I know this can be used for SQL injections.
  27. $data = $sql->query("SELECT * FROM `data` WHERE `channel_id` = ".$sensor." ORDER BY `timestamp` DESC LIMIT 1 ");
  28. if($data->num_rows != 1) die();
  29. $data = $data->fetch_object();
  30.  
  31. if($data->timestamp/1000 <= time()-300) die();
  32.  
  33. echo $data->value;
  34.  
  35. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top