Cloud-free Rockrobo firmware image with Valetudo ================================================ ## This howto has been moved to https://github.com/dgiese/dustcloud/wiki/Cloud-Free-Firmware-Image-With-Valetudo -------------------------------------------- ## Suggested firmware versions * **Gen1:** v11_003514 or newer * **Gen2:** v11_001702 or newer (latest tested: v11_001712) ## Bulding the firmware ### Install required dependencides You should make sure that the following packages are installed in your system: * bash * openssh (for ssh-keygen) * ccrypt * sed * dos2unix ### Prerequisites You need to have a public / private ssh-key pair to connect to the robot. If you do not have a keypair yet, you can generate one with the following command ``` ssh-keygen -t ed25519 -C "your_email@example.com" ``` Per default, the generated keys will be created under `~/.ssh`. If you choose to create the keys in another location, remember your chosen location for later. ### Preparations for building the image 1. Create a new directory for your work mkdir rockrobo cd rockrobo 2. Clone the dustcloud repository (until imagebuilder > 0.1 is available) git clone https://github.com/dgiese/dustcloud.git 4. Create a directory for dummycloud mkdir dummycloud pushd dummycloud 5. Download dummycloud from https://github.com/dgiese/dustcloud/releases wget https://github ... unzip -a dummycloud*.zip popd 6. Create a valetudo directory mkdir valetudo pushd valetudo 7. Download the latest valetudo binary from https://github.com/Hypfer/Valetudo/releases wget https://github ... mkdir deployment pushd deployment wget https://github.com/Hypfer/Valetudo/raw/master/deployment/valetudo.conf popd popd 8. Create rrlogd-patcher directory mkdir rrlogd-patcher pushd rrlogd-patcher 9. Download the latest `patcher.py` wget https://raw.githubusercontent.com/JohnRev/rrlogd-patcher/master/patcher.py popd 8. Create firmware directory mkdir firmware pushd firmware 9. Download the latest firmware (e.g. v001792) wget https://dustcloud.seemoo.de/public/temp/v11_001792.pkg 10. Download sound package wget https://github.com/dgiese/dustcloud/raw/master/devices/xiaomi.vacuum/original-soundpackages/encrypted/english.pkg popd If you followed the above commands, your`rockrobo` directory structure should now look like this: ``` tree -L 2 rockrobo/ rockrobo/ ├── dummycloud │   ├── doc │   ├── dummycloud │   ├── dummycloud_0.1.zip │   └── README.md ├── dustcloud │   ├── cloudprotocol.pdf │   ├── devices │   ├── docker │   ├── dummycloud │   ├── dustcloud │   ├── LICENSE │   ├── Pipfile │   ├── Pipfile.lock │   ├── presentations │   └── README.md ├── firmware │   ├── english.pkg │   └── v11_001792.pkg ├── rrlogd-patcher │   └── patcher.py └── valetudo ├── deployment └── valetudo ``` Next, we can create the firmware image. ### Creating the firmware image To create the firmware image you should run the following commands: ``` mkdir image cd image sudo ../dustcloud/devices/xiaomi.vacuum/firmwarebuilder/imagebuilder.sh \ --firmware=../firmware/v11_001792.pkg \ --soundfile=../firmware/english.pkg \ --public-key=$HOME/.ssh/id_ed25519.pub \ --dummycloud-path=../dummycloud \ --valetudo-path=../valetudo \ --disable-firmware-updates \ --ntpserver=fritz.box \ --rrlogd-patcher=../rrlogd-patcher/patcher.py \ --replace-adbd ``` Here you need now to remember the location of your generated public ssh-key, `id_ed25519.pub`. If you don't have a public key yet, take a look at the Prerequisites section. Note that not all options are required. However if you're router runs a ntp server you should use it. Also I would recommend to replace adbd so in case something goes really wrong you can still access it via USB. Make sure that rrlogd gets patched, (see Appendix for supported versions). You should see something like: Creating backup of rrlogd Trying to patch rrlogd Successfully patched rrlogd **WARNING**: If you patch rrlogd you should use dummycloud or your data will be sent unencrypted to Xiaomi servers! ## Flashing the firmware image After the successful build of the firmware image, we can tell the robot to download and flash it. First, we need to create a virtual environment for it in python. For this the following packages need to be installed: * python3 * python3-pip * python3-venv ``` cd .. mkdir flasher cd flasher python3 -m venv venv ``` and install the required miio python packages: ``` source venv/bin/activate pip3 install wheel pip3 install python-miio cd .. ``` Next, turn your vacuum on and place it in the charger docking station. Connect yourself via WLAN to your robot, the SSID should be sth. like `roborock-vacuum-s5_miap_****` Now we are finally ready to flash the firmware. **IMPORTANT:** The flasher scripts will create a web server where the robot will download the firmware image. This means it needs to be able to connect to port 80 on this box. Make sure that the firewall will not block the network access. Flash the firmware using: ``` python3 dustcloud/devices/xiaomi.vacuum/firmwarebuilder/flasher.py -f image/output/v11_001792.pkg ``` After the successful transfer of the image to the robot, the robot will start flashing the image. This will take about 5~10 minutes. After the process is done, the robot will state that the update was successful. Eventually, we can log in to our robot via ssh: ``` ssh root@192.168.8.1 ``` If everything works out, you can now log in to your robot - enjoy. ## Check if dummycloud is correctly set up Assuming you are logged into your robot, we can check if the dummycloud is correctly set up. First, we need to examine if the dummycloud executable is running via ``` pgrep dummycloud ``` The result should be a process id number, e.g. `397`. Next, we have to check the firewall rules, the port `8053` needs to be redirected to`127.0.0.1`, so that the robot is communicating with the dummycloud. Execute ``` iptables -t nat -L ``` The result should contain the following: ``` Chain OUTPUT (policy ACCEPT) target prot opt source destination DNAT udp -- anywhere ot.io.mi.com udp dpt:8053 to:127.0.0.1:8053 ``` Furthermore, one can verify if the dummycloud is working directly on the robot. If the WiFi LED is constantly on (~30 s after startup), everything is working as expected. ## Appendix ### Flashing doesn't work Make sure your firewall is turned off that the robot can connect to your machine for downloading the firmware. ### Connect robot to your WiFi To integrate the unprovisionised robot to your local WiFi, you need to execute the following on your host PC (**not** on the robot) to obtain the robot's token: ``` cd rockrobo source flasher/venv/bin/activate mirobo --debug discover --handshake true ``` The token will be sth. like `456b567549786e6e73754374323*****`. With this token we can set up the WiFi to which the robot will connect. ``` mirobo --ip=192.168.8.1 --token=456b567549786e6e73754374323***** configure-wifi YOUR_SSID YOUR_WIFI_PASSWORD ``` Now the robot will be in your local WiFi and you can give it for example a static ip via your router. ### Blocking traffic to the outside of your WiFi To make sure that no traffic from the robot can escape your local WiFi, you can add the following rules to the firewall of your robot (to make it permanent put in in /etc/rc.local before `exit0`): ``` iptables -A OUTPUT -d 192.168.0.0/16 -j ACCEPT iptables -A OUTPUT -d 127.0.0.0/8 -j ACCEPT iptables -A OUTPUT -j DROP ``` Have fun!