texy
Forum Moderator
Forum Moderator
Posts: 5160
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: (Yet another) Vintage Pi-Radio

Fri Oct 07, 2016 8:42 am

If you get all that working, I'll send you one of my 2.8" display boards FOC ;)

Then a Bluetooth pairing option would be nice :o
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: (Yet another) Vintage Pi-Radio

Fri Oct 07, 2016 8:46 am

I'm more interested in getting the Bluetooth pairing working.

Sounds like my To Do list is:
  1. Airplay (text) metadata
  2. Bluetooth pairing
  3. Airplay artwork
  4. Bluetooth artwork
I suspect the pairing will be the hardest - lots of research to be done on that.

I'm excited, I love challenges like this!
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

texy
Forum Moderator
Forum Moderator
Posts: 5160
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: (Yet another) Vintage Pi-Radio

Fri Oct 07, 2016 9:22 am

elParaguayo wrote:I'm more interested in getting the Bluetooth pairing working.
So will the challenge to get bluetoothctl commands working remotely, ie through a python call ?

Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: (Yet another) Vintage Pi-Radio

Fri Oct 07, 2016 9:26 am

If it can be done via command line calls then that should be ok - I'm fairly comfortable handling those in python. However, my experience of bluetoothctl is that it starts an interactive session (which is still doable) so that may make it harder.

However, if the correct way is to do it via dbus interactions then that's going to take me longer!

First step will be research.
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: (Yet another) Vintage Pi-Radio

Fri Oct 07, 2016 11:07 pm

Work permitting, I should have Airplay metadata working tomorrow.

I've got it working in a standalone script so I just need to drop it into the radio code.

Code: Select all

<START OF METADATA STREAM>
The Race For Space
Public Service Broadcasting
Go!
<END OF STREAM>
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

User avatar
Douglas6
Posts: 4779
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: (Yet another) Vintage Pi-Radio

Fri Oct 07, 2016 11:31 pm

elParaguayo wrote:I suspect the pairing will be the hardest - lots of research to be done on that.
Bluetooth pairing using the D-Bus Agent1 interface is not difficult at all. There's code in my original BluePlayer post (https://github.com/Douglas6/blueplayer) that was just a stripped-down version of the BlueZ simple-agent code: http://git.kernel.org/cgit/bluetooth/bl ... ent?h=5.23

If I can answer any questions, please feel free.

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: (Yet another) Vintage Pi-Radio

Fri Oct 07, 2016 11:34 pm

Part of my research was going to be looking through your code!

I may well have some questions for you later.
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: (Yet another) Vintage Pi-Radio

Sat Oct 08, 2016 8:30 am

elParaguayo wrote:Work permitting, I should have Airplay metadata working tomorrow.

I've got it working in a standalone script so I just need to drop it into the radio code.

Code: Select all

<START OF METADATA STREAM>
The Race For Space
Public Service Broadcasting
Go!
<END OF STREAM>
Here we go:
Image

Code is on a different branch for now: https://github.com/elParaguayo/PiRadio/ ... y_metadata

PS This song should be mandatory for any videos about AstroPi.
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: (Yet another) Vintage Pi-Radio

Sat Oct 08, 2016 11:08 pm

Douglas6 wrote:
elParaguayo wrote:I suspect the pairing will be the hardest - lots of research to be done on that.
Bluetooth pairing using the D-Bus Agent1 interface is not difficult at all. There's code in my original BluePlayer post (https://github.com/Douglas6/blueplayer) that was just a stripped-down version of the BlueZ simple-agent code: http://git.kernel.org/cgit/bluetooth/bl ... ent?h=5.23

If I can answer any questions, please feel free.
Well, despite you saying it's not that difficult, I'm having trouble!

I've been playing with your code and have managed to able discovery. I can see that visible devices appear as separate devices on the system bus. However, when I try to create the object and retrieve the "Name" property it gives this "<dbus.proxies._DeferredMethod instance at 0x7f446994f7e8>" and I have no idea why I get that and not the name of the device.

Once I've got over that I'll start trying the pairing code.

Can you help?

EDIT: Nevermind - got it!
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

User avatar
Douglas6
Posts: 4779
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: (Yet another) Vintage Pi-Radio

Sat Oct 08, 2016 11:26 pm

elParaguayo wrote:EDIT: Nevermind - got it!
Okies. I'm here if you need me.

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: (Yet another) Vintage Pi-Radio

Sat Oct 08, 2016 11:30 pm

Well, I've got the name (had to use the properties interface and the Get method, rather than trying to use .Name on the device interface), but now I can't call the Connect method. I can create the Device interface but I get an "Input/Output" error when I try to connect.
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

User avatar
Douglas6
Posts: 4779
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: (Yet another) Vintage Pi-Radio

Sun Oct 09, 2016 12:42 am

I've never tried to connect to my phone from the Pi (Try it from bluetoothctl; it won't work). The phone will make the connection when you choose the Pi on the phone's Bluetooth screen (after pairing and trusting, of course).

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: (Yet another) Vintage Pi-Radio

Sun Oct 09, 2016 7:05 am

Quick disclosure: I'm developing code on my laptop (Ubuntu 16.04) so using its bluetooth adapter.

What's interesting is that, if I use the d-feet application (which is a d-bus viewer/debugger), I can see the Connect method on the device and I can run it. If I run it, the phone connects to the laptop. That, to me, suggests it should have worked.

However, I agree with your comment. I would think a normal approach would be to discover the device, pair and then connect from the phone.

The most important thing for me is to list available devices.

I'm making progress. I can get the laptop to pair with my device but this is for devices that become visible once the code has started rather than listing already visible devices but I think I know how to fix that one.
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: (Yet another) Vintage Pi-Radio

Sun Oct 09, 2016 9:30 am

OK. I think I've got an idea how it's all working now.

I'm able to scan for devices, pair and connect from the python code. Just a matter of time of putting it altogether into something neat.

Sadly the week ahead looks pretty painful from a work perspective...
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: (Yet another) Vintage Pi-Radio

Sun Oct 09, 2016 6:15 pm

Bluetooth coming along very nicely now.

I've written some simplified python wrappers for the MediaPlayer, Device and Adapter (i.e. cutting out signal handling makes my life easier - I really don't understand mainloops).

I've now got the radio scanning for and pairing with/connecting to devices. I'll also add player controls.

The only thing is I'll still continuously poll for metadata rather than using signals. That's fine for now but I may revisit later.

Once I've got this code in a state I like I'll push an update to github.
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: (Yet another) Vintage Pi-Radio

Sun Oct 09, 2016 9:20 pm

If anyone's interested in testing, the bluetooth update is here: https://github.com/elParaguayo/PiRadio/ ... oth_update

I'll need to add comments and docstrings to the code to tidy it up a bit but it's in pretty good shape for a first stab at this.

Douglas - my bluetooth wrapping code is here. I may eventually have that module as a standalone repository too as it could be used more widely than just here. Also, I couldn't have done this without your code as a start. So, thank you!
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

User avatar
Douglas6
Posts: 4779
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: (Yet another) Vintage Pi-Radio

Sun Oct 09, 2016 11:55 pm

I just toook a quick look at your wrapper code, and a very cursory look at the bluetoothmode stuff. Very nice, much prettier than my mess. I have to say I don't like the polling versus using the gobject mainloop and callback functions, but I can't give a good reason why. Whatever works, works. If you do decide to pursue the mainloop route, I had it working at some point where mainloop was in it's on Python thread. Just remember to include 'gobject.threads_init()' anytime you use threads with gobject.

Once again, great work on PiRadio.

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: (Yet another) Vintage Pi-Radio

Mon Oct 10, 2016 5:40 am

Continuous polling isn't particularly elegant or satisfying so i may look to revisit the mainloop bit again.
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

texy
Forum Moderator
Forum Moderator
Posts: 5160
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: (Yet another) Vintage Pi-Radio

Mon Oct 10, 2016 6:52 am

Hi,
I may be need to start again with a fresh image as I think I broke the shairport-sync install when I added the USB soundcard. I don't get any audio out when selecting airplay. It's not coming out of the pi's on-board jack either. The other thing is that it doesn't pick up the ID that I named it in /etc/shairport-sync.conf so something is not right. When I installed shairport-sync I used the following options :

Code: Select all

./configure --sysconfdir=/etc --with-alsa --with-avahi --with-ssl=openssl --with-metadata --with-systemd 
Another issue I have is that with the metadata version of the code I just get an error relating to missing "/tmp/shairport-sync-metadata" file.
Maybe it's related to the first issue I have....

Many thanks for continuing with these new features and updates - it is much appreciated that you help others produce their own PiRadio's ;)

Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: (Yet another) Vintage Pi-Radio

Mon Oct 10, 2016 7:04 am

You almost certainly don't need to start again.

I think this can be fixed in the shairport sync config file.

I'll post more when I'm in front of my laptop again.
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: (Yet another) Vintage Pi-Radio

Mon Oct 10, 2016 7:21 am

Douglas,

I've not done much testing but it does seem that Bluetooth audio with an iPhone is significantly better than android.

The iPhone seemed to play stutter free even when the wifi was still enabled on the pi.
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: (Yet another) Vintage Pi-Radio

Mon Oct 10, 2016 8:13 am

texy wrote:Hi,
I may be need to start again with a fresh image as I think I broke the shairport-sync install when I added the USB soundcard. I don't get any audio out when selecting airplay. It's not coming out of the pi's on-board jack either. The other thing is that it doesn't pick up the ID that I named it in /etc/shairport-sync.conf so something is not right. When I installed shairport-sync I used the following options :

Code: Select all

./configure --sysconfdir=/etc --with-alsa --with-avahi --with-ssl=openssl --with-metadata --with-systemd 
Another issue I have is that with the metadata version of the code I just get an error relating to missing "/tmp/shairport-sync-metadata" file.
Maybe it's related to the first issue I have....

Many thanks for continuing with these new features and updates - it is much appreciated that you help others produce their own PiRadio's ;)

Texy
Texy,

Here's my /etc/shairport-sync.conf file:

Code: Select all

// Sample Configuration File for Shairport Sync
// Commented out settings are generally the defaults, except where noted.

// General Settings
general =
{
	name = "PiRadio";
//	name = "Shairport Sync Player"; // This is the name the service will advertise to iTunes. The default is "Shairport Sync on <hostname>"
//	password = "secret"; // leave this commented out if you don't want to require a password
//	interpolation = "basic"; // aka "stuffing". Default is "basic", alternative is "soxr". Use "soxr" only if you have a reasonably fast processor.
//	output_backend = "sysdefault:CARD=ALSA"; // Run "shairport-sync -h" to get a list of all output_backends, e.g. "alsa", "pipe", "stdout". The default is the first one.
//	mdns_backend = "avahi"; // Run "shairport-sync -h" to get a list of all mdns_backends. The default is the first one.
//	port = 5000; // Listen for service requests on this port
// 	udp_port_base = 6001; // start allocating UDP ports from this port number when needed
//	udp_port_range = 100; // look for free ports in this number of places, starting at the UDP port base (only three are needed).
//	statistics = "no"; // set to "yes" to print statistics in the log
//	drift = 88; // allow this number of frames of drift away from exact synchronisation before attempting to correct it
//	resync_threshold = 2205; // a synchronisation error greater than this will cause resynchronisation; 0 disables it
//	log_verbosity = 0; // "0" means no debug verbosity, "3" is most verbose.
//  ignore_volume_control = "no"; // set this to "yes" if you want the volume to be at 100% no matter what the source's volume control is set to.
//  volume_range_db = 60 ; // use this to set the range, in dB, you want between the maximum volume and the minimum volume. Range is 30 to 150 dB. Leave it commented out to use mixer's native range.
};

// How to deal with metadata, including artwork
metadata =
{
	enabled = "yes"; // et to yes to get Shairport Sync to solicit metadata from the source and to pass it on via a pipe
//	include_cover_art = "no"; // set to "yes" to get Shairport Sync to solicit cover art from the source and pass it via the pipe. You must also set "enabled" to "yes".
	pipe_name = "/tmp/shairport-sync-metadata";
};

// Advanced parameters for controlling how a Shairport Sync runs
sessioncontrol = 
{
//	run_this_before_play_begins = "/full/path/to/application and args"; // make sure the application has executable permission. It it's a script, include the #!... stuff on the first line
//	run_this_after_play_ends = "/full/path/to/application and args"; // make sure the application has executable permission. It it's a script, include the #!... stuff on the first line
//	wait_for_completion = "no"; // set to "yes" to get Shairport Sync to wait until the "run_this..." applications have terminated before continuing
//	allow_session_interruption = "no"; // set to "yes" to allow another device to interrupt Shairport Sync while it's playing from an existing audio source
//	session_timeout = 120; // wait for this number of seconds after a source disappears before terminating the session and becoming available again.
};

// Back End Settings

// These are parameters for the "alsa" audio back end, the only back end that supports synchronised audio.
alsa =
{
	output_device = "hw:CARD=ALSA,DEV=0";
//        output_device = "sysdefault:CARD=ALSA";
//  output_device = "default"; // the name of the alsa output device. Use "alsamixer" or "aplay" to find out the names of devices, mixers, etc.
//  mixer_control_name = "PCM"; // the name of the mixer to use to adjust output volume. If not specified, volume in adjusted in software.
//  mixer_device = "default"; // the mixer_device default is whatever the output_device is. Normally you wouldn't have to use this.
//  audio_backend_latency_offset = 0; // Set this offset to compensate for a fixed delay in the audio back end. E.g. if the output device delays by 100 ms, set this to -4410.
//  audio_backend_buffer_desired_length = 6615; // If set too small, buffer underflow occurs on low-powered machines. Too long and the response times with software mixer become annoying.
};

// These are parameters for the "pipe" audio back end, a back end that directs raw CD-style audio output to a pipe. No interpolation is done.
pipe =
{
//  name = "/path/to/pipe"; // there is no default pipe name for the output
//  audio_backend_latency_offset = 0; // Set this offset to compensate for a fixed delay in the audio back end. E.g. if the output device delays by 100 ms, set this to -4410.
//  audio_backend_buffer_desired_length = 44100; // Having started to send audio at the right time, send all subsequent audio this many frames ahead of time, creating a buffer this size.
};

// These are parameters for the "stdout" audio back end, a back end that directs raw CD-style audio output to stdout. No interpolation is done.
stdout =
{
//  audio_backend_latency_offset = 0; // Set this offset to compensate for a fixed delay in the audio back end. E.g. if the output device delays by 100 ms, set this to -4410.
//  audio_backend_buffer_desired_length = 44100; // Having started to send audio at the right time, send all subsequent audio this many frames ahead of time, creating a buffer this size.
};

// These are parameters for the "ao" audio back end. No interpolation is done.
ao =
{
//  audio_backend_latency_offset = 0; // Set this offset to compensate for a fixed delay in the audio back end. E.g. if the output device delays by 100 ms, set this to -4410.
//  audio_backend_buffer_desired_length = 44100; // Having started to send audio at the right time, send all subsequent audio this many frames ahead of time, creating a buffer this size.
};

// Static latency settings are deprecated and the settings have been removed. 
You'll see that the "metadata" section has several lines that have been uncommented (to enable it and to set the filepath for the data). This should fix the error you're getting about that file name. You'll also note that there's an option for album art...

For your sound issue, I suspect you just need to play with the "alsa" section to find the right output device.

On the ID point, i think this is hard coded rather than picking up your own value!
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

texy
Forum Moderator
Forum Moderator
Posts: 5160
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: (Yet another) Vintage Pi-Radio

Mon Oct 10, 2016 7:31 pm

Hi,
still no joy here. By ID, meant that shairport-sync isn't picking up either

Code: Select all

   name = "PiRadio";
...because although the pi is being detected by my iphone and itunes, it thinks it's called 'Raspberrypi'.
Also there is no audio because

Code: Select all

   output_device = "hw:CARD=ALSA,DEV=0";
has no audio from the on-board o/p jack, and if I change it to

Code: Select all

   output_device = "hw:CARD=ALSA,DEV=1";
when I expect it to pick up my USB card, there is still no audio.

On top of that I am still getting

Code: Select all

pi@raspberrypi:~/PiRadio-airplay_metadata $ sudo python main.py
Exception in thread Thread-4:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
    self.run()
  File "/home/pi/PiRadio-airplay_metadata/modes/lib/airplay_metadata.py", line 101, in run
    with open(META_PIPE, "r") as pipe:
IOError: [Errno 2] No such file or directory: '/tmp/shairport-sync-metadata'

I have tried to delete and reinstall shairport-sync, but that hasn't changed anything.
Time to start again........

Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: (Yet another) Vintage Pi-Radio

Mon Oct 10, 2016 8:11 pm

That python error is because of my lazy coding. It doesn't check for the file, it just assumes it's there.

However, it should be there if shairport-sync was running properly and it does sound like you've got a few issues.

Have you tried stopping the service and then running from the command line to see if any errors are apparent (or check the systemd logs)?

If the name isn't being picked up by your iPhone then it's a bit hard to understand what's causing the raspberrypi name. Have you got any other services running which could be advertising your pi?
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

texy
Forum Moderator
Forum Moderator
Posts: 5160
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: (Yet another) Vintage Pi-Radio

Mon Oct 10, 2016 10:04 pm

Sorry - just picked up your reply. I've spent all evening starting afresh. So two steps forward, one back :D
Airplay now working - picking up correct name, audio is coming out of the USB sound card and metadata is also there - so far so good.
So the bad is that bluetooth now connects, displays metadata, but no sound out of on-board or USB.
Time for bed, up a 6am as usual tomorrow.......maybe a reboot will sort it, but thats for tomorrow.
Cheers,
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

Return to “Graphics, sound and multimedia”