我试图在启动时在后台运行我的python脚本 . 当我想运行我的代码时,这种用法一直用于我,但现在似乎无法正常工作 . 我想我正在运行NOOBS .
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")
1 回答
修复了睡眠所需的问题,因此它可以连接到wifi .