Giter Site home page Giter Site logo

miczflor / rpi-jukebox-rfid Goto Github PK

View Code? Open in Web Editor NEW
1.3K 1.3K 394.0 26.37 MB

A Raspberry Pi jukebox, playing local music, podcasts, web radio and streams triggered by RFID cards, web app or home automation. All plug and play via USB. GPIO scripts available.

Home Page: http://phoniebox.de

License: MIT License

Python 20.86% Shell 32.19% PHP 39.96% CSS 3.11% Hack 1.14% C++ 0.56% JavaScript 2.19%
audio contactless jukebox musicbox raspberry rfid rfid-jukebox

rpi-jukebox-rfid's People

Contributors

alvinschiller avatar amtee avatar andreasbrett avatar berdsen avatar bernipi avatar caliandroid avatar dependabot[bot] avatar felb-dectris avatar fredg02 avatar groovylein avatar luegengladiator avatar manajoe avatar miczflor avatar miohna avatar mtill avatar pabera avatar patrickweigelt avatar princemaxwell avatar raspfarbend avatar s-martin avatar schneelocke avatar splitti avatar themorlan avatar topas-rec avatar veloxid avatar veloxidschweiz avatar xn--nding-jua avatar yordan1976 avatar zxa avatar zyanklee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rpi-jukebox-rfid's Issues

Resume folder instead of restarting

Hi,

first off: love this! I build a jukebox for my little son and it's great :)

I have an enhancement request: Resume a playlist/folder instead of restarting it. A restart could be done on second scan.

I would like to use this for Audiobooks, but it's annoying that it starts from the beginning everytime. I already looked into the (horribly extensive) vlc man file but couldnt find an option to "resume" a previously played playlist, so we would probably need to do a workaround for that. Something like:
Create a file within the folder that will note down progress within that folder and that gets read by the script if the folder is started again. The "new card" event could check for running vlc, get the current playstate and log that out into that file. I'll try to experiment a bit with that and may do a pull request, but maybe you have that in your backlog already :)

Install on Ubuntu Mate for the Raspberry Pi

Here just some notes on stuff I had to do to get the software running on Ubuntu Mate for Raspberry Pi instead of Raspbian. Maybe someone else will find it helpful.

  • PHP has to be installed with sudo apt install php php-cgi instead of the command given in the docs. This will install PHP7, which seems to work flawlessly.
  • As on Mate the username is set during the install, it's usually differet from the common pi user on Raspbian. I hence had to change $conf['base_path'] in ./htdocs/config.php to match my home folder.
  • I could not get auto login for my user working via raspi-config as recommended in the docs. As a workaround, I added autostart of the demon to /etc/crontab instead, which works (almost) the same way.
  • Last but not least, I somehow have to run the demon with sudo to have sound. Probably just a missing group membership or something like that, but I have yet to investigate.

So far everthing works great, thanks again for sharing! :)

Toggle mute/unmute

Hi MiczFlor,

I followed your guide and have the system up & running. Thanks for your efforts!
(the components are still spread out accross my desk; fitting them into a nice case will be the harder part ;))

I made two small additions in ~/scripts/playout_controls.sh

  1. the mute command now toggles between mute/unmute,
  2. the volumeup/-down commands now also unmutes if needed and starts from the volume level that was set before sound was muted.

To do that, I basically just save the current volume level to a file and read it from there if the file is present (=volume was muted), otherwise the commands just work as before.

This is just mimicking the common behaviour from remote controls.
(I've added a cheap 5-button remote Seki Slim + IR-receiver TSOP4838 over GPIO + jumper cables - no soldering, right? - for less than 10€)

Code is:

[...]
VOLSTEP=5
VOLFILE=/var/tmp/volume
[...]
elif [ $COMMAND == "mute" ]
then
	[ ! -e $VOLFILE ] && (amixer sget \'$DEVICE\' | egrep -o '[[:space:]][0-9]+[[:space:]]' | tail -n1> $VOLFILE && amixer sset \'$DEVICE\' 0%) || (amixer sset \'$DEVICE\' `<$VOLFILE` && rm -f $VOLFILE)

elif [ $COMMAND == "setvolume" ]
then
    amixer sset \'$DEVICE\' $VALUE%

elif [ $COMMAND == "volumeup" ]
then
    [ -e $VOLFILE ] && (vol=`<$VOLFILE` && vol=`expr ${vol} + ${VOLSTEP}` && amixer sset \'$DEVICE\' $vol && rm -f $VOLFILE) || (amixer sset \'$DEVICE\' ${VOLSTEP}+)

elif [ $COMMAND == "volumedown" ]
then
	[ -e $VOLFILE ] && (vol=`<$VOLFILE` && vol=`expr ${vol} - ${VOLSTEP}` && amixer sset \'$DEVICE\' $vol && rm -f $VOLFILE) || (amixer sset \'$DEVICE\' ${VOLSTEP}-)
[...]

Let me know what you think!

Volume Up/Down not working for stereo faders

I've installed the script on a RPi Zero W with Raspbian stretch. I've noticed that the Volume Up/Down feature seems to be broken:

./playout_controls.sh -c=volumedown
30 30
expr: syntax error

It seem to be not possible to do math with the output of that grep line:

   # read volume in percent
    VOLPERCENT=`amixer sget \'$DEVICE\' | grep -Po '(?<=\[)[^]]*(?=%])'`
    echo $VOLPERCENT
    # increase by $VOLSTEP
    VOLPERCENT=`expr ${VOLPERCENT} - ${VOLSTEP}

I haven't found a fix (i experimented with let, declare -i ....).
Is this code working for anyone?

auto start services w/ cron tab

Hi Mic

I upgraded my Jukebox with a Hifeberry.
Now I wanted to add buttons. But everytime I register the GPIO script for startup no music won't be able to be played.

RPi-Jukebox-RFID with a Pi Zero?

Has anyone tried this project using a Raspberry Pi Zero?
I have an unused Pi Zero and would like to avoid buying an additional pi 3 if I don't have to. I'm wondering if anyone has tried, or has any thoughts on, using a Pi Zero with a Micro USB to USB OTG hub.

Additionally, this Pi Zero already has pins soldered in from a previous project, so I plan on adding the GPIO button functionality.

I'm curious if anyone has any experiences or thouhgts on this before I get started.

Thanks,
PJ

Stop on RFID removal

Is it possible to stop playback on rfid-remove instead of additional rfid to stop?

Reader won't connect unless unplugged and plugged in again after reboot

Hi, I am not very keen with linux, I got everything working but for some reason the reader (which is the same as used in the manuals here PCP-BCG4209) doesn't show up in the list via sudo lsusb unless I unplug it and plug it back in. So, when I reboot my RPi there's no barcode reader available, even though it beeps on startup, LED is on and it beeps when putting an RFID tag on top of it. Anyone's got an idea? Many thanks in advance!

Play Spotify

Hello,

thanks for the great work.
Will it be possible to play songs or playlists from Spotify premium?

Thanks four your help!

404 Error on Web App Login

Hallo zusammen. Meine Hardware nach der MiczFlors Anleitung läuft und ich teste fleißig. Aktuell noch über den HDMI Ausgang an meinen Verstärker, aber die Boxen kommen erst diese Woche. Leider geht das Web Interface nicht wenn ich die IP des PI ins Iphone eingebe. Ich bekommen nur einen Fehler 404. Was ja eigentlich auf einen falschen Link hinweist.

Hätte Ihr einen Tipp, was ich noch prüfen könnte? Kann es mit einem Fehler der Samba Konfiguration zusammen hängen?

No update on Web App

Hi, I just implemented the scripts and the web server for configuration starts well. But any update in the web app and also the RFID are not updating so there is no interaction. What could be the reason?
Regards
Christian

Controlling by RFID

Hi Micz,
yesterday and today I installed twice your system with jessie to a new sd-card.
Now I can start a song by rfid without problems.
But when I prepare the rfid_trigger_play.sh to control
pause, shutdown, next etc with rfid
it does not respond.
With stretch and without webinterface everthing works well. So I am not sure where the problem is.
Best regards
Ulli

Web App does not render as it should

Hi @MiczFlor,

as my other issue is closed now, I am tackling now one on my jukebox that I initially set up with a version prior to the current version (0.9.4).

The web app somehow renders not very nicely in my browser on PC / Smartphone (see screenshot below). I already performed a GIT fetch, but this did not help. The version file got updated to 0.9.4 through the fetch. I also ran the upgrade commands that you posted.

Would you have an idea or advice how I could get the web app properly running?

webinterfacebefore0 9 4

Thanks for your feedback!
Tom

Delay Cron running scripts

Oh boy!! This took me forever to figure out - yes, I'm a raspi noob. Anyway documenting here, so no one else wastes time on this.

Issue: daemon_rfid_reader.py worked perfectly when running through SSH manually. However, when running at reboot, it just didn't play the audio files when triggered by RFID tag. It turns out that cron ran them too early in the boot process.

Solution: Delay running the script by 60 secs.
@reboot sleep 60 && mpg123 /home/pi/RPi-Jukebox-RFID/misc/startupsound.mp3
@reboot sleep 60 && python2 /home/pi/RPi-Jukebox-RFID/scripts/daemon_rfid_reader.py &

VLC Alternatives like mpv

Is it possible to get a different playback tool?
As a commandline tool mpv looks more efficient than vlc.
goodies: --save-position-on-quit can be set via config or commandline.
Maybe this makes #30 and #40 obsolete?

WebInterface

I have reinstalled the JukeBox three days ago. After the new installation the WebInterface does not show the available Audio Files and Audio Folders. Have you changed something on the scripts? On my previous installation it was working very well.

Use APT as installer

Simplify the Installation process with requirements and default Installer Pakages for RPi

Webinterface Sound Controls not working with USB Sound

Hi,

first, thanks for that great project :-)

Im using a external USB Soundcard (Soundblaster Play).
I did manage to get the Card working.

Everything is working fine except the volume control via webinterface.

I discoverd that i have to use different command to adjust Volume
amixer -D hw:U0x41e0x30d3 sset Speaker 100%
Think it is due to the command amixer sset ´PCM´ 100% is not working.
I was able to adjust the Control Script for RFID but i do not know what and where i have to adjust the files for the webinterface to get it to work there as well.
Think it has to be adjustet like i did it in the control script.
Can you please help me.

Thanks

order audio by type

From the code it's possible to order the type of audio in subfolders:

find . -type d | grep shared
./shared/audiofolders
./shared/audiofolders/weblinks
./shared/audiofolders/weblinks/ZZZ-YouTube-Link1
./shared/audiofolders/weblinks/ZZZ-YouTube-Link2
./shared/audiofolders/audiobooks
./shared/audiofolders/audiobooks/Audiobook1
./shared/audiofolders/audiobooks/Audiobook2
./shared/audiofolders/audiobooks/Audiobook3
./shared/audiofolders/podcasts
./shared/audiofolders/podcasts/ZZZ-Podcast-1
./shared/audiofolders/podcasts/ZZZ-Podcast-2
./shared/audiofolders/music
./shared/audiofolders/music/music1
./shared/audiofolders/livestreams
./shared/audiofolders/livestreams/ZZZ-Webstream1

you have to create the same folderstructure in playlists

find . -type d | grep playlists
./playlists
./playlists/audiobooks
./playlists/livestream
./playlists/podcasts
./playlists/music
./playlists/webstream

to store the m3u.

Now it's possible to recreate or keep the m3u by type of audio.
You want to recreate it on podcast or store it in audiobooks.
There is no need to change the code. Only remember to create the shortcut with the specific subfolder:

cat 5000112547726
audiobooks/Audiobook1

cat 4045145288001
music/music1

Internetradiostreams do not start

Hi MiczFlor,

first of all thanks a ton for this super cool project. I just finished with the set up of the first jukebox, which is for our daughter. Now my wife demands another one for her godchild. :-)

With the second one I got an issue as I cannot playback internet radio streams. Local files work like a charm. Would you have a suggestion how to investigate? I already checked and found out that the latest installation is on version 0.9.4. The previous jukebox I had set up does not have a version ID in the \RPi-Jukebox-RFID\settings folder so it must be an earlier version.

Both jukeboxes run based on the Jessie Guide.

Thanks for your feedback
Tom

Multiple RFIDs for Jukebox controls

More of a question than an issue:

My plan is to have cards represent songs while key chain tokens represent controls.

My son will get a key chain with (some) volume control and stop. In addition there is an "admin" key chain for us parents that contains the whole set of controls.

This would require me to set more than one ID for certain levels of volume. Is that currently possible?
I can think of a workaround for this by distributing the range of volumes between two key chains but I would much rather prefer to have two stop commands handy.

Using the web app is an option if we are not outside our wifi, I know. But on vacation it would be a different thing.

Docs: listing simple controls for USB sound device

First, thanks for all the work that went into Phoniebox! I just built one as a birthday gift for my daughter and can't wait to see her test it out.


I am using the latest Raspbian stretch.

$ uname -a
Linux raspberrypi 4.14.52-v7+ #1123 SMP Wed Jun 27 17:35:49 BST 2018 armv7l GNU/Linux

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Raspbian
Description:	Raspbian GNU/Linux 9.4 (stretch)
Release:	9.4
Codename:	stretch

My goal was to use a USB sound device (CM 108 chip) instead of the Raspberry's built-in one. I got an output, but at first I could not set the volume.

My /home/pi/RPi-Jukebox-RFID/settings/Audio_iFace_Name file had the value PCM in it, so I checked the docs at

https://github.com/MiczFlor/RPi-Jukebox-RFID/blob/master/docs/CONFIGURE-stretch.md#create-settings-for-audio-playout

and saw the comment about listing the available iface names using amixer controls. For me, this results in

$ amixer controls
numid=3,iface=MIXER,name='Mic Playback Switch'
numid=4,iface=MIXER,name='Mic Playback Volume'
numid=7,iface=MIXER,name='Mic Capture Switch'
numid=8,iface=MIXER,name='Mic Capture Volume'
numid=9,iface=MIXER,name='Auto Gain Control'
numid=5,iface=MIXER,name='Speaker Playback Switch'
numid=6,iface=MIXER,name='Speaker Playback Volume'
numid=2,iface=PCM,name='Capture Channel Map'
numid=1,iface=PCM,name='Playback Channel Map'

Unfortunately, it is not really obvious, which names of these would be usable as the iface name. I tried using the value MIXER, without success.

I ended up checking the amixer help and found the amixer scontrols command, which lists these results:

Simple mixer control 'Speaker',0
Simple mixer control 'Mic',0
Simple mixer control 'Auto Gain Control',0

So I tried the value Speaker in the file /home/pi/RPi-Jukebox-RFID/settings/Audio_iFace_Name and it worked immediately.

Not sure if this is specific to the versions I used or for the sound device. However I think instead of amixer controls the docs should recommend amixer scontrols.

Another unrelated note: I recognise no difference in quality between the 6 EUR USB sound device and the Raspberry 3 Model B+ built-in one. Both are prone to CPU noise.

Reading RFID tags fails

Hello!

I followed the installation guide which worked very well for me and I did not get a single error message during the whole installation and configuration process. So to begin with a big THANK YOU to MiczFlor. My kids can't wait using the Jukebox.

The webserver, external soundcard, samba etc. are working fine and also the connected devices seem to work properly. Music is also playing when using the webserver. IDs are recognized and files are created on the samba share...

The only (and essential) issue though is that the "translation" of RFID tags into music playback does not work. Like if there is something wrong in the listening process / the setup of the python script. When holding an RFID tag at the device it shows me the ID on the console and on top of that an error message "-bash : 0005347171: command not found" (In German: "-bash : 0005347171: Kommando nicht gefunden). However I have followed the setup carefully and can confirm the right device (rfid-reader) is being listened to.

Any idea what else I could check?

Many thanks for your help (would be much appreciated!)

Best
Jan

RFID Reader

Komme leider bei der Einrichtung nicht weiter:
Habe als RFID Reader einen RC522 und diesen per GPIO angeschlossen.
Mit folgender Anleitung: https://tutorials-raspberrypi.de/raspberry-pi-rfid-rc522-tueroeffner-nfc/
bekomme ich ihn einzeln ohne Probleme zu laufen.

Mein eigentliches Problem ist, dass ich leider nicht weiß, wie ich diesen hier genau integrieren soll.
Da ich kein USB-Reader habe bin ich mit "python2 RegisterDevice.py" leider total aufgeschmissen und weiß mir ehrlich gesagt auch nicht zu helfen.

Gruß
André

RFID reader working properly ??

Hi all,

I followed the steps above with the exact same hardware...
Unfortunately, my RFID-Reader doesn't seem to work properly.
It's making it's "BEEP"-sound on power-on - but there's no beep when I'm holding a NFC Card next to it... and YES - they are the nfs cards that came with the reader and should therefore be the compatible types.

I could not find any setup steps regarding the reader during the tutorial !?

Shouldn't there be any drivers installed for the reader ??

Thanks and many greets !!

Mark

Commands via script do not work

Hey there,

I'm running the project (on an older release) and I have the issue, that the pause-button by rfid is not working. It pauses successfully, when I use the Webinterface button, or type the command echo "pause" | nc.openbsd -w 1 localhost 4212 in a ssh session. But using a rfid-card does not work.

pi@jukebox:/etc $ sudo systemctl status rfid-reader.service
● rfid-reader.service - RFID-Reader Service
   Loaded: loaded (/etc/systemd/system/rfid-reader.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2018-05-13 20:17:35 CEST; 7s ago
 Main PID: 1369 (python2)
   CGroup: /system.slice/rfid-reader.service
           └─1369 /usr/bin/python2 /home/pi/RPi-Jukebox-RFID/scripts/daemon_rfid_reader.py

May 13 20:17:35 jukebox systemd[1]: Started RFID-Reader Service.
May 13 20:17:42 jukebox python2[1369]: CARDID = 1028061683
May 13 20:17:42 jukebox python2[1369]: pausing <- added this, to verify that the if-statement triggered
May 13 20:17:42 jukebox python2[1369]: VLC media player 2.2.6 Umbrella
May 13 20:17:42 jukebox python2[1369]: Command Line Interface initialized. Type `help' for help.
pi@jukebox:/etc $

Using wget http://jukebox/index.php?player=pause works inside ssh also, but still not inside the script. Any ideas, how this could be?

Resume last played track now working! (especially for audiobooks)

Hey,

I tried for the last week to implement a set of scripts that allows to resume the last played track and I finally made it work - the Jukebox now saves the last played playlist, song and position and resumes after reboot of the pi. It's not perfect since the song starts for a second before resuming to the last played position. I'm still trying to tweak that with mute/unmute or working with shorter sleep() in milliseconds.

My appraoch (code see below): The VLC which the RPi-Jukebox uses offers a XML file, that shows all information on the playing track (like artist, title, current position, current track number of the playlist). I took those information and saved it into separate text files - (artist and title for a display that I plan for the future) as well as the current track position and playlist number. Since the "download" of this xml is pretty slow (1-3 seconds), I only use it when pressing the button for "pause" or "shutdown".
Current track position and playlist number I use in combination with the VLC remote functions "goto x" and "seek x" (seek is already integrated in the code with seek 0 as a possibility to start the track from beginning). "goto x" works similarly, it makes vlc jump to the specific item on the playlist and plays it.
To make it work, the playlist cannot be temporary like in the original project, so I changed the path in the rfid_trigger_play.sh to RPi-Jukebox-RFID\shared\playlists\ (First I chose the Folder containing the mp3s itself, however that did not work as all the files in the folder are used to create the playlist, including the m3u's. So I added the subfolder. At the sametime I exported the path of the m3u to a textfile to use after reboot.
Now I have all I need, the playlist and the text files containing current position and current track.

I then created a bash-script that runs after boot of the pi, starts the VLC, loads the playlist, jumps to the current track and plays a specific position.

Now to my code:

  1. To make VLC produce the xml change in the rfid_trigger_play.sh the line

cvlc --no-video --network-caching=10000 -I rc --rc-host localhost:4212 "$PLAYLISTPATH" &

to

cvlc --no-video --network-caching=10000 -I rc --extraintf=http --http-password 123 --rc-host localhost:4212 "$PLAYLISTPATH" &

  1. When already in rfid_trigger_play.sh also change the playlist from temporary to permanent:

instead of

PLAYLISTPATH="/tmp/$FOLDERNAME.m3u"

set

PLAYLISTPATH="$PATHDATA/../shared/playlists/$FOLDERNAME.m3u" (not sure if you need to create the folder "playlists" in ./shared first or if the script does it for you - if you want to be sure, create it first with mkdir playlists.

Additionally we want to export the path of the playlist to a textfile, to be able to remember the last used playlist at start of the pi:

Still in rfid_trigger_play.sh add
echo "$PATHDATA/../shared/playlists/$FOLDERNAME.m3u" > $PATHDATA/../shared/lastplayed.txt
after
find "$PATHDATA/../shared/audiofolders/$FOLDERNAME" -type f | sort -n > "$PLAYLISTPATH"

  1. This is my script to exploit the VLC xml,intended to be run when button for "shutdown" or "pause" are pressed (Created with nano /home/pi/RPi-Jukebox-RFID/scripts/getCurrentSongDetails.py)
#!/usr/bin/python3
#/home/pi/RPi-Jukebox-RFID/scripts/getCurrentSongDetails.py
from bs4 import BeautifulSoup
import urllib.request

def get_currentSongDetails():

    password_mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
    top_level_url = "http://127.0.0.1:8080/requests/status.xml"
    password_mgr.add_password(None, top_level_url, '', '123')
    handler = urllib.request.HTTPBasicAuthHandler(password_mgr)
    opener = urllib.request.build_opener(handler)
    u = opener.open(top_level_url)
    soup = BeautifulSoup(u, 'html.parser')
    currents = []

    for info in soup.select('info'):            # Selects the info category
        if info['name'] == 'title':             # Selects the title inside the info category
            currents.append(info.text)          # Writes title into the currents-array
    for playid in soup.select('currentplid'):   # Selects the current playlist-number of the track
            currents.append(playid.text)        # Writes the playlist-number in the currents-array
    for current in soup.select('time'):           #Selects the current position in the track
        currents.append(current.text)           # Writes the current position into current-array

    return (currents)
currentSongDetails = get_currentSongDetails()

#with open ("/home/pi/RPi-Jukebox-RFID/shared/latestSong.txt", "w") as text_file:     #for putting on a #display - later!
# for (cur) in currentSongDetails[0]:
#     text_file.write('{}'.format(cur))

with open ("/home/pi/RPi-Jukebox-RFID/shared/latestPlid.txt", "w") as text_file2:
   for (cur) in currentSongDetails[1]:
    text_file2.write('{}'.format(cur))

with open ("/home/pi/RPi-Jukebox-RFID/shared/latesttime.txt", "w") as text_file3:
   for (cur) in currentSongDetails[2]:
    text_file3.write('{}'.format(cur))

Relevant output are the the textfiles latestPlid.txt and latesttime.txt that contain the last played playlist-item and the track position. (I don't know why, but the VLC playlists start with track position 4 - so the first song of the playlist has PLID 4, the second has 5 and so on). Here I'm pretty sure python does not creates the textfiles latestPlid.txt, latesttime.txt and latestsong.txt in ./shared for you - better create them yourself beforehand via nano latestPlid.txt (then CTRL-O and Enter to save, CTRL-X to close; same for latesttime.txt, latestsong.txt).

  1. Now my script that should run while/after booting the pi:
#!/usr/bin/env bash
#/home/pi/RPi-Jukebox-RFID/scripts/lastplayed.sh

sudo pkill vlc #necessary?
VLCPLAYS=$(</home/pi/RPi-Jukebox-RFID/shared/lastplayed.txt)
cvlc --no-video --network-caching=10000 -I rc --extraintf=http --http-password 123 --rc-host localhost:4212 "$VLCPLAYS" &

sleep 5 

PLID=$(</home/pi/RPi-Jukebox-RFID/shared/latestPlid.txt)
echo "goto $PLID" | nc.openbsd -w 1 localhost 4212

sleep 1

SONGTIME=$(</home/pi/RPi-Jukebox-RFID/shared/latesttime.txt)
echo "seek $SONGTIME" | nc.openbsd -w 1 localhost 4212

The service I use to start the script lies in /etc/systemd/system/ and looks like this:
(Just copy the code into a new file via nano /etc/systemd/system/resumesong.service then sudo systemctl daemon-reload to inform the system that there's a new service, then sudo systemctl enable resumesong.service to start the service.)

[Unit]
Description=Resume Last Song Service
After=network.target iptables.service firewalld.service rfid-reader.service

[Service]
WorkingDirectory=/home/pi/RPi-Jukebox-RFID
ExecStart=/home/pi/RPi-Jukebox-RFID/scripts/lastplayed.sh
KillMode=process
SendSIGKILL=no

[Install]
WantedBy=multi-user.target
  1. To save playlist, track and position in the track I run the getCurrentSongDetails.py (see No. 2) when play/pause or shutdown buttons are pressed. Theoretically you can run it also when pressing next and/or previous buttons, however knowing my daughter hitting next-button a hundred times to find her favorite song - i really don't know what happens if the "download" of the vlc-xml is requested with the same staccato...

To run the script fetching the data you need to change the gpio-buttons.py in the following way:

add in headline

import time

and change

def def_shutdown():
     check_call("/home/pi/RPi-Jukebox-RFID/scripts/playout_controls.sh -c=shutdown", shell=True)

to

def def_shutdown():
     check_call("/home/pi/RPi-Jukebox-RFID/scripts/getCurrentSongDetails.py")
     time.sleep( 3 )
     check_call("/home/pi/RPi-Jukebox-RFID/scripts/playout_controls.sh -c=shutdown", shell=True)

Also change

def def_halt():
   call("/home/pi/RPi-Jukebox-RFID/scripts/playout_controls.sh -c=playerpause", shell=True)

to

def def_halt():
   call("/home/pi/RPi-Jukebox-RFID/scripts/playout_controls.sh -c=playerpause", shell=True)
   check_call("/home/pi/RPi-Jukebox-RFID/scripts/getCurrentSongDetails.py")

Don't forget to make the new scripts and textfiles accessible with sudo chmod +x <file>!

Done!

I started python only a week ago - so most of my code is stolen or the result of trial and error - if you have any recommendations for simplifying it, let me know.

RC522 module

First of all thank you for this awesome tutorial. Even as bloody beginner I was able to get most of my own project - a jukebox for my little son - running. The only thing which suddenly stopped me was, that you are using an USB RFID reader instead of the RC522 module, which I am using.
If somebody can give me a hint how to integrate this one instead of an USB reader, this would be great!

php5 -> php7

Great work! :-)
With actual raspbian stretch this line from installation manual doesn't work anymore:
sudo apt-get install php5-common php5-cgi php5

PHP5 isn't available anymore as installation package.

It should be substituted simply with:
sudo apt-get install php-common php-cgi php

This installs PHP7 and everything works as it should.

Hardware hack: Play only if RFID is near the reader

Not an "issue" at all, but i want to leave it anywhere as documentation if somebody else is interested (like in #43):

I wanted to have a feature that the player stops if you remove the RFID card from the reader. The problem, discussed here before, is that the reader transmits the card number via USB only one time after it read it and there's no way via USB to "see" for the RPi if the card is still near the reader.

When i got my reader (it's a Neuftech 125 kHz (Amazon link) i found an interesting behaviour: if the reader "sees" the card, a light turns from red to green and stays green, as long as the card is near. So i opened it up and found following:

neuftech1

When the red led is on ("the idle state") there are approx. 2.7 V on point A and a few mV on point B. When the green LED is active (a card is near), there are 3.2 V on point B. This is almost exactly the voltage a GPIO of the RPi can bear. So i attached a 5k Ohm ( found by trial and error: i started with higher values and ended up with that, where it was working reliable) to point B (thanks to the manufacturer for the convenient soldering point in the board) and wired that with a GPIO pin:

neuftech2

Then i defined the stop key in the gpio-buttons.py as following:

stop = Button(6, pull_up=False) (the Pin has to be pulled down, as i apply the voltage from the reader)
stop.when_released = def_stop

So, when a card comes near the reader, the rfid_trigger_play.sh starts the audio. My "LED voltage GPIO button" is pressed and stays in that state until the card is removed. Then the "released" event is triggered by the gpio-buttons.py.

I'm planing to enhance this function in that way, that the audio is paused on removal, but this is not as easy as the solution above. Maybe the code from #47 may help.

I don't know if this works with other readers as well, but if your device shows the same behaviour as i described above, chances are high.

latestID.txt file not being created

Hi, I went through the manuals a few times now and I cannot find what I may have missed. Right now, when I swipe an RFID tag/card all it does is "typing" the ID into the shell (754852442 command not found), but there is no latestID.txt file being created in the shared folder at all. I guess it's something obvious, but my "limited" Linux skills are preventing me from spotting the issue...
Hope someone can help me? Thanks in advance!

Use ACR122U as RFID reader

I am trying to get an ACR 122U working as RFID cardreader. The reader is seen on the USB port, but it looks like it is not reporting as HID input device

root@testbank:/opt/RPi-Jukebox-RFID/scripts# lsusb | grep ACR
Bus 001 Device 006: ID 072f:2200 Advanced Card Systems, Ltd ACR122U
root@testbank:/opt/RPi-Jukebox-RFID/scripts# 
Bus 001 Device 006: ID 072f:2200 Advanced Card Systems, Ltd ACR122U
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0         8
  idVendor           0x072f Advanced Card Systems, Ltd
  idProduct          0x2200 ACR122U
  bcdDevice            2.07
  iManufacturer           1 ACS
  iProduct                2 ACR122U PICC Interface
  iSerial                 0 
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           93
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              200mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           3
      bInterfaceClass        11 Chip/SmartCard
      bInterfaceSubClass      0 
      bInterfaceProtocol      0 
      iInterface              0 
      ChipCard Interface Descriptor:
        bLength                54
        bDescriptorType        33
        bcdCCID              1.00
        nMaxSlotIndex           0
        bVoltageSupport         7  5.0V 3.0V 1.8V 
        dwProtocols             2  T=1
        dwDefaultClock       4000
        dwMaxiumumClock      4000
        bNumClockSupported      0
        dwDataRate          10752 bps
        dwMaxDataRate      250000 bps
        bNumDataRatesSupp.      0
        dwMaxIFSD             256
        dwSyncProtocols  00000000 
        dwMechanical     00000000 
        dwFeatures       00020040
          Auto parameter negotation made by CCID
          Short APDU level exchange
        dwMaxCCIDMsgLen       271
        bClassGetResponse      00
        bClassEnvelope         00
        wlcdLayout           none
        bPINSupport             0 
        bMaxCCIDBusySlots       1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0008  1x 8 bytes
        bInterval               2
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
Device Status:     0x0000
  (Bus Powered)

Is it still possible to use this reader (since i had it laying arround)

Subfolder

Hi,

first of all, I want to compliment your work on this project.

Everything works fine for me, but i've got a question.

Is it possible to link the RFID-Card to a subfolder?

For example:

Card Nr. 1 plays the files in folder /audiofolders/folder1/folder2

Thanks for all
Steffen

INSTALL.md-Suggestions after successful build

First, thanks a bunch for the effort you put in this project and for the detailed instructions. It worked out flawlessly for me and will supply my daughter with a great piece of easy-to-use hardware.
Hats off to you.

I just wanted to suggest a couple of minor-changes for the INSTALL.md-Tutorial, on passages which caught me off-guard:

  • Installscript
    I did not see (or better: i missed) the well commented installscripts in /scripts/installscripts/ - maybe they ought be linked in the tutorial for their time-saving nature?

  • Configuring lighttpd
    In the last step of configuring lighttpd, we set the rights for the shared-folder to make sure ist is accessible by the web server. But at this point in the build-process the folder does not yet exist. We are cloning the repo a couple of steps down the line. maybe the chmod-action should be placed under the "Install git"-section?

  • Using a USB soundcard and changing the volume
    I made use of the linked stackexchange-article regarding the configuration of the usb soundcard via ~/.asoundrc.
    It worked without a problem. But after finishing up everything else, i was not able to set the volume via the Web-App.
    I had to edit Line 60 in /htdocs/index.php and replace 'PCM' with 'Speaker' - this might be helpful for others ordering from your proposed shopping-list (like i did). The line in question looks like this now:

    exec("/usr/bin/sudo amixer sset 'Speaker' ".$urlparams['volume']."%");

  • PHP7
    Since we are living in PHP7-Times i used the following Line to install the php-dependencies

    sudo apt-get install lighttpd php7.0-common php7.0-cgi php7.0

    i can report, it all seems to work just fine.

trouble adding user "pi" to samba

awesome tutorial! thanks for sharing!
i followed the steps of going into the flie "/etc/samba/smb.conf"

  1. i fixed the workgroup and the wins support
  2. i added the path found in the document
  3. i went to a new line in the file and added user: pi and password: raspberry
  4. i saved and exited
  5. in the terminal, i entered sudo smbpasswd -a pi, but got the error "command not found"

phatbeat as DAC

I'm not sure if "issue" is the right place. Just a hint for phatbeat users.

In my setup with a RPI2 and a phatbeat, with standard install from pimoroni everything besides volume controls worked correct.
After changing the Audio_iFace_Name from "PCM" to "Master" everything is working.

gpio buttons

Hey there,
maybe you can help me out. what could be the best way to use gpio buttons for forward and rewind tracks using the gpio buttons. i read a lot about it but i am not able to do it right now. maybe you can give me a hint.

playout_controls.sh - use "=" instead of "=="

took me some time to discover this. from shell i could run the script without errors, but launched within python via check_call it throws this error:
volumeup: unexpected operator
Unknown COMMAND volumeup VALUE

i've read that only few shells support == in if-constructions, so i had to change
every occurance of $COMMAND == "xyz" to $COMMAND = "xyz"

regards,
phil

Web app: control buttons too small

On my Android device it's hard to hit the right button for the player control because they are pretty small (and i'm in the believe to not have abnormal fat fingers ;-).

Is this different on Apple devices?

As i'm working on the Web App at the moment (adding a settings page) i could fix this.

How to leave MP3s on USB-Stick

Sorry this is not a real issue, only a hint:
You may add this to the readme, how one can use RPi-Jukebox with MP3s on an USB stick.
The USB-stick is automatically mounted to
/media/usb0
I leave all MP3 there and put only softlinks to the audiofile folder with this command:

ln -s /media/usb0/* /home/pi/RPi-Jukebox-RFID/shared/audiofolders/

This may help some beginners.

New idea: Sleeptimer function command? Turn off after ideling 30 minutes?

Hi @MiczFlor ,

my wife came up with the idea of having a sleeptimer command. E. g. swipe a RFID card, which makes the raspberry shut down after 45 minutes to not consume the whole powerbank overnight when accidently left turned on.

May in general it would also be good to have an option to automatic turn off the pi, if there is no playback for 30 minutes.

What do you think about this?

Best regards
Tom

Let the jukebox run with root mounted read-only

To avoid corruption due to sudden power loss and to reduce write wear on the sd card it would be good to have the system run on a read-only mounted root.

This is not a feature request - I'm already working on this.

unable to register device

after calling python2 python2 RegisterDevice.py I get the following:
Traceback (most recent call last):
File "RegisterDevice.py", line 4, in
from evdev import InputDevice, list_devices
File "/usr/local/lib/python2.7/dist-packages/evdev/init.py", line 9, in
from evdev.uinput import UInput, UInputError
File "/usr/local/lib/python2.7/dist-packages/evdev/uinput.py", line 35
def from_device(cls, *devices, filtered_types=(ecodes.EV_SYN, ecodes.EV_FF), **kwargs):

Shopping list

Hello,

There is an mistake on the shopping list.
The link for the sound card is used twice.
The link for the USB A Male to Female Extenstion Cable with Switch On/Off is missing.

Regards
Daniel

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.