Repository navigation
Recover Hub 2 gateway key over LAN and during HA setup - #1781
Closed
oliver-mee wants to merge 6 commits into
Closed
oliver-mee wants to merge 6 commits into
oliver-mee wants to merge 6 commits into
Conversation
AlexxIT
added a commit
that referenced
this pull request
Oct 14, 2026
Owner
|
Thanks! Your PR is a really great job! But I rewrote it and fit it into a hundred lines - 5b667ba Now, Telnet on the second gateway will open during the standard procedure for retrieving gateway information. This occurs either simply when retrieving information as part of a cloud integration, or during the process of adding a gateway to the integration. The documentation still needs to be updated. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi! I found that the global/EU Xiaomi Smart Home Hub 2 (Multimode Gateway 2,
lumi.gateway.mgl001) on stock1.0.8_0013can return its gateway key over the local network using its existing Mi Home token. This gives that build an alternative to opening the hub for UART when the key is missing (#1166).The gateway key is a personalised 16-character value, separate from the 32-character token. Gateway3 uses it to authenticate
system_commandwhen enabling Telnet on newer Hub 2 firmware. It's stored in/data/miio/device.confon the hub.Recovery uses the token-authenticated
async_device_feedback_logdiagnostic request to upload that file to a temporary receiver. The request lists it in bothfileListandfilelistand supplies a fresh AES key and IV. The hub returns an encrypted tar archive; the receiver decrypts it in memory, checks the model and MAC against the hub, and reads the key. Upload size, source address and timeouts are checked. Gateway3's existing Telnet setup follows separately.On one physical hub with this build, the recovered key worked with normal Gateway3 setup, local device control and automatic reconnection after a hub reboot. The hub was connected to the router by Ethernet; the recovery computer used Wi-Fi on the same local network. Recovery is enabled only for this exact model/build. A limited emulation of the older
mgl03on1.5.7_0001returned fixed logs instead of the requested file.There are two ways to use it:
scripts/recover_gateway_key.pyasks for the IP and token, then prints the key to paste into Gateway3.Both use the same recovery code. The guide includes installation steps, troubleshooting and the protocol details. It also explains the firmware's conditional cleanup of its temporary diagnostic archive and the password/Telnet changes made by normal gateway setup.
129 tests pass on HA 2026.10.1 / Python 3.14, and 29 script/core tests pass on Python 3.10. These cover encrypted HTTP uploads, validation, cancellation, retries and HA progress with simulated gateway responses. The new HA screens and full physical setup through them still need testing. I'd welcome results from matching hubs and suggestions for other builds to investigate. Please include model, firmware and connection details, keeping tokens and recovered keys private. Feedback on the instructions and code placement is welcome too.
🤖 Generated with GPT-6.1 Sol
🧑💻 Ideated, directed and reviewed by a human, @oliver-mee