Hello,
I have a working automatic top off system for my fish tank with the code below. It works great and replenishes water successfully. The problem I'm having is that everytime my timelog() function is called the printed timestamp on the console displays the execution timestamp of the script. For example. If i run the script at 22:00:00. Lets assume water evaporates and triggers the float switch 2 hours later on the configured pull_up_down pin (22). The timelog() function is called in the process and the timestamp displayed is still 22:00:00. I started my script at 22:16:00 last night and after calling the function over 20x times due to evaporation I only see 22:16:00 in the console. Is there a way to call time to display current system time?
I have a working automatic top off system for my fish tank with the code below. It works great and replenishes water successfully. The problem I'm having is that everytime my timelog() function is called the printed timestamp on the console displays the execution timestamp of the script. For example. If i run the script at 22:00:00. Lets assume water evaporates and triggers the float switch 2 hours later on the configured pull_up_down pin (22). The timelog() function is called in the process and the timestamp displayed is still 22:00:00. I started my script at 22:16:00 last night and after calling the function over 20x times due to evaporation I only see 22:16:00 in the console. Is there a way to call time to display current system time?
#!/usr/bin/python3 import RPi.GPIO as GPIO import time import schedule from time import sleep #DISABLE WARNINGS AND SET GPIO TO BCM MODE GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) ###################################### #relay channels #################################### #ASSIGN RELAY CHANNELS TO BCM PINS Relay_Ch1 = 26 #INITIALIZE RELAY CHANNELS GPIO.setup(Relay_Ch1,GPIO.OUT) #################################### #float switch: GPIO, 22 #LED for visual confirmation in testing: gpio, 18 #################################### GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(18, GPIO.OUT) ################################# timestamp = time.strftime("%H:%M:%S") + str('# ') def timelog(): print('Timestamp for action' + timestamp) def floatTriggered(channel): if GPIO.input(22): print(timestamp + 'WATER LEVEL ADAQUATE - PUMP OFF') timelog() GPIO.output(18, 0) GPIO.output(Relay_Ch1,GPIO.HIGH) else: print(timestamp + 'WATER LEVEL LOW - PUMP ON') timelog() GPIO.output(18, 1) GPIO.output(Relay_Ch1,GPIO.LOW) sleep(3) GPIO.output(Relay_Ch1,GPIO.HIGH) try: GPIO.add_event_detect(22, GPIO.BOTH, callback=floatTriggered, bouncetime=600) while True: sleep(0.1) finally: GPIO.cleanup()