[英]My (working) raspberry pi program doesn't work right when I run it on boot
我正在編寫一個腳本(基本上)從 raspi gpio 引腳控制一些電機。 我已經做了一段時間了,當我啟動 pi 並手動運行程序時,它工作得很好。 我還有一部分代碼允許我使用我的手機通過藍牙連接並發送一些數據來控制電機。 這也適用於手動運行程序。
現在我試圖讓程序在啟動時自動啟動,因為這最終會進入更大的機器(船),我不會將監視器等掛在它上面。 我目前正在通過帶有 @reboot 標簽的 cron 作業來執行此操作。 看起來像這樣:
#This enables GPIO (as far as I know). The program fails without this command being run first.
@reboot sudo pigpiod
#This runs the python program. ampersand forks the process because it should run continuously.
@reboot python3 /home/pi/Desktop/BoatBrain.py &
#and this lets me connect my phone over bluetooth. The python program has
#a portion takes data from that connection. ampersand forks the process, which
#seems like the right thing to do, since it looks like it blocks other things.
#That is also why it is at the end of the cron table.
@reboot sudo rfcomm watch hci0 &
當我重新啟動時,作業全部運行,並且我可以連接我的手機,所以它肯定已經通過了執行 python 腳本的線路,但是我連接的伺服器只是無法控制地抖動到位。 讓我重申一下,當我拿走 cronjobs 並手動運行它時,程序可以正常工作,幾乎沒有抖動,所以感覺不像是電氣問題......
如果您需要更多信息,請告訴我,我很樂意提供。 我傾向於在沒有意識到的情況下忽略事情XD
謝謝!
你有沒有在~/.profile
添加任何東西? 這可能就是當您自己調用命令時它起作用的原因。 如果是這樣,請在sudo vi /etc/profile.d/servo.sh
創建一個文件,其中包含添加到~/.profile
的相同幾行。 然后系統將在重新啟動時具有這些。
此外,您可以將所有三個命令放在一個 shell 腳本中,然后將腳本放在 crontab 中。 然后腳本可以控制它們按順序啟動。 您還可以讓 cronjob 將輸出寫入日志文件,然后查看它的內容。 您還可以通過查看/var/log/syslog
來檢查 cron 何時運行
哦,同樣為了測試,您可以將 @reboot 更改為10 * * * *
類的開始時間,然后您就可以讓 cron 工作而無需重新啟動。 稍后,將其更改回@reboot 以嘗試重新啟動。
要么您的登錄名 (.profile) 缺少某些東西,要么同時啟動命令太快,需要以受控順序啟動,要么系統尚未完全准備好,但我對此表示懷疑。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.