From 101f78be5719d4c7a3a2d36b0da61aa41a96ffb3 Mon Sep 17 00:00:00 2001 From: telegnom Date: Sun, 5 Apr 2015 13:17:50 +0200 Subject: [PATCH] some minor changes --- pi/power.py | 8 ++++---- server/get.php | 24 ++++++++++++------------ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/pi/power.py b/pi/power.py index 5861cfa..b07a4a4 100755 --- a/pi/power.py +++ b/pi/power.py @@ -13,13 +13,13 @@ def trans(): queuelast = time.time() while True: queuedata = powerqueue.get() - queuetime = queuedata[0] + queuetime = int(queuedata[0]) queueval = str(queuedata[1]) if ((queuetime - queuelast) >= 5): - payload = "val:" + str(queuetime) + ";" + queueval + payload = {"val": str(queuetime) + ";" + str(queueval)} if sys.stdout.isatty(): - print("request https://strom.ccc-ffm.de:2342/gettest.php => "+payload) - r = requests.post("https://strom.ccc-ffm.de:2342/gettest.php", data=payload, verify=False, auth=('CCC', 'Freundschaft')) + print("request https://strom.ccc-ffm.de:2342/get.php => "+repr(payload)) + r = requests.post("https://strom.ccc-ffm.de:2342/get.php", data=payload, verify=False, auth=('CCC', 'Freundschaft')) if sys.stdout.isatty(): print(r) queuelast = queuetime diff --git a/server/get.php b/server/get.php index c1a8295..d96b0f9 100644 --- a/server/get.php +++ b/server/get.php @@ -1,14 +1,14 @@ update(array("power" => $val[1]), $val[0]); - $fileh = fopen("power.log", "w+"); - fwrite($fileh, $_POST['val']); - fclose($fileh); - echo "0"; - } else { - echo "1"; - } - +if (preg_match("/^[0-9]{10}\;[0-9]{1,5}\.?[0-9]{0,20}/", $_POST['val'])) { + $val = explode(";", $_POST['val']); + $updator = new RRDUpdater("power.rrd"); + $updator->update(array("power" => $val[1]), $val[0]); + $fileh = fopen("power.log", "w+"); + fwrite($fileh, $_POST['val']); + fclose($fileh); + echo "0"; +} else { + echo "1"; +} ?> +