Pi number 1 is monitoring my door bell, and when it is pressed, it calls Pi number 2 to take a picture. The stdout/stderr output should be written to a log file, along with the date/time that the button was pressed. The oddity is that it appears to be caching this data, and then writing it next time there is a button press. The log file (ls -l) has the time stamp for the most recent event, but the last entry is for the event before that.
Is what I'm running. Any suggestions on how to get it to write the most recent event information ?
Code: Select all
from gpiozero import Button import subprocess import sys import time doorbell_sensor = Button(6) while True: doorbell_sensor.wait_for_press() date_string = time.strftime ('%y%m%d%H%M') time_log = open ('/home/pi/data/door_log.txt', 'a+') time_log.write (date_string + "\n") # calls pi2 to take photo etc process = subprocess.Popen("ssh pi2 /home/pi/bin/take_still.sh", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) output,stderr = process.communicate() time_log.write (output.decode()) time_log.write (stderr.decode() + "\n") time_log.close # Wait 30 seconds before continuing doorbell_sensor.wait_for_release(30)