Cracking a Toy Robot's Bluetooth Protocol, Then Teaching It to Chase the Cat
We have a 小帮 R1 at home, a little robot car that comes with an online course from Zuoyebang’s 小鹿素养 app. Two wheels, an LED matrix screen, a voice, and a button that starts an AI chat. Normally it only takes orders from web courseware running inside the app. I wanted it to take orders from me: commands from a Mac, a dance, calling the cat by name, and then chasing the cat.
All I had was the app’s Android package. This post covers how I dug the protocol out of it, which paths worked, and which were dead ends.
Finding the code that talks to the robot
The APK is 150 MB with twelve dex files. The first step wasn’t decompiling, it was searching strings:
strings -a classes*.dex | grep -i xbr1
xbr1 is the R1’s code name. The search turned up xbr1_speak, xbr1_writeMotor, xbr1_screenText and friends, the action names the web courseware calls through a JavaScript bridge. Following those names led to three places:
ble_conn.d: the R1 manager class, which receives actions from the web page;com.blufi.esp32.a.b.b: where actions get encoded into bytes;libblepulse_android.so: a newer Rust implementation of the same commands, switched on by a server flag.
I meant to use jadx, but the jadx archive I had was corrupted. Luckily the Android SDK ships dexdump, which disassembles dex into smali-style text. It’s harder to read than Java, but the encoder functions are short, and that was enough.
Transport: BluFi, unencrypted
The package name com.blufi.esp32 gives half the story away: there’s an ESP32 inside, speaking Espressif’s BluFi protocol. BluFi exists to set up Wi-Fi on a device, but it has a “custom data” frame type, and the vendor pushed every control command through that opening.
| UUID | |
|---|---|
| Service | 0000ffff-… |
| Write (phone → robot) | 0000ff01-… |
| Notify (robot → phone) | 0000ff02-… |
The frames are standard BluFi:
[type 0x4D] [frame control] [sequence] [length] [data…]
The app never runs BluFi’s security negotiation, so frames are neither encrypted nor checksummed. The sequence number counts up by one per frame from the moment the connection opens. All of this reads straight out of the encoder; no guessing needed.
The command table
Every method in the encoder class looks alike: build a byte array whose first byte is the command number, then hand it to the sender. Reading them one by one gives the table:
| Command | Does | Parameters |
|---|---|---|
0x40 |
reset | — |
0x41 |
motors | left wheel, right wheel, one byte each |
0x42 |
open AI chat | role number |
0x43 |
speak (TTS) | voice-name length + voice name + text |
0x44 |
clear screen | — |
0x45 |
light one dot | x, y, state |
0x46 |
scroll text | brightness + text |
0x47 |
custom image | brightness + bitmap |
0x48 |
unlock AI mode | — |
To show “Hi” on the screen, write 4D 00 00 04 46 03 48 69 to FF01.
I wrote a small Python script, r1.py, using the bleak library, and connected straight from the Mac. The first text I sent scrolled across the LED matrix.
Speech: a missing voice name
Screen and motors worked. Speech didn’t. Send 0x43 and the robot replies “success” twice, then says nothing.
The encoder is clear about the format: voice name first, text after. The question was where a voice name comes from. I tried a pile of guesses: an empty string, default, female, xiaoyan, Volcano Engine’s BV001_streaming, Microsoft’s zh-CN-XiaoxiaoNeural. Every one got “success” and silence.
The lesson: the robot’s “success” only means it received the command, not that it spoke. It hands the text and voice name to a cloud service and doesn’t care whether the cloud recognizes the voice.
Then, in the disassembly, I found a hidden test screen, GyroActivity2. It’s a developer tool: one button per command, every parameter hard-coded. The speech buttons use two voice names: voice and longqiang_v2.
longqiang_v2 worked on the first try: “欢迎使用小帮R1设备” (“welcome to the 小帮 R1”). voice stayed silent; it’s probably a placeholder.
longqiang_v2 looks like a voice from Alibaba Cloud’s CosyVoice lineup. Following that hunch, I tried eight more names in the same family, each one announcing its own number. Seven spoke:
longqiang_v2 longxiaochun_v2 longxiaoxia_v2 longwan_v2
longcheng_v2 longhua_v2 longjielidou_v2 longshu_v2
Only longtong_v2 was silent. The robot now has eight voices to choose from.
Cut off mid-sentence
One more snag: “开心哪里跑” came out as just “开心哪里”, missing the last syllable.
My first suspect was the end of the sentence, so I sent it five ways: plain twice, with a full stop, with an ellipsis, and with an extra “啊” on the end. All five played in full.
The difference was timing. In that test I waited 7 seconds between sentences, while the script disconnected Bluetooth 1.5 seconds after sending. Dropping the connection seems to cut off whatever is still playing. Waiting longer, scaled to the length of the text, fixed it.
More treasure on the test screen
The same test screen settled a few open questions:
- The motor test value is
a=-50, b=50, so the values are signed: negative is reverse, and one positive plus one negative spins in place; - The custom-image sample is 15 bytes, which looks like a screen 15 columns wide and 8 dots tall;
- The text samples use brightness 3 and 5.
A dance, then a cat chase
With signed motors, a dance is easy to put together:
- Wiggle: drive one wheel at a time so the body swings left and right;
- Shuffle: both wheels forward, then back;
- Spin: one wheel forward, one backward.
Add “DANCE”, “<3” and “YEAH” on the screen, and you have an eight-second dance.
The cat chase adds a voice on top:
- “开心” (happy) lights up on the screen, and the robot says it out loud;
- The screen switches to the cat’s name, and it calls: “咪咪,咪咪,快过来呀!” (Mimi, Mimi, come here!);
- The face turns into
>w<. An excited wiggle, a dash forward, veer right, veer left, another dash, a pounce with a little recoil, and a victory spin; - A
^_^on the screen, and “抓到你啦!” (got you!).
python r1.py chase 咪咪
To be clear, it isn’t chasing the actual cat. The R1 has no camera and sends no sensor data back; it just runs a lively fixed route. The cat doesn’t know that, though. All the cat sees is a little car shouting its name and charging at it, which works well enough.
Dead ends
Two things I wanted and couldn’t have, written down so nobody else has to try.
Playing a local MP3. If it can play Alibaba Cloud’s voices, why not my own audio? The Rust implementation settles it: the speak command validates exactly two things, the text and the voice name, capped at 255 characters. No command in the whole Bluetooth protocol carries audio, a file or a link. The robot fetches the sound from the cloud over its own Wi-Fi; the Bluetooth side only ever carries text.
The mysterious FF05. After connecting, the service turned out to have a characteristic my notes didn’t mention: ff05, writable and notifiable. I wrote a sweep of bytes to it, and every write produced the same BluFi status reply on FF02. It’s just another entrance to the same command parser, not a secret audio channel.
Button and motion events. I listened on Bluetooth for 30 seconds while pressing the buttons and picking the robot up and shaking it. Not one notification arrived. The R1 handles its buttons entirely on its own and never tells the phone.
The R2 hiding in the Rust library
There was one more surprise in libblepulse_android.so. Besides the R1, the library implements a second device, xbr2, with far more abilities:
- vibration (strength and duration);
- showing stored images by ID;
- battery level, version and MAC address queries;
- role configuration and unlocking;
- pushed events: posture (looks like gyroscope data), screen events, volume changes, and speech recognition results.
These exist only in the Rust library; the Java side barely exposes them. None of it helps the R1, but it hints at the next product: a little companion that knows how it’s being held and understands what you say.
Takeaways
- When reverse-engineering an app, start by searching strings; a code name (
xbr1here) is the best thread to pull; - Without jadx, the Android SDK’s own
dexdumpis enough to read the encoder functions; - A device’s “success” only means it received the command, not that it did the thing, especially for anything that goes through the cloud;
- A developer’s test screen is a gold mine; the hard-coded parameters are ready-made answers;
- One working voice name gave away the provider behind it, and the naming pattern led to more;
- Don’t disconnect right after sending; some actions need time to finish;
- Disassembly tells you what a device can do, and also what it can’t, which saves just as much time.
Comments