我正在研究 pycom 的 lopy4,在从 txt 文件加载配置数据时遇到了 od 问题:
def loadFromConfigFile():
f= open('config.txt')
for line in f:
if "uuidExpected" in line:
uuidExpected=line[13:len(line)-1].strip()
elif "app_eui" in line:
app_eui = ubinascii.unhexlify((line[8:len(line)-1]).strip())
elif "app_key" in line:
app_key = ubinascii.unhexlify((line[8:len(line)-1]).strip())
elif "syncClockTime" in line:
syncClockTime=float(line[14:len(line)-1].strip())
elif "loraJoinTime" in line:
loraJoinTime=float(line[13:len(line)-1].strip())
elif "bleScanInterval" in line:
bleScanInterval=int(line[16:len(line)-1].strip())
elif "mainLoopWaitTime" in line:
mainLoopWaitTime=int(line[17:len(line)-1].strip())
elif "hbInterval" in line:
hbInterval=int(line[11:len(line)-1].strip())
f.close()
loadFromConfigFile()
当我使用此功能时,我的程序会卡在这里:
lora.join(activation=LoRa.OTAA, auth=(app_eui, app_key), timeout=0)
while not lora.has_joined():
time.sleep(loraJoinTime)
print('Not yet joined...')
print("joined!")
setClock()
睡眠功能不起作用,打印功能在终端窗口中显示“尚未加入...”的垃圾邮件。
f= open('config.txt')
for line in f:
if "uuidExpected" in line:
uuidExpected=line[13:len(line)-1].strip()
elif "app_eui" in line:
app_eui = ubinascii.unhexlify((line[8:len(line)-1]).strip())
elif "app_key" in line:
app_key = ubinascii.unhexlify((line[8:len(line)-1]).strip())
elif "syncClockTime" in line:
syncClockTime=float(line[14:len(line)-1].strip())
elif "loraJoinTime" in line:
loraJoinTime=float(line[13:len(line)-1].strip())
elif "bleScanInterval" in line:
bleScanInterval=int(line[16:len(line)-1].strip())
elif "mainLoopWaitTime" in line:
mainLoopWaitTime=int(line[17:len(line)-1].strip())
elif "hbInterval" in line:
hbInterval=int(line[11:len(line)-1].strip())
f.close()
当我不将此代码包装到函数中时,一切正常。当我在硬编码循环之后编写函数时,一切正常。