I try to insert stopwatch in my python code. Code read data from API, and if is value bigger then "3" switch relay to ON ( raspberry Pi3 ). This is read every XXX minutes. I want print time how long it's relay on or off.
while True:
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%H:%M:%S')
.
.
.
.
.
.
if highest > 3:
print("RELAY ON")
print st
print # time how long it's on
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7, GPIO.OUT)
else:
print("RELAY OFF")
print st
print # time how long it's off
GPIO.cleanup()
time.sleep(60)
I try with this code, but I do not know where to insert it.
import time
start = time.time()
time.sleep(10)
end = time.time()
total = end-start
print total
Thankyou for help!