switched from datengammelstelle to strom.ccc-ffm.de and from get and local cacheing to post and immediate post
This commit is contained in:
parent
963b42ef22
commit
9340e23036
14
power.py
14
power.py
@ -1,7 +1,8 @@
|
|||||||
#!/usr/bin/python
|
#/usr/bin/python
|
||||||
|
|
||||||
import RPi.GPIO as GPIO
|
import RPi.GPIO as GPIO
|
||||||
import time
|
import time
|
||||||
|
import requests
|
||||||
|
|
||||||
# set gpio port numeration to bcm style
|
# set gpio port numeration to bcm style
|
||||||
GPIO.setmode(GPIO.BCM)
|
GPIO.setmode(GPIO.BCM)
|
||||||
@ -16,21 +17,22 @@ lpower = 10000
|
|||||||
#start busy loop
|
#start busy loop
|
||||||
while True:
|
while True:
|
||||||
#wait for a falling edge on gpio 24
|
#wait for a falling edge on gpio 24
|
||||||
GPIO.wait_for_edge(24, GPIO.FALLING)
|
#GPIO.wait_for_edge(24, GPIO.FALLING)
|
||||||
|
time.sleep(2)
|
||||||
|
|
||||||
#get current time and calculate current power from difference
|
#get current time and calculate current power from difference
|
||||||
current = time.time()
|
current = time.time()
|
||||||
diff = current - last
|
diff = current - last
|
||||||
power = 1800 / diff
|
power = 1800 / diff
|
||||||
|
|
||||||
|
|
||||||
#write into logfile
|
#write into logfile
|
||||||
logfile = open("/srv/powerpi/power.out", "w+", 0)
|
if (power < lpower + 3500):
|
||||||
if (power < lpower + 1500):
|
|
||||||
out = str(current) + ";" + str(round(power,0))
|
out = str(current) + ";" + str(round(power,0))
|
||||||
else:
|
else:
|
||||||
out = str(current) + ";0"
|
out = str(current) + ";0"
|
||||||
logfile.write(out)
|
payload = {"val": out}
|
||||||
logfile.close()
|
r = requests.post("https://strom.ccc-ffm.de/test.php", data=payload, verify=False)
|
||||||
lpower = power
|
lpower = power
|
||||||
last = current
|
last = current
|
||||||
GPIO.cleanup()
|
GPIO.cleanup()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user