Skip to content

Learn unknown device MQTT credentials on first connect#22

Closed
piotrkochan wants to merge 1 commit intoPython-roborock:mainfrom
piotrkochan:fix/learn-device-mqtt-credentials
Closed

Learn unknown device MQTT credentials on first connect#22
piotrkochan wants to merge 1 commit intoPython-roborock:mainfrom
piotrkochan:fix/learn-device-mqtt-credentials

Conversation

@piotrkochan
Copy link
Copy Markdown

My Saros 10R ignores bootstrap credentials from nc_prepare (don't know why...) and connects to MQTT using its own device credentials. The server rejects the connection because device_mqtt_usr is empty, and there's no way to identify it- record_mqtt_topic only runs after authentication succeeds.

This PR adds a fallback. When authentication returns unknown_device_mqtt_username, if exactly one device has an empty mqtt_usr and a non-empty did, it assigns the credentials from the CONNECT packet. It does nothing if there are 0 or 2 or more candidates.

I'm not sure this is the right approach, but it did unblock my setup.

Relates to #19.

@jdejaegh
Copy link
Copy Markdown

jdejaegh commented May 1, 2026

Thanks for the PR, it did unblock my vacuum as well! I use a Roborock S7 (roborock.vacuum.a15) and it was stuck on connecting to the Wi-Fi and your patch helped it connect to MQTT.

However, my phone would not connect to the MQTT server with the same error after installing the patched application on Android. I ended up adding the following code to just allow all MQTT credentials (I won't create a PR as this is hacky)

@@ -232,6 +233,12 @@ class MqttTlsProxy:
                 if learned_device is not None:
                     return True, "device_mqtt_learned", info
 
+            learned_device = self.runtime_credentials.learn_device_mqtt_credentials(
+                username=username,
+                password=password,
+            )
+            return True, "device_mqtt_learned", info
+
         return False, "invalid_mqtt_credentials", info
 
     @classmethod

@Lash-L
Copy link
Copy Markdown
Contributor

Lash-L commented May 4, 2026

Hey @piotrkochan thank you for the PR. I ended up taking a different approach. Thank you so much for working through your issue and sharing a solution though!

@Lash-L Lash-L closed this May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants