Monday, July 19, 2021

Airplay (Shairport-sync) on the Raspberry Pi and Disabling Wifi Power Save

As of this writing on Jul 19th 2021 I am having trouble with the packaged version of shairport-sync. This page outlines how to fairly simply compile it from a different repository and also to disable the problematic wifi power save mode which can cause skipping.

 

I am now running 4 different raspberry pi’s with the Shairport-sync software to receive airplay streams from our phones and computers and they work great. The ones connected via WiFi tend to have dropouts while the ones with physical connections seem to work perfectly all the time and almost never skip. This seems to be in spite of the power or memory of the machines in question which range from pi zero’s through Pi3 B+ and a couple of Pi4’s now.

I recently upgraded the one we use the most to a Pi4 trying to see if that would solve the problem, and I wanted it to run some other software at the same time and thought it would be worth doing a reload on that older Pi3. 

I initially tried the standard distribution of the shairport-sync installed via:

sudo apt install shairport-sync

That worked great except that I could not seem to make any changes to the configuration file. If you just want to use your hostname as the share name and do not need to change any other configuration options then this will work just fine and you don’t really need to do anything else other than enable it via the systemctl enable shairport-sync and then reboot. I didn’t want my hostname to be the share name and whenever I made any changes to the configuration file, which the standard package installs in /etc/shairport-sync.conf instead of the other standard location where it has been as long as I can remember in /usr/local/etc/shairport-sync.conf, it would just crash upon starting up.

I uninstalled it and decided to scrape around and do an actual build of the software from the same repository that I used originally for the others. There are several forks available the one I used successfully is this one by github user Mike Brady

First install some necessary packages to be able to build it, this should be done after you’ve updated the software on your pi via the normal methods.

sudo apt install autoconf libtool libdaemon-dev libasound2-dev libpopt-dev libconfig-dev
sudo apt install avahi-daemon libavahi-client-dev
sudo apt install libssl-dev
sudo apt install git

Now we need to clone the git repository and to the configure and make steps:


cd ~
git clone https://github.com/mikebrady/shairport-sync.git
cd shairport-sync
autoreconf -i -f
./configure --with-alsa --with-avahi --with-ssl=openssl --with-systemd --with-metadata

If there are other options you wish to compile in like the mqtt server or others that configure line is the place to add them.

Once those are done you can do the make and install:

make
sudo make install

And enable the app to run at startup like this:

sudo systemctl enable shairport-sync

If you wish to change the name of the share as it appears to iOS devices or increase the timeouts for resyncs which I also did for a little more leeway with a bad wifi connection you can edit the configuration file which should be placed in /usr/local/etc/shairport-sync.conf via the command:

sudo nano /usr/local/etc/shairport-sync.conf

You’ll find the name entry at the top of the first section, you can uncomment theirs and change it or just add a line like:

name="Living Room";

you can also scroll down a bit to find the drift and resync tolerances. If you really want to have several servers all receiving the stream at the same time and playing the same music in sync then you should not alter these, but if you are mostly using one at a time as I do for whatever room I’m in and not the entire system you can increase their default times by altering the default lines which look like:



// drift_tolerance_in_seconds = 0.002; // allow a timing error of this number of seconds of drift away from exact synchronis$
// resync_threshold_in_seconds = 0.050; // a synchronisation error greater than this number of seconds will cause resynchron$

uncomment those and experiment with larger values. For myself I increase the drift tolerance to 0.05 and the resync threshold to 0.1

There are SO many suggestions out there on how to force the wifi power save mode to stay off after a restart but only this one worked for me. You can check to see if the wifi power save is on by running the command:


iw dev wlan0 get power_save
and change it via the command:
sudo iw dev wlan0 set power_save off

It seems that despite all protestations by many people that this is now off by default on their pi’s it is most definitely on when mine reboot. We need to create a systemctl command to run at startup that will execute the command above. If you have more than one wifi interface or are using the descriptive names option in the newer Pi OS’s you may have to use a different name than wlan0 but that is the default if you haven’t changed anything as of this writing.

Create the file with the nano editor like this:


sudo nano /etc/systemd/system/wifi_power_save_off.service

Paste the following into the file and save with ctrl-o and then ctrl-x to exit the editor.

[Unit]
Description=Set WiFipower save off so no skipping of audio
After=sys-subsystem-net-devices-wlan0.device

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/sbin/iw dev wlan0 set power_save off

[Install]
WantedBy=sys-subsystem-net-devices-wlan0.device

In order for the systemctl system to see this additional file you have to run the reload daemon command and finally enable it with these 2 commands:

sudo systemctl daemon-reload
sudo systemctl enable wifi_power_save_off

Now reboot your pi and check to see that your shairport-sync share shows up in your iOS devices properly and then run the "iw dev wlan0 get power_save" command again to make sure that it has run properly.

Thursday, February 4, 2021

Dead Instrument Cluster, part: The Second

 See my previous article and then know that 4 days later it died again. 

I was lucky in that I never cancelled the appointment to get it fixed so when that day rolled around I drive it in without any instrument display. The only danger was that I didn’t know how fast I was going which was easily solved by running Wayz on my iPhone and that I didn’t know how much gas it had in it but my wife assured me it was nearly full when it went dark again ;) 

They took over 2 hours to decide that it was actually broken again and that they would need to order a new instrument cluster. I told them that in moment one, but OK whatever. Since the last one failed only 4 months ago they are going to replace it under warranty. 

They really didn’t want me to take it back home without a speedometer, so I had to sign a hand written phrase on the receipt to the effect that I had been counseled about the dangers of driving it without a speedometer. I signed it, I have one. At least approximate on my phone. I tried to explain that too.

Sadly the part is back ordered so they don’t know how long it will take to get a replacement.

Luckily I decided to take it apart yet again and do some lower level debugging of the connections to the board. This time I was going to take it apart, actually de-solder a component, and then re-solder it with leaded solder and put it together enough to do a quick test. That way I can be sure what I touched and didn’t unlike the first time when I just randomly reflowed anything that was large enough for me to safely handle without a lot of prep work.

Step one was just the connector to the board itself. I used a combination of a solder sucker and solder wick to remove maybe 80% of the solder holding the connector in place from the back. And then generously fluxed it and resoldered it with standard leaded solder. Put the device together enough to test it with both displays connected again. and the screws holding them in installed so that the very weak little connectors for them wouldn’t get broken or torn and it lit right up.

So the problem is definitely in the connection of the connector and not in the other power supply components that I resoldered in the first entry of this saga.

If you think you can do this I would encourage you not to. See my first entry that has more info on the very delicate connectors for the screens and other parts. But since it’s dead anyway and they were going to replace it anyway I decided it couldn’t get any more dead than it was so I took a chance.

If it is still working when I finally get the call from them in the future that the real part is back in stock and to bring it in for replacement it’s going to be a tough decision what to do. Do I keep the one I’ve been fixing and hope it keeps working? Do I let them replace it with another one that is definitely going to have the same problem but now I know how to fix it? Do I let them even notice that I fixed it? Or just claim that it spontaneously started working again and has been on and off for all that time? I like that last one but I don’t want to lie to them. I’d really like to keep this one as a spare and let them replace it with a new one. Thats the offer I’ll make them I think. I’ll be sure to update with more information if the backordered replacement ever arrives ;) When we got this first replacement we had to tell them what the odometer reading was so that they could get it burned into the new one. They didn’t ask me this time so either they will call back when it is ready to go and then spend more time getting that burned in or it will just come with it set to 0. Since the car only has 40k miles on it it would be hilarious to reset it to 0. I’m pretty sure that they will call to ask me. The temptation is to tell them less than the last time just for fun ;) We keep our cars until they are ready to be junked so I won’t be using that to sell it to someone else fraudulently, but just curious what they would say...

Friday, January 29, 2021

Instrument Cluster Board Level Repairs And The Evils of Lead Free Solder

 My wife drives a Ford C-Max “energie” plugin hybrid. It is an awesome little car that Ford no longer bothers to sell in the US because they failed to market it well enough and it became unprofitable for them to keep them around. Or it is possible that Americans really are only interested in double sized trucks and SUV’s and simply don’t want smaller cars at all. I don’t know but I suspect a combination of both problems exist. In any case I was in Chicago 4 months ago caring for my mom and I got a call from home saying that the dashboard on the car was completely blank. Had to manage remotely getting her a rental and getting the car fixed at the dealership. A couple of thousand dollars later we had a new instrument cluster as the old one was dead. It took weeks to get fixed as a new one had to be ordered with the proper odometer reading burned into it. 


This morning it did it again! Not even a full 4 months later! Car starts but the instrument cluster stays dark and eventually the touch screen/ radio comes up with a message that says “Vehicle Network Communication Error” and will not do anything else. Other interesting side effects are that the climate controls defaulted back to Celsius without being able to talk to the instrument cluster. 

Since there is no way to control most of the car and no way to know easily how fast you’re going the car is simply not safe to drive that way beyond just not having to have it towed to the dealership. 

The local Ford dealership said that since this was an electrical problem it required special attention from special people and they wouldn’t be able to even begin to work on it for 5 days! Don’t bother bringing it in before this coming Wednesday! And no willingness to tell me if this would be a warranted repair since they just did it. 

As I sat here fuming about how long we’d have to rent a car for as they ordered another new one for us I decided that since it was dead anyway I’d take it out and have a look at it. I’ve rarely regretted doing that and have often found that I could make a repair to something that would have cost a lot of money to replace unnecessarily. 

It turns out that it’s very easy to remove the instrument cluster from most Ford cars. There are lots of youtube videos about it but basically you pull the cowling that connects the rubbery sheet that covers the top of the adjustable steering column to the plastic under the cluster straight towards you and then that reveals the 2 7mm bolts that hold in the cluster. Make sure to adjust the steering wheel all the way down and forward or you can’t get it out. On this C-Max there are 2 clips that you need to force to let go directly behind it, but I have no idea if just yanking it straight out is the right thing to do for your model or not. It was the right thing for mine. Grab the cluster and pull it straight towards you until they let go. If you do it wrong or yours is held on differently though you might break something expensive so find a take apart video for your specific model before you start applying excessive force to anything.

There is a single connector on the back that you can reach around and find the pinch spot to easily remove it. You may want to put a towel over the cowling part or any other exposed plastics to keep from scratching them as you figure out how to get the cluster out from between the steering wheel and the dashboard. It is possible, but only just.



 

It actually look me longer to clear enough room on the desk to work on it than to get it out of the car ;) After carefully removing all the other plastic coverings you get to the point of having to remove the speedometer meter pointer. There is no D shaped or otherwise locking connection point for this. It is strictly a friction fit piece of plastic pushed down over the pin that comes up from the stepper motor that drives it. At this point it is recommended that you take a piece of tape, I used electrical that didn't seem to damage the plastics or paint or printed parts underneath it but go easy on it, and make that line up with exactly where the pointer is at it's sopping point. You'll notice it is a little below zero but if you get this wrong when you put it back together you'll be driving at a speed other than what you think you are. "I took the dash apart Officer and evidently did not get the pointer back on right" is not going to get you out of a speeding ticket. Put some tape on the underside lined up with it's stop point so that you get it back together right.

I used a "spudger" and very gently pried it up on both sides. The plastic these parts are made of feels like the lowest quality styrofoam and I believe they would break if you so much as looked at them wrong. If you don't have a proper spudger put some cloth or something to protect the black plastic background as you pry upwards or you will damage it and have to look at the light soaking through your scratches forever.

The next thing you have to remove to get to the board are the connections to the 2 screens on either side. I didn't capture a picture of this but I HATE these kind of board connectors. I've ruined many similar ones on Raspberry Pi camera connectors or others. In this specific one the connectors had a black plastic bar across the ribbon connector that you VERY GENTLY pried upwards to release the ribbon cable and then could slide the ribbon cable out. For me they worked very well but if you have any qualms about this sort of thing don't do it. You must remove them to safely work on the board though because once you take off the front plastics nothing else is holding them in place and any force or movement will be transferred to the connector which will either rip the cables or tear the connectors right off the board. It does not take much force to do that at all so really be seriously careful at this point. I would also make sure you don't confuse the left and right screens. I couldn't see any difference in looking at them but it seemed like a good idea not to put it back together backwards. They would certainly fit just fine backwards but who knows if they have different firmware or something.

And finally you'll have the nice board you can have a good look at!



It is, of course, almost entirely surface mount and there just isn't much you can do about that unless you're much more of a professional soldering god than I am. I put it under the inspection microscope and can see a lot of connections that looked a bit iffy to me. The first thing I did was to put some flux over the through hole pins that go to the connector on the opposite side of the board. You can see them as two rows of parallel pins in the picture aboe right in the middle of the board towards the top. I then carefully touched each one up with some nice antique leaded solder making sure not to over do it. I then searched the board for other such connections and found lots that looked like they were not particularly well done. I also touched up the larger connections in the several different power regulators on both sides of the board though I don't know if that or just the connector itself was what finally brought it back to life.

Many of the CPU connections looked quite badly done to me as well but I did not try to reflow any of them in the initial attempt to get this working as I was almost certain that if I touched them I'd make things worse and not better.

I re-attached the screens and the plastic case parts necessary to hold them and provide for the cable attachment point to the car and took it back to the garage and low and behold it lit up!


Took it back upstairs and re-affixed the speedometer indicator and the rest of the plastics and it kept working! 

This is almost certainly a failure to make proper connections while using lead free solder. The connections seem to become brittle and just break. I have assembled only 1 device with lead free solder, a wonderful clock kit and every 2 years I have to take it apart and resolder one of the LED displays with good old fashioned lead free solder as the original connections fail one after another. 

It should be possible to do such things properly with lead free solder, but it is my opinion that it requires slightly different design and probably different or better flux and other such things. The solder joints themselves look so horrible with lead free solder that I think it would be impossible to validate them with visual inspection the way you can with leaded solder. A cold leaded solder joint is obvious. The ones that failed with lead free solder look identically awful to me to the ones that are still working. 

In any case, if you have the skills you should take things apart and look at them before you pay someone many thousands of dollars to replace it. We may be putting less lead into the land fills but we're putting a lot more entire assemblies into them because of it. It seems there should be a solution that properly recycles leaded boards while still letting you use what is so obviously a superior way of making things that should last for more than a few years.

I'm off to cancel the appointment at the Ford dealership for next week and to complain to someone who has no idea what the parts are made of and who won't know who to contact to complain at corporate that their instrument cluster boards are patently defective because they have not carried lead free solder construction techniques over into their new lead free board designs. I know it's pointless but I'm still going to complain to them...

.code { background:#f5f8fa; background-repeat:no-repeat; border: solid #5C7B90; border-width: 1px 1px 1px 20px; color: #000000; font: 13px 'Courier New', Courier, monospace; line-height: 16px; margin: 10px 0 10px 10px; max-height: 200px; min-height: 16px; overflow: auto; padding: 28px 10px 10px; width: 90%; } .code:hover { background-repeat:no-repeat; }