Last active
October 2, 2019 18:51
-
-
Save adlerweb/588fb15b2c100908eed0806905bf16a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Usage: | |
- platform: command_line | |
name: foo | |
command: "php -f /home/homeassistant/vzapi.php 1" | |
unit_of_measurement: "W" | |
Todo: | |
- Rewrite in Python | |
- Use UUID instead of ID | |
*/ | |
if($argc != 2) die('id?'); | |
$sensor = (int)$argv[1]; | |
error_reporting(E_ALL); | |
$mysql_serv = 'localhost'; | |
$mysql_user = 'vz-read'; | |
$mysql_pass = '*****'; | |
$mysql_datb = 'volkszaehler'; | |
$sql = new mysqli($mysql_serv, $mysql_user, $mysql_pass, $mysql_datb); | |
//Yes, I know this can be used for SQL injections. | |
$data = $sql->query("SELECT * FROM `data` WHERE `channel_id` = ".$sensor." ORDER BY `timestamp` DESC LIMIT 1 "); | |
if($data->num_rows != 1) die(); | |
$data = $data->fetch_object(); | |
if($data->timestamp/1000 <= time()-300) die(); | |
echo $data->value; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment