How to get Spotify working on your Xiaomi vacuum
a.k.a. how to root your vacuum, gain ssh access and install Spotify in it
Some years ago, I watched a really interesting talk in 34C3 titled “ Unleash your smart-home devices: Vacuum Cleaning Robot Hacking”, where the speakers explained how they reverse-engineered and gained root access to the Xiaomi vacuum, how it’s software work (it has an Ubuntu 14.04 inside), how to disconnect it from the Xiaomi network, and lots more.
So the last week I remembered that talk and decided to try it with my vacuum, experimenting and concluding in this tweet:
Some people asked me how I have done it, so here is the promised step by step guide.
Warning: It’s an easy process, but some fails (like installing a wrong firmware) can brick your vacuum. Go carefully, and in case of doubt stop, I will not be responsible for your broken vacuum cleaner.
Note: The guide is written assuming that you will use an Ubuntu-based distro. Also aiming the first generation vacuum (but the second one should work too changing the firmware).
In summary, there are only two steps: root you vacuum following the dustcloud instructions and install the spotifyd UNIX daemon.
Important: Spotify premium is needed in to use spotifyd.
Rooting your vacuum cleaner
All the root process is based on the dustcloud documentation, so I will not rewrite it. I will point you to the doc page and help you with some notes.
The first step is factory reset your vacuum because probably you have a recent firmware that it’s not rootable. So follow these instructions.
Once your vacuum is factory reset, follow the steps in the dustcloud rooting instructions. Some notes:
- In step 3 the
wget https://github.com/dgiese/dustcloud/releases/download/0.1/firmwarebuilder_0.1.zip
will not work because the 0.1 version is not more on github. Usewget https://github.com/dgiese/dustcloud/releases/download/0.3/firmwarebuilder_0.3.zip
or go to the releases page to see what’s the last version. - In step 4, the firmware that worked for me (1st generation) is the v11_003132. And I didn’t try it, but I will go for the v11_001810.fullos for the second generation.
- Once you finish the root process and the vacuum cleaner is restarted, you have to connect it again to your wifi. In order to do this, you can use the Xiaomi Home app as always.
- In order to access it with ssh, you will need the vacuum IP. If you’re in the same network (can be the vacuum temporal network that you used to root it), you can run
mirobo discover --handshake true
and you will see the IP and the token of the robot. Then, usessh root@<IP>
. - If you want the token and in the discover you only see something like ffffff…, access by ssh and execute
cat /mnt/data/miio/device.token
. - Extra: with mirobo and the token, you can install custom sounds using
mirobo --ip <IP> --token <token> install-sound sound.pkg
. Some example sounds: english, catalan or spanish. - If with the new firmware you have some problems with the Xiaomi Home app, you can switch to FloleVac.
Installing spotifyd
You will need to install nano, wget and unzip on the Vacuum:
apt-get update && apt-get install nano wget unzip && apt-get autoclean && apt-get clean
Why nano and not vim? Why the clean stuff? The Xiaomi Vacuum has a minimal root partition space, so I am trying to don’t overuse it.
Then, we will download the last ARM spotifyd version and save it in /opt/spotifyd
. As before, you can go to the spotifyd releases page to see if there is a newer version.
cd /opt && wget https://github.com/Spotifyd/spotifyd/releases/download/0.2.11/spotifyd-2019-06-19-armv6.zip && unzip spotifyd-2019-06-19-armv6.zip && rm spotifyd-2019-06-19-armv6.zip
Then, we will create a folder to save the spotifyd cache in a mounted partition that has more space than the root partition:
mkdir /mnt/data/spotifyd_cache
Now, we prepare the spotifyd configuration. Just nano /etc/spotifyd.conf
and write the configuration:
[global]
username = <spotify_user>
password = <spotify_password>
backend = alsa # run `spotifyd --backends` for possible values
device = hw # run `aplay -L` for possible values
# control = alsa_audio_device # device for the mixer
mixer = "Lineout volume control"
volume-control = alsa # or alsa_linear, or softvol
device_name = Vacuum # must not contain spaces
bitrate = 160 # or 96, or 320
cache_path = /mnt/data/spotifyd_cache
volume-normalisation = true
normalisation-pregain = -10
And now, let’s configure upstart (yup, upstart) to run spotifyd on the vacuum boot. Execute nano /etc/init/spotifyd.conf
and write:
description "spotifyd service"
author "Angel Fernandez"start on (local-filesystems and net-device-up IFACE!=lo)
stop on runlevel [06]respawnscript
exec /opt/spotifyd --no-daemon >> /mnt/data/spotifyd.log 2>&1
end script
Note: Probably it’s not the best upstart script in the world, because it was totally unknown for me until some days ago.
And for start spotifyd now, just execute: start spotifyd
.
And now, with some Spotify client connected into the same network as the vacuum cleaner, you will be able to select it as a Spotify device.
So that’s all, if you have any doubt ask in the comments or on Twitter.
And once we have root access to our devices, and these devices have Linux inside, the possibilities are almost infinite.
So if you have other crazy ideas like this, go ahead, try it, play and experiment! And then, share it 😊