【问题标题】:Raspberry Pi WiFi Radio Script IssuesRaspberry Pi WiFi 无线电脚本问题
【发布时间】:2014-08-21 23:43:37
【问题描述】:

我遇到了一个问题,由于我对 Python 了解不多,我希望其他人能帮助我理解我的问题。

我正在构建一个便携式无线电。 Raspberry Pi 使用 Pianobar 访问 Pandora 服务器,登录我的帐户,获取我的电台,然后开始播放第一个。

我正在关注 Adafruit 官方指南:https://learn.adafruit.com/pi-wifi-radio/overview

我一直按照指南进行操作,直到 Pianobar 开始工作。我可以从命令行运行“pianobar”。它会在 10 秒内连接并开始播放音乐。

但是,当我启动允许 16x2 LCD 键盘与钢琴条交互的脚本时,它不起作用。

更具体地说,它通过了脚本的前半部分。 LCD 显示 IP 地址并显示“正在检索电台列表...”。 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 - 这是我要运行的脚本

根据我的基本知识,检索电台列表所需的时间似乎比任何超时都长。请帮助我,因为我完全迷路了。谢谢!

【问题讨论】:

    标签: python raspberry-pi pandora


    【解决方案1】:

    我遇到了同样的问题,我只是在启动脚本中 ping 了 10 次 google 的低技术修复。这给了系统足够长的时间来稳定网络连接。

    【讨论】:

      【解决方案2】:

      我发现用户 ID“pi”在 PiPhi.py 中是硬编码的!改变 第 33 行 (PICKLEFILE), 286 (pepect.spawn('sudo -u pi... 解决了我的问题..

      希望这会有所帮助..

      【讨论】:

        【解决方案3】:

        这里可能存在两个问题。我很难产生这个过程。这在钢琴栏上显示为 EOF 错误。“获取电台...确定。\r\n”除外。要查看发生了什么处理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)

        我通过指定钢琴条的完整路径解决了我的问题(如上所示)。

        第二个问题可能是因为您的钢琴条配置中有一个有效的默认电台。如果是这种情况,则在启动时未显示选择站列表,您将需要请求它。此错误显示在 getStations() 中的 pianobar.expect 中。如果初始请求超时,我通过请求电台列表来解决此问题:

            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)

        【讨论】:

          【解决方案4】:

          我知道这是旧的,但我自己也遇到了这个问题。我发现发出以下命令:

          pianobar.send('s')
          

          之前

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

          强制pianobar更新电台列表

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2016-09-30
            • 2023-03-13
            • 2016-02-17
            • 2017-06-16
            • 2016-03-14
            • 2015-07-15
            • 2018-01-08
            • 1970-01-01
            相关资源
            最近更新 更多