User avatar
thagrol
Posts: 1780
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Pi car music player advice

Wed Jan 09, 2019 10:27 pm

Just do it from your client. Those command run at startup only. Any subsequent commands from mpc or any other mpd client will override them.

You'd only need to login and edit the script if you wanted different startup behaviour.

Note that with a read only filesystem mpd won't be able to save its state file so it won't resume where it left off even if you remove the startup commands.
This space unintentionally left blank.

rivethead
Posts: 22
Joined: Fri Nov 30, 2018 6:54 pm

Re: Pi car music player advice

Thu Jan 10, 2019 4:01 pm

thagrol wrote:
Wed Jan 09, 2019 10:27 pm
Just do it from your client. Those command run at startup only. Any subsequent commands from mpc or any other mpd client will override them.

You'd only need to login and edit the script if you wanted different startup behaviour.

Note that with a read only filesystem mpd won't be able to save its state file so it won't resume where it left off even if you remove the startup commands.
I don't see any options to do that with the mpdroid client, maybe there's another one that does. Or I just haven't found out how yet.
I don't need it to resume where I left off as long as I can change it through the client. I like the default setting of random play on startup but would like to be able to change it to play an album in sequence when desired.

So far it's a great little player!

User avatar
thagrol
Posts: 1780
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Pi car music player advice

Thu Jan 10, 2019 5:00 pm

rivethead wrote:
Thu Jan 10, 2019 4:01 pm
I don't see any options to do that with the mpdroid client, maybe there's another one that does. Or I just haven't found out how yet.
I don't need it to resume where I left off as long as I can change it through the client. I like the default setting of random play on startup but would like to be able to change it to play an album in sequence when desired.
I'm not familiar witt mpdroid so can't give precise instructions but it should be something like this:
  • Clear current queue/playlist
  • Switch off repeat
  • Switch off random/shuffle
  • Add album to playlist
  • Hit play
It's not something I'd recommend doing whilst driving, have a passenger do it or do it before moving off. With the engine running otherwise you'll lose it when starting - most cars cut power to the accessory feed when running the starter motor.
So far it's a great little player!
:)
This space unintentionally left blank.

rivethead
Posts: 22
Joined: Fri Nov 30, 2018 6:54 pm

Re: Pi car music player advice

Mon Jun 24, 2019 4:44 am

Hi Guys,

I've continued to experiment with the pi zero as a music player. I'm struggling with making it Read-only so I don't have to wory as much about hard shutdowns. I always lose contact with the access point right after I run the commands for making the system read-only. Any ideas on what I might need to do to make a remote controlled pi creating an access point but continue to access once the switch is made?

User avatar
thagrol
Posts: 1780
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Pi car music player advice

Mon Jun 24, 2019 12:46 pm

This space unintentionally left blank.

rivethead
Posts: 22
Joined: Fri Nov 30, 2018 6:54 pm

Re: Pi car music player advice

Tue Jun 25, 2019 1:26 am

thagrol wrote:
Mon Jun 24, 2019 12:46 pm
This worked for me: https://learn.adafruit.com/read-only-raspberry-pi
I tried this and answered no to all three options. When I reboot the AP disappears. I wonder what I'm doing wrong?

User avatar
thagrol
Posts: 1780
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Pi car music player advice

Tue Jun 25, 2019 10:37 am

rivethead wrote:
Tue Jun 25, 2019 1:26 am
thagrol wrote:
Mon Jun 24, 2019 12:46 pm
This worked for me: https://learn.adafruit.com/read-only-raspberry-pi
I tried this and answered no to all three options. When I reboot the AP disappears. I wonder what I'm doing wrong?
Strange. Not sure what else to suggest. Sorry.
This space unintentionally left blank.

rivethead
Posts: 22
Joined: Fri Nov 30, 2018 6:54 pm

Re: Pi car music player advice

Wed Jun 26, 2019 2:14 am

I guess the probllem I keep getting myself into is once I create the access point the pi no longer has internet access so I can't run the read-only-fs script because it's looking for an internet connection to update what it needs. If I run this while it still has an internet connection I assume I then wouldn't be able to update the files needed to create the access point again.

User avatar
thagrol
Posts: 1780
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Pi car music player advice

Wed Jun 26, 2019 11:24 am

There's a couple of ways around that:
  1. Download the script before setting up the AP but don't run it until after doing so. IIRC the script itself doesn't need internet access to run.
  2. Run that script before setting up the AP then remount / read/write to setup the AP.This should do it:

    Code: Select all

    sudo mount -o remount,rw /
    It'll revert to read only at next boot or run this to switch back:

    Code: Select all

    sudo mount -o remount,ro /

The adafruit script needs to be run once, not on every boot.
This space unintentionally left blank.

rivethead
Posts: 22
Joined: Fri Nov 30, 2018 6:54 pm

Re: Pi car music player advice

Fri Jun 28, 2019 7:15 pm

Ok I succesfully built it and ran the adafruit script to make it read only. It does seem to need internet access because I see it updates packages from repositories. Could that not be the case? Either way I finally have it set up as read only which is perfect for random play in the car. The access point part has always been hit or miss for me though. If I remount as rw and go through the steps for access point I never know if in the end I'll be able to access the thing. Here goes!

Thanks again for your help

rivethead
Posts: 22
Joined: Fri Nov 30, 2018 6:54 pm

Re: Pi car music player advice

Fri Jun 28, 2019 7:51 pm

So it happened once again. I went through the steps to set up the access point to be able to remotely control it. Did exactly what the steps are and when I reboot I can't see the new network and can't access the pi. I really need to get this part resolved as its happened dozens of times. Any ideas?

User avatar
thagrol
Posts: 1780
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Pi car music player advice

Fri Jun 28, 2019 8:34 pm

Not really. Without access to your hardware and its log files I'm at a loss.

Having said that, here's a few long shot ideas to try:

I'm assuming you're trying to follow my write up at https://github.com/thagrol/ice-pi/blob/master/build.pdf and that you have a zeroW and are attemtping to use the onboard WiFi as an access point.
  1. Boot with a monitor connected and watch the output for errors.
  2. Login to the zeroW over a serial connection (from another Pi is safest). You can then check logs and "systemctl status hostapd" on the running system. As an alternative, you may be able to achieve the same thing with a USB ethernet adaptor rather than a serial connection.
  3. Using another linux box/live CD/pi with different SD card, edit /etc/fstab so "/" is mounted rw and reboot.
    See if that works.
    If so, it's possible that a log or state file for hostapd will need to be have it's location changed.

I'm a little short on time over the next few days but I'll try to find time to post the relevant config files from my working setup.
This space unintentionally left blank.

User avatar
thagrol
Posts: 1780
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Pi car music player advice

Fri Jun 28, 2019 10:07 pm

OK, these are the most relevant config files from my build:

/etc/fstab:

Code: Select all

proc            /proc           proc    defaults          0       0
PARTUUID=d92ab215-01  /boot           vfat    defaults,ro          0       2
PARTUUID=d92ab215-02  /               ext4    defaults,noatime,ro  0       1
# a swapfile is not a swap partition, no line here
#   use  dphys-swapfile swap[on|off]  for that

#ice-pi
/dev/mmcblk0p3	/music	vfat	ro	0	0
tmpfs /var/log tmpfs nodev,nosuid 0 0
tmpfs /var/tmp tmpfs nodev,nosuid 0 0
tmpfs /tmp tmpfs nodev,nosuid 0 0

/etc/hostapd/hostapd.conf:

Code: Select all

interface=wlan0
#driver=nl80211
ssid=ice-pi
country_code=GB
hw_mode=g
channel=7
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=ilikedrivinginmycar
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

/etc/dnsmasq.conf:

Code: Select all

interface=wlan0
dhcp-range=10.0.0.2,10.0.0.200,255.255.255.0,24h
dhcp-leasefile=/tmp/dnsmasq.leases
dhcp-authoritative
no-resolv
no-poll
server=8.8.8.8
server=8.8.4.4

/etc/init.d/hostapd:

Code: Select all

#!/bin/sh

### BEGIN INIT INFO
# Provides:		hostapd
# Required-Start:	$remote_fs
# Required-Stop:	$remote_fs
# Should-Start:		$network
# Should-Stop:
# Default-Start:	2 3 4 5
# Default-Stop:		0 1 6
# Short-Description:	Advanced IEEE 802.11 management daemon
# Description:		Userspace IEEE 802.11 AP and IEEE 802.1X/WPA/WPA2/EAP
#			Authenticator
### END INIT INFO

PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON_SBIN=/usr/sbin/hostapd
DAEMON_DEFS=/etc/default/hostapd
DAEMON_CONF=
NAME=hostapd
DESC="advanced IEEE 802.11 management"
PIDFILE=/run/hostapd.pid
LOGFILE=/var/log/hostapd.log

[ -x "$DAEMON_SBIN" ] || exit 0
[ -s "$DAEMON_DEFS" ] && . /etc/default/hostapd
[ -n "$DAEMON_CONF" ] || exit 0

DAEMON_OPTS="-f $LOGFILE -B -P $PIDFILE $DAEMON_OPTS $DAEMON_CONF"

. /lib/lsb/init-functions

case "$1" in
  start)
	log_daemon_msg "Starting $DESC" "$NAME"
	start-stop-daemon --start --oknodo --quiet --exec "$DAEMON_SBIN" \
		--pidfile "$PIDFILE" -- $DAEMON_OPTS >/dev/null
	log_end_msg "$?"
	;;
  stop)
	log_daemon_msg "Stopping $DESC" "$NAME"
	start-stop-daemon --stop --oknodo --quiet --exec "$DAEMON_SBIN" \
		--pidfile "$PIDFILE"
	log_end_msg "$?"
	;;
  reload)
  	log_daemon_msg "Reloading $DESC" "$NAME"
	start-stop-daemon --stop --signal HUP --exec "$DAEMON_SBIN" \
		--pidfile "$PIDFILE"
	log_end_msg "$?"
	;;
  restart|force-reload)
  	$0 stop
	sleep 8
	$0 start
	;;
  status)
	status_of_proc "$DAEMON_SBIN" "$NAME"
	exit $?
	;;
  *)
	N=/etc/init.d/$NAME
	echo "Usage: $N {start|stop|restart|force-reload|reload|status}" >&2
	exit 1
	;;
esac

exit 0
uname -a returns
Linux ice-pi 4.14.34+ #1110 Mon Apr 16 14:51:42 BST 2018 armv6l GNU/Linux
This space unintentionally left blank.

User avatar
thagrol
Posts: 1780
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Pi car music player advice

Fri Jun 28, 2019 10:14 pm

OK.

I have a likely candidate for the problem and it's in my write up.

If you use the dnsmasq.conf file I quoted above it should work. The problem is likely to be that default location for the leases fiel for dnsmasq isn't writeable.

To remind myself, I've opened an issue on my github for that project.

Do let me know if that fixes things for you.

My appologies for your lost time.
This space unintentionally left blank.

rivethead
Posts: 22
Joined: Fri Nov 30, 2018 6:54 pm

Re: Pi car music player advice

Sat Jun 29, 2019 12:29 am

Now I am even more confused. I added the extra lines you had in the dnsmasq file and it finally worked like you said! Having said that now I'm baffled because I never had more than the two lines for the wlan0 interface and the dhcp-range. In the past I have gone through your steps but have alternated with the access point part between yours and the raspberrypi forum post with similar steps. Do you think this problem appeared since I've made my system read only? I am also wondering what made it writeable now since it worked?

Thanks for catching this!

User avatar
thagrol
Posts: 1780
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Pi car music player advice

Sat Jun 29, 2019 10:28 am

rivethead wrote:
Sat Jun 29, 2019 12:29 am
Now I am even more confused. I added the extra lines you had in the dnsmasq file and it finally worked like you said! Having said that now I'm baffled because I never had more than the two lines for the wlan0 interface and the dhcp-range. In the past I have gone through your steps but have alternated with the access point part between yours and the raspberrypi forum post with similar steps. Do you think this problem appeared since I've made my system read only? I am also wondering what made it writeable now since it worked?

Thanks for catching this!
Yeah, it was the move to read only that broke it.

dnsmasq needs to write to the leases file to keep track of which clients have which IP addresses. The default location is on read only storage so it can't write to it and startup fails.

With the read only config I'm using /tmp is in RAM (via tmpfs) so putting the leases file there allows it to be written to though it will be lost on a power off or reboot.

I'd expect the RPF's documentation to be assuming a read/write filesystem so there's no need to move the leases file from its default location.
This space unintentionally left blank.

rivethead
Posts: 22
Joined: Fri Nov 30, 2018 6:54 pm

Re: Pi car music player advice

Sat Jun 29, 2019 3:43 pm

thagrol wrote:
Sat Jun 29, 2019 10:28 am
rivethead wrote:
Sat Jun 29, 2019 12:29 am
Now I am even more confused. I added the extra lines you had in the dnsmasq file and it finally worked like you said! Having said that now I'm baffled because I never had more than the two lines for the wlan0 interface and the dhcp-range. In the past I have gone through your steps but have alternated with the access point part between yours and the raspberrypi forum post with similar steps. Do you think this problem appeared since I've made my system read only? I am also wondering what made it writeable now since it worked?

Thanks for catching this!
Yeah, it was the move to read only that broke it.

dnsmasq needs to write to the leases file to keep track of which clients have which IP addresses. The default location is on read only storage so it can't write to it and startup fails.

With the read only config I'm using /tmp is in RAM (via tmpfs) so putting the leases file there allows it to be written to though it will be lost on a power off or reboot.

I'd expect the RPF's documentation to be assuming a read/write filesystem so there's no need to move the leases file from its default location.
I understand. So with this read only system we can update the music folder without needing to switch to rw but any config changes you need to ssh in and remount. So when adding the line for the leases file does it create it each time or does this directory exist from the dsmasq install? I'm just wondering how its writing to this file since it's read only.

User avatar
thagrol
Posts: 1780
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Pi car music player advice

Sat Jun 29, 2019 4:15 pm

rivethead wrote:
Sat Jun 29, 2019 3:43 pm
thagrol wrote:
Sat Jun 29, 2019 10:28 am
rivethead wrote:
Sat Jun 29, 2019 12:29 am
Now I am even more confused. I added the extra lines you had in the dnsmasq file and it finally worked like you said! Having said that now I'm baffled because I never had more than the two lines for the wlan0 interface and the dhcp-range. In the past I have gone through your steps but have alternated with the access point part between yours and the raspberrypi forum post with similar steps. Do you think this problem appeared since I've made my system read only? I am also wondering what made it writeable now since it worked?

Thanks for catching this!
Yeah, it was the move to read only that broke it.

dnsmasq needs to write to the leases file to keep track of which clients have which IP addresses. The default location is on read only storage so it can't write to it and startup fails.

With the read only config I'm using /tmp is in RAM (via tmpfs) so putting the leases file there allows it to be written to though it will be lost on a power off or reboot.

I'd expect the RPF's documentation to be assuming a read/write filesystem so there's no need to move the leases file from its default location.
I understand. So with this read only system we can update the music folder without needing to switch to rw but any config changes you need to ssh in and remount. So when adding the line for the leases file does it create it each time or does this directory exist from the dsmasq install? I'm just wondering how its writing to this file since it's read only.
The leases file is created by dnsmasq during start up if it doesn't already exist. It's updated as leases (IP addresses) are assigned and as they expire.

To understand why it can be writen to when in /tmp you need to understand a little about linux filesystems and mount points.

Essentiall a mount point is just a directory on some storage media. With nopthing mounted it'll usually be empty.

When something is mounted to it, instead of seeing what's on the storage medium in (or below that directory) you see the contents of the mounted file system.

To illustrate try this on a normal raspbian installation.

Code: Select all

sudo umount /boot
ls /boot
sudo touch /boot/hidden
sudo mount /boot
ls /boot
By mounting a tmpfs filesystem on /tmp we're providing some writeable storage at /tmp that exist only in RAM and never touches the SD card.

Putting the lease file in /tmp/something means dnsmasq can create and write to it as much as it wants without ever trying to write to the SD card.
This space unintentionally left blank.

Return to “Media centres”