Raspberry Pi Radio Amplifier WiFi Script Problems

I have a problem, and since I don't know much about Python, I would appreciate the help of someone else to help me understand what my problem is.

I am creating a portable wireless radio. The Raspberry Pi uses Pianobar to log into the Pandora server, log into my account, get my stations, and then start playing on the first.

I am following the official Adafruit guide: https://learn.adafruit.com/pi-wifi-radio/overview

I followed the guide all the way to Pianobar. I can run "pianobar" from the command line. It connects and starts playing music in less than 10 seconds.

However, when I run a script that allows a 16x2 LCD keyboard to interact with pianobar, it doesn't work.

Specifically, it goes through the first half of the script. The LCD displays the IP address and says "Retrieving Station List ...". After 10 seconds, the script exits with all of this.

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 is the script THAT I IF TRYING TO WORK

From my basic knowledge, it looks like it takes longer than any timeout to get the list of stations. Please help me as I am completely lost. Thank!

+3


source to share


4 answers


I had the same problem: for a low tech fix, I just pinged Google 10 times at the start of the script. This gave the system a long enough time for the network connection to stabilize.



0


source


I found the userid "pi" is hardcoded in PiPhi.py! changes line 33 (PICKLEFILE), 286 (pepect.spawn ('sudo -u pi ... solved my problem ..



hope this helps.

0


source


There can be two problems here. I am having difficulty creating a process. This shows up as an EOF error on pianobar.excect for 'Get station ... Ok. \ R \ n'. To see what's going on, this is an EOF exception and pianobar.before printing:

# 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)
      

Run codeHide result


I fixed my problem by giving the full path for the pianobar (as shown above).

The second problem might be that you have a valid default station in your piano bar configuration. If so, the selected station list is not displayed at startup, which you will need to request. This error appears in the pianobar.expect file in getStations (). I fixed this by asking for a list of stations 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)
      

Run codeHide result


0


source


I know this is a long time ago, but I ran into the problem myself. I found myself issuing the following command:

pianobar.send('s')

      

before

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

      

forced pianobar to update the station list

0


source







All Articles