version as running since 2015-04-05 noon
This commit is contained in:
		
							
								
								
									
										20
									
								
								pi/power.py
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								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:
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user