AlexxIT/go2rtc · error
failed to publish wake-up message
Error message
failed to publish wake-up message: %w
What it means
After publishing the wake-up message to topic m/w/{deviceId} at QoS 1, WakeUp waits on the Paho publish token and wraps any token error in this message. It means the MQTT broker rejected or failed the PUBLISH — typically because the connection dropped or broker refused the publish. The wake-up command was not delivered.
Solutions
- Check client.IsConnectionOpen() (or track the OnConnectionLost callback) before publishing
- Reconnect the MQTT client (Reconnect/resubscribe) and retry WakeUp once
- Verify broker reachability and TLS/auth settings used at Connect time
- Ensure the client isn't closed; sending after Close() will fail similarly
Example fix
// before
err := client.WakeUp(deviceID)
// after
if !client.IsConnectionOpen() {
if cerr := reconnect(client); cerr != nil { return cerr }
}
err := client.WakeUp(deviceID)
if err != nil && strings.Contains(err.Error(), "publish wake-up") {
err = retryWakeUp(client, deviceID)
} Defensive patterns
Strategy: retry
Validate before calling
if client == nil || !client.IsConnectionOpen() { return errors.New("mqtt not connected") } Try / catch
err := client.WakeUp(deviceID)
if err != nil && strings.Contains(err.Error(), "publish wake-up") {
if cerr := reconnect(client); cerr == nil {
err = client.WakeUp(deviceID) // one retry
}
} Prevention
- Track OnConnectionLost and proactively reconnect
- Add keepalive/ping settings appropriate to low-power links
- Bound retries with backoff to avoid publishing into a dead broker
When it happens
Trigger: client.Publish(...).Wait() returns a non-nil token.Error(): broker disconnected mid-publish, keepalive expired, QoS 1 packet not acknowledged, or publish attempted while the client is disconnected/closed.
Common situations: Network drops between the device and broker, broker restarts, or calling WakeUp on a client whose MQTT connection already died; long-idle low-power camera clients often have stale connections.
Understand the failure class
Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.
Related errors
- failed to subscribe to lowPower topic
- openIoTHubConfigResponse.Msg
- mqtt client is closed, send mqtt message fail
- failed to start MQTT
- loginResp.ErrorMsg
AI-assisted analysis of AlexxIT/go2rtc@c245815e75 (2026-09-07).
Data as JSON: /api/errors/7b5022e6b6650473.
Report an issue: GitHub.
Appendix: source
Thrown at pkg/tuya/mqtt.go:192
// Convert to hex string
hexStr := fmt.Sprintf("%08x", crc)
// Convert hex string to byte array (2 chars at a time)
payload := make([]byte, len(hexStr)/2)
for i := 0; i < len(hexStr); i += 2 {
b, err := hex.DecodeString(hexStr[i : i+2])
if err != nil {
return fmt.Errorf("failed to decode hex: %w", err)
}
payload[i/2] = b[0]
}
// Publish to wake-up topic: m/w/{deviceId}
wakeUpTopic := fmt.Sprintf("m/w/%s", c.deviceId)
token := c.client.Publish(wakeUpTopic, 1, false, payload)
if token.Wait() && token.Error() != nil {
return fmt.Errorf("failed to publish wake-up message: %w", token.Error())
}
// Subscribe to lowPower topic to receive dps[149] status updates
// (we don't wait for this signal - camera responds immediately)
lowPowerTopic := fmt.Sprintf("smart/decrypt/in/%s", c.deviceId)
if token := c.client.Subscribe(lowPowerTopic, 1, c.onLowPowerMessage); token.Wait() && token.Error() != nil {
return fmt.Errorf("failed to subscribe to lowPower topic: %w", token.Error())
}
return nil
}
func (c *TuyaMqttClient) SendOffer(sdp string, streamResolution string, streamType int, isHEVC bool) error {
// Map Skill StreamType to MQTT stream_type values
// streamType comes from GetStreamType() and uses Skill StreamType values:
// - mainStream = 2 (HD)
// - substream = 4 (SD)
//View on GitHub (pinned to c245815e75)