简体   繁体   English

Raspberry Pi WiFi无线电脚本问题

[英]Raspberry Pi WiFi Radio Script Issues

I am having a problem and since I don't really know much about Python, I would appreciate the help of someone else to help me understand what my problem is. 我遇到了问题,因为我对Python并不是很了解,我会感谢别人的帮助,帮助我理解我的问题。

I am building a Portable Wireless Radio. 我正在建造便携式无线电台。 The Raspberry Pi utilizes Pianobar to go out to the Pandora servers, log in to my account, get my stations, and then begin playing the first one. Raspberry Pi利用Pianobar前往Pandora服务器,登录我的帐户,获取我的电台,然后开始播放第一个。

I am following the official Adafruit guide: https://learn.adafruit.com/pi-wifi-radio/overview 我正在关注官方的Adafruit指南: https ://learn.adafruit.com/pi-wifi-radio/overview

I have followed the guide all the way up until Pianobar was working. 我一直跟着指南一直到Pianobar工作。 I am able to run "pianobar" from the command line. 我可以从命令行运行“pianobar”。 It connects and begins playing music in less than 10 seconds. 它可以在不到10秒的时间内连接并开始播放音乐。

However, when I start the script that allows the 16x2 LCD Keypad to interface with pianobar, it doesn't work. 但是,当我启动允许16x2 LCD键盘与pianobar接口的脚本时,它不起作用。

More specifically, it gets through the first half of the script. 更具体地说,它通过脚本的前半部分。 The LCD displays the IP address and says "Retrieving Station List...". 液晶显示屏显示IP地址并显示“检索电台列表...”。 After 10 seconds, the script exits with all of this. 10秒后,脚本退出所有这些。

pi@pandora ~/Python-WiFi-Radio $ sudo python PiPhi.py

Spawning pianobar...
Receiving station list...
Traceback (most recent call last):
  File "PiPhi.py", line 288, in <module>
    stationList, stationIDs = getStations()
  File "PiPhi.py", line 190, in getStations
    pianobar.expect('Select station: ', timeout=10)
  File "/usr/local/lib/python2.7/dist-packages/pexpect.py", line 1311, in expect
    return self.expect_list(compiled_pattern_list, timeout, searchwindowsize)
  File "/usr/local/lib/python2.7/dist-packages/pexpect.py", line 1325, in expect_list
    return self.expect_loop(searcher_re(pattern_list), timeout, searchwindowsize)
  File "/usr/local/lib/python2.7/dist-packages/pexpect.py", line 1409, in expect_loop
    raise TIMEOUT (str(e) + '\n' + str(self))
pexpect.TIMEOUT: Timeout exceeded in read_nonblocking().
<pexpect.spawn object at 0xb6b305b0>
version: 2.3 ($Revision: 399 $)
command: /usr/bin/sudo
args: ['/usr/bin/sudo', '-u', 'pi', 'pianobar']
searcher: searcher_re:
    0: re.compile("Select station: ")
TIME: -03:35/03:43
TIME: -03:35/03:43
after: <class 'pexpect.TIMEOUT'>
match: None
match_index: None
exitstatus: None
flag_eof: False
pid: 2315
child_fd: 5
closed: False
timeout: 30
delimiter: <class 'pexpect.EOF'>
logfile: None
logfile_read: None
logfile_send: None
maxread: 2000
ignorecase: False
searchwindowsize: None
delaybeforesend: 0.05
delayafterclose: 0.1
delayafterterminate: 0.1

pi@pandora ~/Python-WiFi-Radio $ 

http://pastebin.com/6Lm3dTwx - THIS IS THE SCRIPT THAT I AM TRYING TO RUN http://pastebin.com/6Lm3dTwx - 这是我试图跑的脚本

From my basic knowledge, it looks like it it taking longer than whatever timeout is to retrieve the station list. 根据我的基本知识,它看起来比检索电台列表的超时时间更长。 Please help me as I am completely lost. 因为我完全迷失了,请帮助我。 Thanks! 谢谢!

I had the same problem, for a low tech fix I just pinged google 10 times in the startup script. 我有同样的问题,对于低技术修复我只是在启动脚本中敲了10次google。 This gave the system long enough to get the network connection stabalized. 这使系统足够长,以使网络连接稳定。

I found that userid "pi" is hard coded in PiPhi.py! 我发现用户标识“pi”在PiPhi.py中是硬编码的! Changing line 33 (PICKLEFILE), 286 (pepect.spawn('sudo -u pi... solved my problem .. 改变第33行(PICKLEFILE),286(pepect.spawn('sudo -u pi ...解决了我的问题..

hope this helps .. 希望这可以帮助 ..

There are potentially two issues here. 这里可能存在两个问题。 I was having difficulty spawning the process. 我很难产生这个过程。 This shows up as an EOF error at the pianobar.excect for 'Get stations...Ok.\\r\\n'. 这在'获取电台...确定。\\ r \\ n'的pianobar.excect中显示为EOF错误。 To see what is happening process the EOF exception and print pianobar.before: 要查看正在发生的事情,请处理EOF异常并打印pianobar.before:

 # Launch pianobar as pi user (to use same config data, etc.) in background: print('Spawning pianobar...') pianobar = pexpect.spawn('sudo -u pi /home/pi/pianobar/pianobar', timeout=60) print('Receiving station list...') expectIdx = pianobar.expect(['Get stations... Ok.\\r\\n', pexpect.EOF, pexpect.TIMEOUT]) if expectIdx == 0: stationList, stationIDs = getStations() try: # Use station name from last session stationNum = stationList.index(defaultStation) except: # Use first station in list stationNum = 0 print 'Selecting station ' + stationIDs[stationNum] pianobar.sendline(stationIDs[stationNum]) elif expectIdx == 1: # EOF print 'pianobar.expect EOF error' print pianobar.before # shows response from pianobar spawn pianobar.kill(0) elif expectIdx == 2: # TIMEOUT print 'pianobar.expect TIMEOUT error' pianobar.kill(0) 

I fixed my problem by specifying the full path for pianobar (as shown above). 我通过指定pianobar的完整路径来修复我的问题(如上所示)。

The second issue could be because you have a valid default station in your pianobar configuration. 第二个问题可能是因为您的pianobar配置中有一个有效的默认工作站。 If this is the case the select station list is not displayed at startup any you will need to request it. 如果是这种情况,启动时不会显示选择站列表,您需要请求它。 This error shows up at the pianobar.expect in getStations(). 此错误显示在getStations()中的pianobar.expect上。 I fixed this by requesting the station list if the initial request timed out: 如果初始请求超时,我通过请求站列表来修复此问题:

  expectIdx = pianobar.expect(['Select station: ', pexpect.EOF, pexpect.TIMEOUT], timeout=10) if expectIdx == 1: # EOF print 'pianobar.expect EOF error at getStations' print pianobar.before # shows response from pianobar spawn pianobar.kill(0) elif expectIdx == 2: # TIMEOUT # try requesting the station list pianobar.send('s') pianobar.expect('Select station', timeout=10) 

I know this is old but I've just encountered the problem myself. 我知道这已经老了,但我刚刚遇到了这个问题。 I found that issuing the following command: 我发现发出以下命令:

pianobar.send('s')

before 之前

pianobar.expect('Select station: ', timeout=20)

forced pianobar to update the station list 强制pianobar更新电台列表

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM