Raspberry Pi python 启动时
Raspberry Pi python on startup
我正在尝试 运行 我的 python 脚本在后台启动。当我想 运行 我的代码时,它一直对我有用,但现在它似乎不起作用。我认为我是 运行宁诺布斯。
sudo nano /etc/rc.local
#!/bin/sh -e
sudo python /home/pi/Firebase.py &
exit 0
Firebase.py
from firebase import firebase
import RPi.GPIO as GPIO
import time
firebase = firebase.FirebaseApplication('https://raspberrypi-5c0ce.firebaseio.com/', authentication = None)
#result = firebase.put('/light_switch','state', 'off')
#currentState = firebase.get('/light_switch', 'state')
#print(currentState)
#Initialize gpio settings
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
#Initialize gpio board
input1 = 26
input2 = 19
#setup led color with gpio setup
GPIO.setup(input1, GPIO.OUT)
GPIO.setup(input2, GPIO.OUT)
#GPIO.setup(yellowLed, GPIO.OUT)
#output actual color of led based on variableColor and 1 for tru
while True:
currentState = firebase.get('/light_switch', 'state')
#print(currentState)
if currentState == "on":
GPIO.output(input1, 1)
GPIO.output(input2, 1)
#print("on")
else:
GPIO.output(input1, 0)
GPIO.output(input1, 0)
#print("off")
解决了需要睡眠才能连接到 wifi 的问题。
#!/bin/sh -e
# Print the IP address
# Sleep introduced to see if Wifi acquired and IP assigned
date >> /tmp/rc_local_b4_sleep
sleep 15
date >> /tmp/rc_local_after_sleep
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi
/sbin/ifconfig > /tmp/network_at_boot
python /home/pi/Firebase.py &
exit 0
我正在尝试 运行 我的 python 脚本在后台启动。当我想 运行 我的代码时,它一直对我有用,但现在它似乎不起作用。我认为我是 运行宁诺布斯。
sudo nano /etc/rc.local
#!/bin/sh -e
sudo python /home/pi/Firebase.py &
exit 0
Firebase.py
from firebase import firebase
import RPi.GPIO as GPIO
import time
firebase = firebase.FirebaseApplication('https://raspberrypi-5c0ce.firebaseio.com/', authentication = None)
#result = firebase.put('/light_switch','state', 'off')
#currentState = firebase.get('/light_switch', 'state')
#print(currentState)
#Initialize gpio settings
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
#Initialize gpio board
input1 = 26
input2 = 19
#setup led color with gpio setup
GPIO.setup(input1, GPIO.OUT)
GPIO.setup(input2, GPIO.OUT)
#GPIO.setup(yellowLed, GPIO.OUT)
#output actual color of led based on variableColor and 1 for tru
while True:
currentState = firebase.get('/light_switch', 'state')
#print(currentState)
if currentState == "on":
GPIO.output(input1, 1)
GPIO.output(input2, 1)
#print("on")
else:
GPIO.output(input1, 0)
GPIO.output(input1, 0)
#print("off")
解决了需要睡眠才能连接到 wifi 的问题。
#!/bin/sh -e
# Print the IP address
# Sleep introduced to see if Wifi acquired and IP assigned
date >> /tmp/rc_local_b4_sleep
sleep 15
date >> /tmp/rc_local_after_sleep
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi
/sbin/ifconfig > /tmp/network_at_boot
python /home/pi/Firebase.py &
exit 0