{"record":{"id":"20ee721ee69142a2","repo":"AlexxIT/go2rtc","slug":"failed-to-start-mqtt-w-20ee72","errorCode":null,"errorMessage":"failed to start MQTT: %w","messagePattern":"failed to start MQTT: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/tuya/smart_api.go","lineNumber":314,"sourceCode":"\n// WebRTC Flow\nfunc (c *TuyaSmartApiClient) Init() error {\n\tif err := c.initToken(); err != nil {\n\t\treturn fmt.Errorf(\"failed to initialize token: %w\", err)\n\t}\n\n\twebrtcConfig, err := c.loadWebrtcConfig()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to load webrtc config: %w\", err)\n\t}\n\n\thubConfig, err := c.loadHubConfig()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to load hub config: %w\", err)\n\t}\n\n\tif err := c.mqtt.Start(hubConfig, webrtcConfig, c.skill.WebRTC); err != nil {\n\t\treturn fmt.Errorf(\"failed to start MQTT: %w\", err)\n\t}\n\n\tif c.skill.LowPower > 0 {\n\t\t_ = c.mqtt.WakeUp(c.localKey)\n\t}\n\n\treturn nil\n}\n\nfunc (c *TuyaSmartApiClient) GetStreamUrl(streamType string) (streamUrl string, err error) {\n\treturn \"\", errors.New(\"not supported\")\n}\n\nfunc (c *TuyaSmartApiClient) GetAppInfo() (*AppInfoResponse, error) {\n\turl := fmt.Sprintf(\"https://%s/api/customized/web/app/info\", c.baseUrl)\n\n\tbody, err := c.request(\"POST\", url, nil)\n\tif err != nil {","sourceCodeStart":296,"sourceCodeEnd":332,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/pkg/tuya/smart_api.go#L296-L332","documentation":"Wraps an error from mqtt.Start() after Tuya cloud configs were successfully loaded. The MQTT layer connects to the Tuya hub broker using hubConfig to exchange WebRTC signaling. Any connect, TLS, auth, or subscribe failure surfaces as this error.","triggerScenarios":"TuyaSmartAPI Start() when the MQTT client cannot connect/authenticate to the broker from hubConfig: wrong broker host/port, TLS handshake failure, credentials rejected, or network unreachable.","commonSituations":"Firewall or ISP blocking the MQTT port; stale hub credentials after re-pairing the device; DNS failure resolving the broker hostname; hubConfig fetched from the wrong region so broker endpoints are invalid.","solutions":["Inspect the wrapped inner error for connect vs TLS vs auth failure","Verify outbound access to the Tuya MQTT broker host:port from this network","Re-fetch config/token; re-pair or re-authenticate the device if credentials were rotated","Confirm region/countryCode matches the account so hubConfig contains valid broker endpoints","Check DNS resolution of the broker hostname on the host running go2rtc"],"exampleFix":"// before\nif err := c.mqtt.Start(hubConfig, webrtcConfig, skill.WebRTC); err != nil {\n    return fmt.Errorf(\"failed to start MQTT: %w\", err)\n}\n// after\nif err := c.mqtt.Start(hubConfig, webrtcConfig, skill.WebRTC); err != nil {\n    log.Errorf(\"mqtt start failed (broker=%s): %v\", hubConfig.Broker, err) // surface broker for diagnosis\n    return fmt.Errorf(\"failed to start MQTT: %w\", err)\n}","handlingStrategy":"retry","validationCode":"// Go: pre-check broker reachability before Start\nconn, err := net.DialTimeout(\"tcp\", brokerHost+\":\"+brokerPort, 5*time.Second)\nif err != nil { return fmt.Errorf(\"mqtt broker unreachable: %w\", err) }\nconn.Close()","typeGuard":"func hubConfigValid(cfg *tuya.HubConfig) bool { return cfg != nil && cfg.Broker != \"\" && cfg.Port > 0 }","tryCatchPattern":"if err := c.Start(); err != nil {\n    if strings.Contains(err.Error(), \"failed to start MQTT\") {\n        return retryWithBackoff(3, c.Start) // transient network failures\n    }\n    return err\n}","preventionTips":["Open firewall egress to Tuya MQTT broker host:port","Check DNS resolution of broker hostnames on the host","Re-pair devices after credential rotation","Test TLS connectivity (openssl s_client) to the broker during setup"],"tags":["tuya","mqtt","connection","network"],"backgroundTag":"connection-refused","analyzedSha":"c245815e75e2a5fd60b4290f12bfc04e55a984d3","analyzedAt":"2026-09-07T11:47:02.965Z","contentChangedAt":"2026-09-07T11:47:02.965Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}