python语法循环使用_Python while循环使用无效语法

importtimeimportRPi.GPIOasGPIO

GPIO.setmode(GPIO.BCM)GPIO.setup(17,GPIO.IN)floatSwitch=GPIO.input(17)importsmtplib

running=Truelog=open("sumpPumpLog.txt","r+")startTime=time.time()defelapsedTime():"""This function checks how much time

has elapsed since the timer has started"""endtime=time.time()elapsed=endtime-starttimereturnelapseddefsendEmail(*msg):"""This function sends an email to selected recipients with a custom

message as well as the log file attached."""#enter the code that sends an email to the family with the log attachedfromaddr='from@email.com'toaddrs=[to@email.com']

msg = """Please see the Pi and the data log file for more details."""

# Credentials (if needed)

username = 'my_username'

password = 'my_password'

msg.attached()

# The actual mail send

server = smtplib.SMTP('smtp.gmail.com:587')

server.starttls()

server.login(username, password)

server.sendmail(fromaddr, toaddrs, msg)

server.quit()

if running is True:

if floatSwitch is True:

#Write the time and what happened to the file

log.write(str(time.time() + "Float switch turned on")

#Wait until switch is turned off

while floatSwitch is True:

startTime = time.time()

if floatSwitch is False:

log.write(str(now) + "Float switch turned off")

break

#if elapsedTime > 3 min (in the form of 180 seconds)

elif elapsedTime() > 180:

log.write(str(now) + "Sump Pump has been deemed broaken")

sendEmail("The sump pump is now broken.")

else:

log.write(str(time.time() + "The sctipt has stopped.")

sendEmail("The script has been stopped.")

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值