/XIAOMI_Robot

Python script to use a XIAOMI Vaccum cleaner robot via raspberry or out from FHEM

Primary LanguagePython

<title>

XIAOMI Vaccum cleaner robot

</title>

--------------------------------------------------------------------------

Update: xiaomi_robot.py works with TOKEN - no sniffing needed

--------------------------------------------------------------------------

Please refere to "Ermittlung_TOKEN_DE.pdf" to see, how you can check which token-id your robot use

Quick & dirty description:

  1. reset WLAN from you robot
  2. robot establish a new AdHoc network "rockrobo....."
  3. remove robot device in your App on your smartphone
  4. Alternative 1:
  5. install python script
  6. python xiaomi_robot.py -info
  7. robot answer with a status and the current token (16 Bytes)
  8. save YOUR token
  9. if this way didn't work for you go to alternative 2
  10. Alternative 2:
  11. open PacketSender
  12. insert in field Hex: 21 31 00 20 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
  13. insert a name
  14. save
  15. send
  16. Robot should answer immediately with a status and his token
  17. Robot answer with : 21 31 00 20 00 00 00 00 03 4C 94 1D 58 FE 4B F2 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
    but the FF FF... is exchanged with YOUR Token (16 Bytes)
  18. copy this 16 bytes and save them - you need it later
  19. using the python script
  20. Install python script (works only with Python 2.7)
  21. maybe you have to install python cryptography library with pip install cryptography
  22. check if pip install libs for python 2.7 and not for 3.5 (=> pip -V)
  23. test if script run without error messages. If you get error messages normally a lib is missing
  24. python xiaomi_robot.py -h
  25. you should see a help screen - if yes you won :-)
  26. Start: python xiaomi_robot.py -ip "ip from your robot" -cmd "start" -token "your token"
  27. Pause: python xiaomi_robot.py -ip "ip from your robot" -cmd "pause" -token "your token"
  28. Home: python xiaomi_robot.py -ip "ip from your robot" -cmd "home" -token "your token"
  29. Good luck and have fun

LunaX 25-MAR-17


Python script to use this robot


--------------------------------------------------------------------------

Important notes:

--------------------------------------------------------------------------

  1. all commands must be sniffed via Wireshark for you own environment
  2. if you work with wireshark use this filter to find you own commands
    • (data.len == 80 || data.len == 64 || data.len == 96  || data.len == 144) && (ip.proto == 17)



Using this tool:  


it is possible to send several commands in a sequence to the bot

examples:  

./xiaomi_vaccum_cleaner_script.py --cmd find start standard

First send FIND-command, than start robot cleaning and set hoover to standard


./xiaomi_vaccum_cleaner_script.py -vv --cmd find start standard

same as above but with verbose-verbose output


./xiaomi_vaccum_cleaner_script.py -vv -w 10 --cmd find start standard

same as above but wait 10secs between every command


./xiaomi_vaccum_cleaner_script.py -i 192.189.8.100 -vv --cmd find start standard

same as above but use new IP-Addrress as in script


-------------------------------------------------------------------------------


usage: xiaomi_vaccum_cleaner_script.py [-h] [-i] [-p] [-w WAIT] -c

                                       [{stop,start,home,silent,standard,power,find} [{stop,start,home,silent,standard,power,find} ...]]

                                       [-v]


XIAOMI vaccum cleaner


optional arguments:

  -h, --help            show this help message and exit

  -i, --ip              UDP destination ip

  -p, --port            UDP destination port

  -w WAIT, --wait WAIT  wait in seconds between two commands

  -c [{stop,start,home,silent,standard,power,find} [{stop,start,home,silent,standard,power,find} ...]], --cmd [{stop,start,home,silent,standard,power,find} [{stop,start,home,silent,standard,power,find} ...]]

  -v, --verbose         verbose output


  -------------------------------------------------------------------------------


############################################################################

HowTo sniff your XIAOMI robot

############################################################################

Preconditions:

  1. download and install "WireShark" on your pc
  2. download and install "PaketSender" on your pc
  3. install an ANDROID emulator on your pc (MAC OS => BlueStack)
    • install XIAOMI MI application
    • configure the application
    • test application if robot works - IMPORTANT !!!!!
  4. Start Wireshark
  5. setup network card to sniff (e.g. WiFI)
  6. insert into filter text field this filter criteria
    • (data.len == 80 || data.len == 64 || data.len == 96  || data.len == 144) && (ip.proto == 17)
  7. Start sniffing (icon upper left blue shark fin)
  8. go to android app and go to main screen (MAP is shown) - do nothing
  9. you should see packets in Wireshark
  10. click middle button (CLEAN) 1x time - wait until robot moves
  11. click middle button again (STOP) - robot should stop
  12. go to wireshark and stop recording (red square)
  13. now you should see all packetes from app to robot and answer from robot
    • Short introduction into UDP Packets

PING/CARD command:  Host send every second 80Bytes, Robot return 256 Bytes

(this packets can be ignored)


Normal commands:  host sends 80Bytes, robot answer: 64Bytes

(start,stop,find,home)


Power commands: Host: 96 Bytes, Robot: 64Bytes

(silent, standard, power)


Joystick commands: Host: 144 Bytes, Robot: 64Bytes

(not implemented yet)  

  1. to find YOUR START-Command, find a 80/64 Byte sequence.
    • Wireshark combine both (send & receive with a bracket (left side)).
  2. copy only DATA-Packet (80 Bytes)
    • these packets start every time with HEX: 213100xx
    • xx = Number of Bytes, for 80Bytes = 50, 96Bytes = 60, ...
  3. start PaketSender
  4. insert 80Byte packet in HEX-Field
  5. click SAVE-Button
  6. click SEND-Button
  7. IMPORTANT:
    • in below log table you must see
    • first:    your SEND udp package
    • second:   a 64 Byte response from both
    • If you do not see this response than the bot didn't recognize the command



Use RESET-Command - sometimes this avoid the "not responding"

21310020ffffffffffffffffffffffffffffffffffffffffffffffffffffffff


Good luck and enjoy your XIAOMI Robot

March 2017, LunaX