diff --git a/pi/power.py b/pi/power.py index b07a4a4..e960c46 100755 --- a/pi/power.py +++ b/pi/power.py @@ -42,14 +42,20 @@ def readgpio(): print("start readgpio mainloop") while True: gpioevent = gpiopoll.poll() - gpio.read() + gpioval = gpio.read(1) gpio.seek(0) - now = time.time() - power = round(1800 / (now-last),2) - if sys.stdout.isatty(): - print("Current power consumption: " + str(power) + " Watt") - powerqueue.put([now, power]) - last = now + if gpioval == '0': + now = time.time() + if ((now-last) >= 0.2): + power = round(1800 / (now-last),2) + if sys.stdout.isatty(): + print("Current power consumption: " + str(power) + " Watt") + print(repr(gpioval)) + powerqueue.put([now, power]) + last = now + else: + if sys.stdout.isatty(): + print("ERROR: not a falling edge! Ignoring interrupt") if __name__ == "__main__": try: diff --git a/pi/powerpi b/pi/powerpi index fc410ae..e77c38b 100755 --- a/pi/powerpi +++ b/pi/powerpi @@ -6,8 +6,8 @@ # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 -# Short-Description: Put a short description of the service here -# Description: Put a long description of the service here +# Short-Description: PowerPi - Logging electric energy consumption +# Description: Logs the electric energy consumption in the hq with the power of a raspberry and a flying circus. ### END INIT INFO # Change the next 3 lines to suit where you install your script and what you want to call it