WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Tutorial: Unpluggable Squeezebox player on piCore  (Read 10638 times)

Offline Gerrelt

  • Full Member
  • ***
  • Posts: 182
Tutorial: Unpluggable Squeezebox player on piCore
« on: February 06, 2014, 04:36:19 AM »
Hi everybody,

I've converted my notes to a turorial, which I placed on a webpage.
You can use this tutorial to create a Squeezebox player on a Raspberry Pi which can connect to the LMS Media Server. This will enable you to play internet radio stations and the music files (mp3 etc) on your server.
See this page:

http://www.gerrelt.nl/RaspberryPi/wordpress/tutorial-unpluggable-squeezelite-player-on-tinycore/

Greetings,
    Gerrelt.
« Last Edit: February 06, 2014, 05:38:11 AM by Gerrelt »
my Raspberry Pi page: http://raspberry.gerrelt.nl

Offline Gerrelt

  • Full Member
  • ***
  • Posts: 182
Re: Tutorial: Unpluggable Squeezebox player on piCore
« Reply #1 on: January 10, 2015, 03:31:47 AM »

I've made the startup daemon script that I use on Raspbian compatible with piCore.
The advantage is that all the functions in the script (auto-play, change favorite etc.) can now be used on piCore too.
The tutorial now descibes how to use it.

If you want to change your current installation to use this daemon script, execute these commands:

Code: [Select]
tce-load -wi bash.tcz
sudo ln -s /tmp/tcloop/bash/usr/local/bin/bash /bin/bash
sudo echo "bin/bash" >> /opt/.filetool.lst

sudo wget http://www.gerrelt.nl/RaspberryPi/squeezelitehf.sh
sudo mv squeezelitehf.sh /usr/local/etc/init.d/squeezelite
sudo chmod a+x /usr/local/etc/init.d/squeezelite

sudo wget http://www.gerrelt.nl/RaspberryPi/squeezelite_settings.sh
sudo mv squeezelite_settings.sh /usr/local/bin
sudo chmod a+x /usr/local/bin/squeezelite_settings.sh

sudo echo "usr/local/etc/init.d/squeezelite" >> /opt/.filetool.lst
sudo echo "usr/local/bin/squeezelite_settings.sh" >> /opt/.filetool.lst

sudo cp /opt/bootlocal.sh /opt/bootlocal.sh.old

Now, open the settings script with:

Code: [Select]
sudo nano /usr/local/bin/squeezelite_settings.sh
And change the settings that you also did in the bootlocal.sh script (saved to /opt/bootlocal.sh.old).
You probably only changed the soundcard.

Now change the bootlocal.sh script to the new daemon script. Open the script:

Code: [Select]
sudo nano /opt/bootlocal.sh
And remove all the lines below "# when using wifi, connect to wifi before this line".
And put this line there in it's place:

Code: [Select]
/usr/local/etc/init.d/squeezelite start
Now, don't forget to save it all to the SD card:
Code: [Select]
filetool.sh -b
And carelessly  :D  unplug and plug in the raspberry to do a reboot.
Squeezelite should now be started automatically.

Daemon script functions
This script has more functions then just starting squeezelite. It contains funtions that do autoplay, play a favorite, stop playing, set volume and update squeezelite.
Especially the autoplay function is usefull, it will send the "play" command to the raspberry. With this you can make the player automatically start playing when the raspbery is booted.
This function can be triggered by the SL_AUTO_PLAY setting in the squeezelite_settings.sh file.

Also the play favorite function can be handy. You could schedule to play certain internet radio stations at certain times.
my Raspberry Pi page: http://raspberry.gerrelt.nl

Offline Greg Erskine

  • Sr. Member
  • ****
  • Posts: 402
Re: Tutorial: Unpluggable Squeezebox player on piCore
« Reply #2 on: January 10, 2015, 07:27:00 PM »
hi Gerrelt,

Thanks for posting your stuff. It always makes for interesting reading.

I do have a couple of questions:

1. Where have you needed to use bash instead of just sh?
2. Did you ever find out why the favourite id changes every time you poll LMS?
(id:1a8989c4.1) The first 8 digits just seem to be a random number.
3. Have you found anyone that uses "folders" in their favorites?

regards
Greg

Offline Gerrelt

  • Full Member
  • ***
  • Posts: 182
Re: Tutorial: Unpluggable Squeezebox player on piCore
« Reply #3 on: January 11, 2015, 06:40:59 AM »
Hi Greg,

"Answers"   ;D :

1. I don't know anymore. At one point, while making some changes to the script, I discovered I needed bash for something.
It probably had something to do with "if" statements or expressions.

2. No, I haven't found out why yet.

3. No. I didn't even know that was possible. I just checked and discovered the "new folder" button. That probably doesn't work with my play_fav function.

Greetings,
    Gerrelt.
my Raspberry Pi page: http://raspberry.gerrelt.nl

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1072
Re: Tutorial: Unpluggable Squeezebox player on piCore
« Reply #4 on: January 11, 2015, 11:07:41 AM »

2. Did you ever find out why the favourite id changes every time you poll LMS?
(id:1a8989c4.1) The first 8 digits just seem to be a random number.

Interesting.....I don't play favorites this way.   If you edit the favorite, it shows a link to the source, that never changes.
i.e.
http://opml.radiotime.com/Tune.ashx?id=s21156&formats=aac,ogg,mp3,wmpro,wma,wmvoice&partnerId=16&serial=356568cff86c8a969096f2a09aa9bf95

try running your favorite query like this.....the url will be after the url tag.
Code: [Select]
80:1f:02:xx:xx:xx favorites items 0 1000 want_url:1

Offline Gerrelt

  • Full Member
  • ***
  • Posts: 182
Re: Tutorial: Unpluggable Squeezebox player on piCore
« Reply #5 on: January 12, 2015, 10:46:45 AM »
Hi Paul,

 I don't think I understand your reply.

I tried what you suggested, but it just returns the same as without the URL
The command is not for starting to play a certain favorite, but for retrieving the favorites list.

Greetings,
    Gerrelt.
my Raspberry Pi page: http://raspberry.gerrelt.nl

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1072
Re: Tutorial: Unpluggable Squeezebox player on piCore
« Reply #6 on: January 12, 2015, 12:11:40 PM »
I thought you were trying to gather a list of favorites to be able to play them, or to setup a startup sequence.   Once the URL is captured, they it does not have to remain in the favorites.

The URL is in addition to the rest of the tags normally returned........

Offline Gerrelt

  • Full Member
  • ***
  • Posts: 182
Re: Tutorial: Unpluggable Squeezebox player on piCore
« Reply #7 on: January 12, 2015, 12:51:10 PM »
Ah, I see. I just found the want_url tag in the command line manual too.
But, indeed, that is not entirely what I want.

The way it works now is working fine, the id does work when referencing it.
But the strange thing is that the hexidecimal part of the ID (before the dot) is different everytime you query the favorites.

I think it is some kind of query result reference id.
my Raspberry Pi page: http://raspberry.gerrelt.nl

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1072
Re: Tutorial: Unpluggable Squeezebox player on piCore
« Reply #8 on: January 12, 2015, 02:50:41 PM »
Ah, I see. I just found the want_url tag in the command line manual too.
But, indeed, that is not entirely what I want.

The way it works now is working fine, the id does work when referencing it.
But the strange thing is that the hexidecimal part of the ID (before the dot) is different everytime you query the favorites.

I think it is some kind of query result reference id.

So in a perfect world, what is the way it would work?

Offline Greg Erskine

  • Sr. Member
  • ****
  • Posts: 402
Re: Tutorial: Unpluggable Squeezebox player on piCore
« Reply #9 on: January 12, 2015, 03:06:07 PM »
thanks Gerrelt and Paul_123,

I reckon both the id or url references will work fine. I wonder why you can't reference directly via the favorite's title?

The documentation mentions item_id:1.2.3.4, so I think returning the leading hexadecimal string is just a bug that won't be fixed.

I noticed using item_id:10 or item_id:00000000.10 works just as well as  item_id:523809ac.10.

I am checking hasitems tag in my code to get just first level favorites and ignoring any directories and mysqueezebox.com.

The favorites feature in LMS is great, I wonder why I have never used it the last 10 years?

regards
Greg
« Last Edit: January 12, 2015, 03:08:13 PM by Greg Erskine »

Offline Gerrelt

  • Full Member
  • ***
  • Posts: 182
Re: Tutorial: Unpluggable Squeezebox player on piCore
« Reply #10 on: January 13, 2015, 09:37:06 AM »
The documentation mentions item_id:1.2.3.4, so I think returning the leading hexadecimal string is just a bug that won't be fixed.
I noticed using item_id:10 or item_id:00000000.10 works just as well as  item_id:523809ac.10.

Ah, that's good to know!
Yeah, it's probably a bug. Maybe in the favorites the top level has id NULL, and that produces the wierd hex number.

So in a perfect world, what is the way it would work?

I would have expected a unique number per favorite, so you can always reference that number if you want a certain favorite.
But the way it works now is fine too.

my Raspberry Pi page: http://raspberry.gerrelt.nl

Offline lykkedk

  • Full Member
  • ***
  • Posts: 182
Re: Tutorial: Unpluggable Squeezebox player on piCore
« Reply #11 on: January 16, 2015, 11:30:38 AM »
Hi Gerrelt  :)

Real hardcore coding you have done here mf.

Good job!

As i only need, one part (At a start) the autoplay at boot, could you perhaps tell me, howto do that ?

RG;
Jesper.

Offline Gerrelt

  • Full Member
  • ***
  • Posts: 182
Re: Tutorial: Unpluggable Squeezebox player on piCore
« Reply #12 on: January 17, 2015, 07:22:29 AM »
Hi Jesper,

 Thanx!

Sure I can tell you.
After starting squeezelite it takes a while before the LMS server has accepted the new player. So you cannot immediately send a "play" command to the LMS server.
You will have to wait until the squeezelite player has fully connected.

I do that by using the "connected" command from the LMS command line (see line 6 in the code below).
If the call returns 0, it means it is not connected. So I call the "connected" command in a loop with a 1 second sleep (line 13) until the connected command returns 1.

When it's connected I first send a command to switch on the player on the LMS server. For this I use the "power" command from the LMS command line (see line 22 in the code below).

After that a start playing command can be send to the LMS server.
For that I created a different function called "do_play" in the script (line 26.

This is the code for waiting until squeezelite is connected and the switch on command:

Code: [Select]
    # next commands can only be done if Squeezebox server IP is set
    if  [ ! -z "$SB_SERVER_IP" ]; then
      echo "Wait until player is connected to Squeezebox server before sending play command"
      for i in $(seq 1 10)
      do
        PLAYERCONNECTED=$(printf "$SL_NAME connected ?\nexit\n" | nc $SB_SERVER_IP $SB_SERVER_CLI_PORT  | tr -s ' '| cut -d ' ' -f3)
        if [ "$PLAYERCONNECTED" == "1" ]
        then
          echo "Player connected to Squeezebox server after $i seconds"
          break
        fi
        echo "Not connected after $i seconds..."
        sleep 1
      done
     
      if [ "$PLAYERCONNECTED" == "1" ]
      then
        # connected
     
        # First send power-on command to squeezebox server
        echo "Sending power on command for player ${SL_NAME} (${SL_MAC_ADDRESS}) to Squeezebox server (${SB_SERVER_IP} ${SB_SERVER_CLI_PORT})"
        printf "$SL_MAC_ADDRESS power 1\nexit\n" | nc $SB_SERVER_IP $SB_SERVER_CLI_PORT > /dev/null
     
        # check if auto play is set
        if [ ! -z "$SL_AUTO_PLAY" ] && [ "${SL_AUTO_PLAY^^}" == "YES" ]; then
          do_play
        fi
      else
        echo "Could not send play command to player $SL_NAME on Squeezebox server $SB_SERVER_IP"
      fi
     
    fi

In the do_play function I use the "play" command (see line 7) from the LMS command line. This is the code:

Code: [Select]
do_play()
{
    VOLUME=$1
    # This function only works if the Squeezebox server IP is set
    if  [ ! -z "$SB_SERVER_IP" ]; then
      echo "Sending play command to Squeezebox server"
      printf "$SL_NAME play\nexit\n" | nc $SB_SERVER_IP $SB_SERVER_CLI_PORT > /dev/null
      if  [ ! -z "$1" ]; then
         # volume has to be set
         do_set_volume "$VOLUME"
      fi
    else
      echo "The IP address of the Squeezebox server is not set (variable: SB_SERVER_IP should be set). This is needed for the play function."
    fi
}

Greetings,
    Gerrelt
my Raspberry Pi page: http://raspberry.gerrelt.nl

Offline lykkedk

  • Full Member
  • ***
  • Posts: 182
Re: Tutorial: Unpluggable Squeezebox player on piCore
« Reply #13 on: January 17, 2015, 07:55:26 AM »
Hey thank you Gerrelt

I will look into it, and try to make it work!

Youre SB-Server still resides on another machine (NAS/Laptop etc... etc..)?

Thank again...

jesper.

Offline Gerrelt

  • Full Member
  • ***
  • Posts: 182
Re: Tutorial: Unpluggable Squeezebox player on piCore
« Reply #14 on: January 17, 2015, 08:05:32 AM »
Yes, my LMS server is running on my NAS.
my Raspberry Pi page: http://raspberry.gerrelt.nl