Monday, January 18, 2016

Raspberry PI (B+) as Spotify Connect device (Work in progress)


Well I've been buying these little Rapsberry Pis since they started so I keep some of them around and to be honest I end up changing them for something else, as my primary interest is music (then video) and for there is always something that's more powerful (Intel NUC) or smaller, or easier to handle (Windows, doh).

In the end as application I use my dear Kodi, whenever possible with a bootable Openelec image (both great pieces of software).

With the Rpi2 (1GB RAM!) I found that Openelec runs so much better and there is little excuse not to use as a Kodi player.  But given I've had the other boxes around I went for something that's quite interesting: a music headless server that can manage Spotify Connect and maybe Airplay (but anyway that's something available on Kodi). For that I will use the next best thing to the Rpi2, the Raspberry Pi B+.

As of today, Spotify ain't granting rights to everyone out there to write apps to get Spotify Connect built into devices (Chromecast does now; Gramophon too).

So what can we do? There's a little development ("Spotify Connect Web") to allow the rPi to act as a Spotify Connect target and that will be the start of the project.

So what am I using?

REQUIREMENTS
- Rapsberry PI B+: Accesories/peripherals
    * Wireless K400R Logitech Keyboard/Mouse
    * Connected via Ethernet, HDMI monitor (then SSH)
    * External usb power source.
    * Kingston Micro SD Card 8GB Class 10.

- An external amplifier/(amplified) speakers: as I plan to use it hooked to my stereo amp, there you go, stereo amp + speakers (or active/amplified speakers, I used that for the test)

- Raspbian Jessie LITE, latest from the site. As I won't need a GUI I figured the Lite version will do fine (and my internet speed sucks, a smaller size is better!)

- Spotify Connect Web:  Available at https://github.com/Fornoth/spotify-connect-web
  There are quite a numerous forks out there.. For now I'll stick to this one, the original.

- A Spotify Premium Account

PREPARING THE RPI:
- SD Formatter 4 on the card, with size adjustment
- WIN32DiskImager; pick the .img from Jessie and burn it to the SD Card.
- Start the Rpi with the card and the peripherals.

CONFIGURING THE RPI:
- Login as pi/raspberry
- First thing, run sudo raspi-config and expand the filesystem to use the 8gb, you're gonna need them.
- Reboot to apply the change

CONFIGURING SOUND & SPOTIFY CONNECT:

- These are mostly the instructions found in the github site aforementioned.
- First, follow the instructions in the github site to get the developer key from Spotify. YOU'LL NEED A PREMIUM ACCOUNT.
- I added the "-- name" option to have your output named as you like. I used "rpiConnect1". That name will appear in the devices list in Spotify.
curl -O http://spotify-connect-web.s3-website.eu-central-1.amazonaws.com/spotify-connect-web.sh
chmod u+x spotify-connect-web.sh
# Download the current chroot (~ 180 MB)
./spotify-connect-web.sh install
# Copy your `spotify_appkey.key` into the app directory. (See below for information on how to get that file.)
sudo cp spotify_appkey.key spotify-connect-web-chroot/usr/src/app/
# Run using normal cmdline options
./spotify-connect-web.sh --username 12345678 --password xyz123 --bitrate 320 --name Devicename

- That should work if you test the output to this device.


FURTHER CONFIGURATION, AUTOSTART & TROUBLESHOOTING

AUTOSTART:
To have the service start with our rpi, what I did (after extensive googling of course) is:
- Create a script in your pi home directory, called spserver.sh. Contents should be:

# set sound output to analog:
sudo amixer -c 0 cset numid=3 1

# run the spotify connect server in the background
/home/pi/spotify-connect-web.sh --name rpiConnect1 --username my_spotify_user --password my_spotify_pwd --bitrate 320


- Add in etc/rc.local, the lines below. Put them above the exit 0 command (leave it there). The ampersand (&) will get the process running in the background.

#start spotify connect
su pi -c /home/pi/spserver.sh &

FURTHER CONFIGURATION

In the link below I got some nice information on how to change a line to provide a default volume of 1. For that change line 74 in the file below (commenting out the math, and fixing "1" as volume)
/spotify-connect-web-chroot/usr/src/app/connect.py


ref. link:
http://support.hifiberry.com/hc/en-us/community/posts/201863051-hifiberry-digi-spotify-connect#community_comment_206970525
mixer_volume = 1 #int(mixer.getvolume()[0] * 655.35)

That together with the amixer setting solved the "no volume" situation I had at first.

TROUBLESHOOTING/NOTES
-  The analog output setting was necessary in my case as I (believe) I couldn't hear anything because I had an HDMI monitor connected (and so there goes my sound). The amixer setting (sudo amixer -c 0 cset numid=3 n) is selecting analog (where n is 0=auto, 1=headphones/analog, 2=hdmi). Probably it's a one time setting, but I couldn't check that yet.

ref. links:     
http://raspberrypi.stackexchange.com/questions/44/why-is-my-audio-sound-# output-not-working
http://elinux.org/R-Pi_Troubleshooting#Sound_does_not_work_at_all.2C_or_in_some_applications

- There can be static on the Rpi analog output; that's something to consider, there may be some solutions out there, the best is to change over to a better sound device for the rPi.

TODO:
- A wifi dongle (I have a TPLink device but it's attached for now to the Openelec rPI, also it's not anything with fancy speed)
- A better sound device for the Rpi:  either a HifiBerry DACor similar, or a USB inexpensive sound dongle. That will require more investigation for sure.
- Installing an Airplay solution too; how would it work together with spotify connect web? Trying now:
http://raspberrypihq.com/how-to-turn-your-raspberry-pi-into-a-airplay-receiver-to-stream-music-from-your-iphone/
- hardware volume handling: see at
https://github.com/Fornoth/spotify-connect-web/issues/11




Tuesday, January 05, 2016

Intel Compute Stick / Windows 10 issues and troubleshooting


This is a draft entry to record my issues with the Intel Compute Stick.

I started on Win 8.1 with Bing as it was provided, but managed to upgrade to Windows 10 (Only 32bit, Home is allowed by license) without major issues.

I used the stick primarily as an HTPC device; installed Kodi on it, and little more. Kinda slow, but did work, as Kodi is cool enough to manage a good performance on any platform.

One day, suddenly, Win10 presented an error - honestly I am not sure which error it was, but after reading some forums about this problem, I guess it was a Windows 10 Update Pack (November update? 10586 version?) that couldn't finish and left the machine in a "limbo" state.

Thing is, after that, I couldn't even reset the PC to a bare Windows 10 install (it stuck on some percentage after a long time working) even when choosing to lose all my stuff.

What seems to be working now is the following:

- Created (with the help of Rufus: select MBR Partition with UEFI!) a bootable USB thumb drive in other Windows machine, with the latest Windows 10 Home 32bit ISO from Microsoft. Note that the Sandisk Extreme thumb drive seems to work, while a Kingston G4 seems to have failed.

- I was using a crappy USB Hub 2.0 to connect wireless keyboard and the thumb drive.... It was obviously giving me a headache. I moved over to a wired USB keyboard (as per other users' recommendations) and a wired USB mouse, changed the USB Hub to one with external power supply.

- Also, I was able to do go for the 3 second power button menu (apparently the wireless keyboard was preventing me from getting there) and updated the BIOS version from 18 to 31 (lots of versions in between!)

- Then I was able to select F10 boot menu, chose the Sandisk thumb with bootable Win10 iso and then started the installation.

- On the license key prompt I selected "Skip" (with the other hub/keyboard I got an error that there was no storage available or something, asking me to enter a driver for that; it might have been the issue with the wireless combo USB dongle?)

- I chose to delete the Windows partition and installed over there (about 21gb can't recall exactly). I didn't touch the "images" and other partitions. Not sure what I'll do about that in the future. Don't think they're any worth.

- Bummer! I chose the wrong ISO (not the first time I do that), and I ended up with Windows 10 Pro installed on the Stick - well, we know it works BUT.. Thing is that Windows appeared as "not activated" and with an error that surely would prevent to activate it even on the phone:

- After all, that was not the license I was entitled to; Windows 8.1 Bing is freely updated to Windows 10 Home 32BIT ONLY. So, patience, and did it all over again, this time with a thumb drive with the correct Windows 10 Home ISO on it. I did run the setup from inside Windows 10 Pro this time, then deleted the main partition again... And did the whole process...

- And when finally I reached the desktop and checked on This PC's properties... SUCCESS!! Windows 10 Home, (self) activated!!

SO - It seems to be working fine! Tomorrow I'll check if it does power up ok, will try to tidy up things a little ( more free space, improve performance etc) *and* try to get an image of this thing in case of more trouble.

DAY 2
- The machine booted up without issues; did some performance tweaking, uninstalled some apps and I'm trying to download kodi for Windows.

- I also followed the instructions in this link to set Wifi as a "metered" connection to avoid the automatic download of updates.. Version 10586 seems to cause trouble. Now I'm on 10240.

- Pending is to use File History or anything else to create an image of the system in case of trouble. Which seems to be something very likely to happen again.

- Next thing is to install the Stick drivers from Intel!