Reverse-Engineering a $4 Smart Bulb for Local Control
For a while now I have been building a little family dashboard that runs on a cheap Android photo frame I rooted and took over. It shows the clock, the calendar, whose turn it is to do the chores, the weather, the shopping list, and a slideshow of our photos. It syncs with a tiny Cloudflare Worker so our phones can see the same thing. It is one of those projects that is never really “done”, and every weekend my wife hands me one more idea.
The latest one was simple on the surface: “can it control the bedroom lamp too?”
The lamp is a cheap Globe Electric Wi-Fi bulb, controlled by an app called Globe Suite. I figured this would be an hour of work. It turned into an evening, a rooted emulator, and a 512 MB memory dump.
A little background on how these bulbs work
Almost every no-name smart bulb you can buy is secretly a Tuya device. Tuya is the company behind the chips and the cloud; the brand on the box (Globe, and a hundred others) just ships a rebranded copy of Tuya’s app. Globe Suite is one of those rebrands.
Normally the app talks to the bulb through Tuya’s cloud. But Tuya devices also speak a local protocol on your own Wi-Fi, which is what I wanted — no cloud, no latency, works even if the internet is down. To talk to a bulb locally you need three things:
- Its device id — easy, the bulb literally broadcasts it on the network every few seconds.
- Its IP address — also in that broadcast.
- Its local key — a 16 character secret, set when the bulb was paired, that encrypts the local connection.
The id and IP are free. The whole game is getting that local key, and Tuya very deliberately does not show it to you in the app.
The “normal” way, which did not work
The documented way to get a local key is through a free Tuya IoT developer account. You create a “cloud project”, then from inside the app you scan a QR code to link your account to that project, and then the developer API will happily hand you the local keys for all your devices. Tools like tinytuya automate the read once the account is linked.
So I did all of that. Made the account, made the project, picked the right data center, generated the QR code. In Globe Suite I went to the profile tab, found the scan icon, scanned it, and got a nice “Confirm login” screen. I tapped it. And… nothing. Zero devices linked to my project. I tried again, faster, in case the QR had expired. Still nothing.
It took me a while and a very helpful Home Assistant forum thread to understand why. That QR flow is built for Tuya’s own Smart Life and Tuya Smart apps. When a rebranded app like Globe Suite scans it, the scanner is wired to a generic “log in to the platform” action, not the “authorize this cloud project to see my devices” action. So you authorize… a login, which does nothing useful, and your bulb never shows up. The people on that thread who succeeded had all re-paired their bulbs in the official Smart Life app first.
I did briefly consider that. Reset the bulb, add it fresh in Smart Life, scan from there. But Globe accounts and Smart Life accounts are separate, so it meant un-pairing the bulb and moving it to a different app, and I was now annoyed enough to want the key without giving up.
The second dead end
The other classic trick is that old versions of these apps used to store the local key in a plain text preferences file. Grab an old APK, read the file, done.
Except the current Globe app sets allowBackup=false, so I can’t pull its data without root. And the old APK? APKMirror doesn’t host Globe Suite at all, and APKPure re-signs every APK it serves with a generic key. When I checked the signature of the APKPure copy, it was signed by CN=Android, O=Google Inc. instead of Tuya’s real signing certificate. That means it is not the genuine app — somebody repackaged it — and I was not about to type my real account password into a repackaged app. Dead end.
At this point the cheap and documented routes were both gone. What was left was the thing I had been avoiding: the app has the key sitting decrypted in memory the whole time it is logged in. I just had to go get it.
Going in through memory
I did not want to touch my actual phone for this, so I used a throwaway rooted Android emulator. A couple of important details:
- You need a
google_apissystem image, not thegoogle_apis_playstoreone. The Play Store images blockadb root; the plain Google APIs images allow it. - I installed the genuine Globe app, not the repackaged one. I pulled the real APK (two split files) straight off my phone and checked that it was signed by Tuya’s real certificate before installing it in the emulator. Then I logged in with my own credentials, into the real app, on a machine I controlled.
adb -s emulator-5554 root
adb -s emulator-5554 install-multiple base.apk split_config.arm64_v8a.apk
Once the bulb showed up in the emulator, I knew the key had to be in the app’s process memory. With root you can read /proc/<pid>/mem. I dumped the regions and searched for the device id, which I already knew from the network broadcast. It lived in exactly one place: a single huge rw-p region at address 0x14000000 — the ART managed heap, about half a gigabyte of it.
My first instinct was to grep that dump for "localKey":"...". No luck. The only hit was the literal string "localKey":"localKey", which is just a schema template. The actual key is not stored as a JSON blob — it is a managed Java String object, and the device bean (a class with the lovely name com.thingclips.smart.interior.device.bean.DeviceRespBean) just holds a reference to it somewhere else on the heap.
So I had to parse the heap a little. An ART String object has a small header — a few fields, then the character count at offset 8, then the raw characters at offset 16. From there the approach was:
- Find every place the device id string’s object lives.
- Find every object that holds a reference (a pointer) to that string — those are the device beans and related objects.
- For each of those objects, read the other
Stringreferences packed next to the device id, and print the short ones.
That spat out a handful of 16 character strings. And here is the twist that cost me two wrong guesses: a couple of them looked exactly like a key — clean 16 character hex, something like a1b2c3d4e5f60718. I tried them against the bulb. They failed with Check device key or version.
The real key was the one that did not look like a key at all — sixteen characters, but full of punctuation, more like )q7!Vx~3mZ:Ld#f} (not my actual key, obviously). Tuya local keys are just 16 random bytes; the tidy hex strings sitting next to it were the device’s secKey and a UUID — decoys. The moment I fed the ugly one to tinytuya, the bulb answered with its full state:
{"dps":{"20":true,"21":"white","22":1000,"23":1000, ...}}
That is the whole device in one line: 20 is on/off, 22 is brightness, 23 is colour temperature, 24 is the colour, and so on. I had the key. I wrote it to a gitignored file, and tore the entire emulator back down — the AVD, the system image, the heap dump. It had my login session and device data in it and had served its purpose.
Teaching the frame to speak Tuya
Having the key is only half of it. The dashboard is a web page running in the frame’s WebView, and a browser cannot open the kind of raw encrypted socket the bulb needs. So the actual talking has to happen in the native Android app, and the web page asks it to.
I ended up writing a small Tuya 3.4 client in Java, from scratch, no library. The 3.4 protocol is a bit more involved than the older ones: you do a little session handshake first, trading random nonces and HMACs, and the session key you end up using is:
sessionKey = AES-ECB-encrypt(localNonce XOR remoteNonce, key = localKey)
After that, every message is AES encrypted with the session key and wrapped in a frame with an HMAC-SHA256. Asking for status is one command with an empty {} body; setting the light is another command carrying {"dps":{"20":true,"22":600}} and friends. I also had it listen for the bulb’s UDP broadcast so that if the router hands the bulb a new IP, the frame just finds it again by id instead of breaking.
The native app exposes two methods to the web page — get() and set() — and because a round trip on the LAN takes a beat, I made them asynchronous so the dashboard never freezes waiting on a light bulb. The web side is just a tile on the home screen and a little control panel: on/off, a brightness bar you drag, warm-to-cool, a row of colours, and a few presets.
There was one last gremlin. My control panel used a data-mode attribute on the White/Colour toggle. It turns out the dashboard’s root element also has a data-mode attribute — it is how the whole frame switches between day and night. So every tap in the panel was quietly bubbling up and setting the bulb’s mode to "day" instead of applying my colour. Renaming one attribute fixed it.
Was it worth it
For controlling one lamp, no. The sensible move was to re-pair the bulb in Smart Life and read the key the boring way in ten minutes.
What I got out of it: I now understand how these bulbs actually work, I have a tiny dependency-free Tuya client I fully control, and the key never leaves my house.