首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Raspberry Pi python启动

Raspberry Pi python启动
EN

Stack Overflow用户
提问于 2017-03-21 19:48:00
回答 1查看 330关注 0票数 0

我试图在引导时在后台运行python脚本。当我想要运行我的代码时,这种方法一直在为我工作,但现在它似乎不起作用了。我想我在运营NOOBS。

代码语言:javascript
复制
sudo nano /etc/rc.local
代码语言:javascript
复制
#!/bin/sh -e

sudo python /home/pi/Firebase.py &


exit 0

Firebase.py

代码语言:javascript
复制
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")
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-21 23:52:34

修正了需要睡眠的问题,这样它才能连接到wifi。

代码语言:javascript
复制
#!/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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42936838

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档