第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

為什么python腳本在Pi Zero上隨機(jī)死亡?

為什么python腳本在Pi Zero上隨機(jī)死亡?

達(dá)令說 2022-08-02 18:45:05
編輯:為了清楚起見:問題不在于MQTT,而在于Pi Zero上的python腳本剛剛死亡。經(jīng)過一段時(shí)間后,腳本將停止存在,并且sudo ps -ax | grep python 不再列出運(yùn)行腳本的進(jìn)程。原始問題:我寫了一個(gè)簡單的腳本,從pi zero讀取DHT22傳感器,并每分鐘將溫度和濕度發(fā)布到單獨(dú)的MQTT主題上。在某些時(shí)候,腳本只是停止,因?yàn)樗粫?huì)讀取或發(fā)布更多的讀數(shù),即使它在一段時(shí)間內(nèi)運(yùn)行 True 循環(huán)。在我的經(jīng)紀(jì)人中,pi然后顯示為“離線”,因?yàn)檫@是最后一個(gè) will 消息。日志文件不包含任何有用的信息,從某種意義上說,只要寫入日志文件,腳本就會(huì)按預(yù)期工作,然后突然出現(xiàn)空白。def on_connect(client, userdata, flags, rc):    message = "connected with rc: " + str(rc)    print(message)    log(message, mqtt_log_file)    mqttPub.publish(topicStatusBedroom, "Online", 1, True)def on_publish(client, obj, mid):    message = "published with mid: " + str(mid)    print(message)    log(message, mqtt_log_file)def on_disconnect(client, userdata, rc):    print("client disconnected ok")    log("client disconnected\n", mqtt_log_file)    while True:        try:            mqttPub.connect(url_str, url_port)            break # break the while loop, if reconnect works        except:            time.sleep(2) # otherwise sleep and retrydef log(message, file):    file = open(file, "a")    file.write(message)    file.close()  mqttPub = mqtt.Client()mqttPub.on_connect = on_connectmqttPub.on_publish = on_publishmqttPub.on_disconnect = on_disconnectmqttPub.username_pw_set(username, givenPassword)mqttPub.will_set(topicStatusBedroom, 'Offline', 1, True)mqttPub.connect(url_str, url_port)mqttPub.loop_start() # loop_start handles reconnects automaticallyif __name__ == "__main__":    pin = 22    sensor = Adafruit_DHT.DHT22    log_file = 'dht_22_logging.txt'
查看完整描述

1 回答

?
茅侃侃

TA貢獻(xiàn)1842條經(jīng)驗(yàn) 獲得超22個(gè)贊

:腳本因 SSH 連接而死機(jī)。有效的方法是創(chuàng)建腳本的服務(wù)并使用systemd啟動(dòng)它。我確實(shí)按照本教程進(jìn)行了操作:https://learn.sparkfun.com/tutorials/how-to-run-a-raspberry-pi-program-on-startup/all

該腳本已經(jīng)運(yùn)行了一周,沒有任何問題。


查看完整回答
反對 回復(fù) 2022-08-02
  • 1 回答
  • 0 關(guān)注
  • 155 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)