Home of the Squeezebox™ & Transporter® network music players.
Results 1 to 8 of 8
  1. #1
    Junior Member
    Join Date
    Oct 2017
    Posts
    7

    [SOLVED] Mobile PiCorePlayer: Is it possible to play music from USB-Stick?

    Solution below.

    Hi all,

    I am building a battery powered PiCorePlayer based music player (rPi Zero W, 3,5" display, PhatDAC). At home I have the LMS server running on my NAS, everything works fine. I also want to play music when I am not at home, i.e. from a USB stick.

    I would install LMS on with the PiCorePlayer. However, I don't want to access the web-interface to mount the USB-stick. esepcially, if I am not at home, the player will probably not be connected to any network...

    My question therefore is: Is it possible to tell the LMS server to auto-mount a USB stick and scan it for media.

    Any help is greatly appreciated!

    Thanks
    DomCa


    Solution:

    Summing up my experience, here is what I did:

    I installed LMS on the RPI an dconfigured it to load music from "/mnt/sda1" and playlists in "/home/tc". The USB stick is mounted read only so no unmount is necessary...
    I also isntalled the curl extension.

    I then created a udev rule file: /etc/udev/rules.d/99-mount-usb.rules

    Code:
    ACTION=="add", KERNEL=="sda1", SUBSYSTEM=="block", RUN+="/bin/sh -c '/bin/mount_reload.sh'", OPTIONS="last_rule"
    I also created the script file /bin/mount_reload.sh

    Code:
    #!/bin/sh
    mount -o ro /dev/sda1 /mnt/sda1
    curl -s http://localhost:9000/settings/index.html?p0=rescan > /dev/null
    run: chmod a+wx /bin/mount_reload.sh

    for a working backup add to the file /opt/.filetool.lst:

    etc/udev/rules.d/99-mount-usb.rules
    bin/mount_reload.sh

    Backup the system to permanently store the changes.


    I am no linux-pro, there may be better solutions, but I am quite happy with what I acchieved...
    Last edited by DomCa; 2019-08-22 at 07:38.

  2. #2
    Senior Member chill's Avatar
    Join Date
    Mar 2007
    Posts
    1,335
    pCP doesn't automount by default. I believe it might be possible to achieve that, but I went a slightly different way by scripting the mounting process (I run an overnight backup via cron, and I check if the backup disk is inserted and then mount it).

    It's also possible to use the pCP Command Line Interface to trigger a 'clear and rescan' (with 'pcp wipecache').

    But I'm not sure how you'd:
    a) trigger the script that mounts and then rescans - a button on the GPIO pins perhaps? - or
    b) tell LMS that the new stick is the path to your music. I guess if the mount script always put the stick on the same mountpoint that would solve that.

    If you could somehow run such a script at boot then you wouldn't need another way to trigger it, but you'd be doing a 'clear and rescan' with every boot.

  3. #3
    Junior Member
    Join Date
    Oct 2017
    Posts
    7
    Hi Chill,


    thank you for the tip! I think using a dedicated button will be easily possible in my project! I will just havew to find a way to trigger a script via the button.


    Cheers!
    DomCa

  4. #4
    Senior Member chill's Avatar
    Join Date
    Mar 2007
    Posts
    1,335
    Quote Originally Posted by DomCa View Post
    thank you for the tip! I think using a dedicated button will be easily possible in my project! I will just havew to find a way to trigger a script via the button.
    Check out SqueezeButton Pi Daemon (sbpd). It can be installed as a pCP Extension. It started life as a way to trigger LMS commands, but it now also allows you to run a script. One of my buttons now calls a one-line script to safely shutdown pCP if I need to kill the power ('pcp bs').

  5. #5
    Senior Member chill's Avatar
    Join Date
    Mar 2007
    Posts
    1,335
    My sbpd command line, with all but the 'pcp bs' button removed for clarity.

    Code:
    sbpd -d -M dc:a6:32:03:82:22 -A 192.168.1.4 -P 9000 -f /home/tc/sbpd_commands.cfg b,27,POWR,2,0,SCRIPT:/home/tc/pcp_bs.sh,2000
    The -M, -A and -P options force the program to work on a specific player on a specific instance of LMS - not necessary in your case I think.

    The -f option points to my config file, where various commands are defined. But only the POWR command is left in this example (this toggles the soft power on the player with the specified MAC address (dc:a6:32:03:82:22). My POWR command is defined in sbpd_commands.cfg as 'POWR=["power"]')

    The string 'b,27,POWR,2,0,SCRIPT:/home/tc/pcp_bs.sh,2000' means that a short push on button GPIO27 will use the POWR command to toggle the player's soft power, while a long press (>2000 millisec, i.e. 2 seconds, to avoid accidental presses) will call the pcp_bs.sh script.
    Last edited by chill; 2019-07-31 at 03:00. Reason: I forgot the -d option.

  6. #6
    Member
    Join Date
    Apr 2019
    Location
    Wunstorf, Germany
    Posts
    54
    I am using PiCorePlayer always with local music and local LMS. For this I attached a M.2 SSD with 512MB via an USB M.2 enclosure to my Pi 3B+ with 7ô display in an SmartiPi enclosure.

    The M.2 SSD behaves like an USB stick. I have it mounted read only as it is HFS+ format (to be synced easier with my iTunes library on my Mac) and use the cache for LMS on an extra attached small USB stick.

    The only problem is that the Pi needs a network to work. Via WiFi it is difficult I think because you have to specify the SSID and password.

  7. #7
    Junior Member
    Join Date
    Oct 2017
    Posts
    7
    Hi all,

    sorry for my late answer. I have been on vacation.

    I now found a very nice solution. I use udev rules to automount any USB sticks /dev/sda1 to /mnt/sda1 and then run the reload command for the LMS. No need for any other plugins or the like...

    Best regards,
    DomCa

    The udev file I use is named "99-usbmount-reload.rules" in directory /etc/udev/rules.d/

    ACTION=="add", KERNEL=="sda1", SUBSYSTEM=="block", RUN+="/bin/sh -c '/bin/mount_reload.sh'", OPTIONS="last_rule"
    ACTION=="remove", KERNEL=="sda1", SUBSYSTEM=="block", RUN+="/bin/umount /mnt/sda1", OPTIONS="last_rule"

    I suppose the remove would not be required.

    The script file mount_reload contains:

    #!/bin/sh
    mount /dev/sda1 /mnt/sda1
    pcp wipecache
    Last edited by DomCa; 2019-08-22 at 06:09.

  8. #8
    Junior Member
    Join Date
    Oct 2017
    Posts
    7
    Ok. I will still need to figure out, how to tell squeezlite in the PiCorePlayer to connect to the local LMS instead my network LMS...
    And to connect back to the network LMS after the USB stick is detached.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •