我有一个程序来控制我的鸡舍的很多事情,包括在规定的时间开门和关门。偶尔会发生一些事情,门开不开也关不上,我现在已经让它在这种情况下发送电子邮件。问题是,它将发送6个或更多的电子邮件,我一直在努力研究如何限制它只发送一个可能使用while或if-但我需要重新设置它,以便如果在另一天再次发生,它将发送另一封电子邮件。这就是我的循环
def loop():
# retrieve current datetime
now = datetime.time(datetime.datetime.now().hour, datetime.datetime.now().minute)
# Open door on all days at the correct time
if ((now.hour == HOUR_ON.hour) and (now.minute == HOUR_ON.minute)):
if (gpio.digitalRead(17) == 0):
openplay()
# Close door on all days at the correct time
if ((now.hour == HOUR_OFF.hour) and (now.minute == HOUR_OFF.minute)):
if (gpio.digitalRead(22) == 1):
closeplay()
# check if door is open, 2 minutes after set time
if ((now.hour == HOUR_ON.hour) and (now.minute == HOUR_ON.minute + 120) and (now.second == 0) and (gpio.digitalRead(25) == 0)):
# send email
sendemail()
# check if door is closed, 2 minutes after set time
if ((now.hour == HOUR_OFF.hour) and (now.minute == HOUR_OFF.minute + 120) and (now.second == 0) and (gpio.digitalRead(25) == 1)):
# send email
sendemail()
# gives CPU some time before looping again
webiopi.sleep(1)
这只是一个爱好,我把大部分搜索的东西放在一起,但不能破解这个,所以如果有任何帮助,我将不胜感激
这似乎可以做到。你知道吗
关门10分钟后,它检查门是否关上,是否调用sendmail(a),emailsent1是否设置为True—一分钟后,它再次设置为false。你知道吗
我是否需要emailsent1和emailsent2作为全局?你知道吗
假设
sendemail()
是您定义的函数,您可以重写它来存储它上次发送电子邮件的时间,如果时间不够长,就不要发送它。你知道吗对我来说
now.minute == HOUR_ON.minute + 120
没有意义,你说的是2小时,而不是2分钟,除非现在。分钟以秒为单位返回值?你知道吗另一种可能性是:这个python程序是否有多个实例同时运行?
pgrep python3
查看有多少python实例正在运行。你知道吗相关问题 更多 >
编程相关推荐