以下脚本用于发送电子邮件警报,由于某种原因,它一直绕过我设置的标志..
############################################################
## MAIN ##
############################################################
Open_serial()
while True:
line = ser.readline()
if line:
tmp = line.split()
if 'tank' in line:
tank_temp = tmp[1]
print 'Tank temperature:',tank_temp
if tank_temp >= 27:
flag = raise_flag()
if flag:
send_email('Tank temperature overheat',tank_temp)
flag = False
elif tank_temp <= 23:
flag = raise_flag()
if flag:
send_email('Tank temperature too low',tank_temp)
flag = False
if 'led' in line:
led_temp = tmp[1]
print 'Lights temperature:',led_temp
if led_temp >= 55:
flag = raise_flag()
if flag:
send_email('Lights temperature Overheat',led_temp)
flag = False
if 'White' in line:
white_pwm = tmp[1]
print 'White lights PWM value:',white_pwm
white_per = white_percent(white_pwm)
print 'White lights % value:',white_per
if 'Blue' in line:
blue_pwm = tmp[1]
print 'Blue lights PWM:',blue_pwm
blue_per = blue_percent(blue_pwm)
print 'Blue lights % value:',blue_per
这是标志功能:
def raise_flag():
global start
interval = 900
if start > interval:
start = 0
flag = True
return flag
else:
flag = False
start = start + 1
time.sleep(1)
return flag
当温度在 25°C 范围内时,脚本会继续发送电子邮件,我不知道为什么它会一直发送电子邮件?我放置了标志,所以当满足条件时它不会发送 1000 封电子邮件,每 15 分钟只有 1 封...