Koenkk / zigbee2mqtt

Zigbee 🐝 to MQTT bridge 🌉, get rid of your proprietary Zigbee bridges 🔨
https://www.zigbee2mqtt.io
GNU General Public License v3.0
11.78k stars 1.64k forks source link

MQTT error: Cannot parse topic #21350

Open I-Would-Like-To-Report-A-Bug-Please opened 7 months ago

I-Would-Like-To-Report-A-Bug-Please commented 7 months ago

What happened?

It seems that Z2M lost a connection to MQTT server for a moment.

In Z2M logs I could only see MQTT error: Cannot parse topic constantly poping.

Initially, I thought there was an issue with the broker so I restarted it but that didn't fix the issue. Next, I've tried just a simple netcat connect test which has proven to work fine. As a last step, I've restarted Z2M which worked immediately.

That leads me to the conclusion that there could be some temporary problem with the connection which should be restored but it wasn't.

I've found similar issue from about a half year ago here: https://github.com/Koenkk/zigbee2mqtt/issues/16667

It has happened 2nd time in about 2 months, so after last issue I've prepped some temporary restart script that looks like that, maybe it'll help someone:

#!/usr/bin/env bash
set -o pipefail

cd /home/pi/zigbee2mqtt-data/log/ || exit 1
cd $(ls -1tr | tail -n1)          || exit 1

if tail -n30 log.txt | grep -q "MQTT error: Cannot parse topic"; then
  curl -H "Content-Type: application/json" -d \
    '{ "username": "Zigbee2Mqtt-Alert",
       "content": "Restarting Z2m",
       "avatar_url": "https://www.zigbee2mqtt.io/logo.png"
    }' "https://discord.com/api/webhooks/XXX/ZZZ"
  sudo systemctl restart zigbee2mqtt.service
fi

What did you expect to happen?

Z2M restores connections properly and starts processing events again.

How to reproduce it (minimal and precise)

Not a clue. I'd probably start maybe with simulating network issue? Stopping broker?

Zigbee2MQTT version

1.34.0

Adapter firmware version

20230507

Adapter

zStack3x0

Setup

Pi installed by the node/setup script provided on the website.

Debug log

No response

I-Would-Like-To-Report-A-Bug-Please commented 6 months ago

Today it has happened again, luckily script kicked in nicely and was able to restart Z2M which has fixed the issue.

A bit of log.txt

error 2024-02-20 05:14:44: MQTT error: Cannot parse topic
error 2024-02-20 05:14:44: MQTT error: Invalid header flag bits, must be 0x2 for pubrel packet
<SOME VALID MESSAGES>
info  2024-02-20 05:14:58: MQTT publish: topic 'zigbee2mqtt/Data.AirQualitySensor', payload '{"co2":357,"formaldehyd":1,"humidity":63.7,"last_seen":"2024-02-20T05:14:58.281Z","linkquality":80,"pm25":8,"temperature":18.1,"voc":12}'
error 2024-02-20 05:14:58: MQTT error: Cannot parse topic
error 2024-02-20 05:14:58: MQTT error: Cannot parse topic
info  2024-02-20 05:14:58: MQTT publish: topic 'zigbee2mqtt/Data.AirQualitySensor', payload '{"co2":357,"formaldehyd":1,"humidity":64.1,"last_seen":"2024-02-20T05:14:58.325Z","linkquality":80,"pm25":8,"temperature":18.1,"voc":12}'
error 2024-02-20 05:14:58: MQTT error: Cannot parse topic
error 2024-02-20 05:14:58: MQTT error: Invalid header flag bits, must be 0x2 for pubrel packet
error 2024-02-20 05:14:58: MQTT error: Invalid header flag bits, must be 0x2 for pubrel packet
error 2024-02-20 05:14:58: MQTT error: Cannot parse topic
error 2024-02-20 05:14:58: MQTT error: Cannot parse topic
<SOME VALID MESSAGES>
error 2024-02-20 05:14:59: MQTT error: Cannot parse topic                                                                                                                                   info  2024-02-20 05:14:59: MQTT publish: topic 'zigbee2mqtt/Heating.TRV.Games', payload '{"battery_low":false,"child_lock":"UNLOCK","current_heating_setpoint":20,"error":null,"frost_protection":"ON","last_seen":"2024-02-20T05:14:59.543Z","linkquality":163,"local_temperature":13,"local_temperature_calibration":-3,"running_state":"heat","scale_protection":"ON","schedule_friday":"06:00/12.0 08:00/16.0 18:00/22.0 20:00/20.0","schedule_monday":"06:00/12.0 08:00/16.0 18:00/22.0 20:00/20.0","schedule_saturday":"06:00/12.0 08:00/16.0 18:00/22.0 20:00/20.0","schedule_sunday":"06:00/12.0 08:00/16.0 18:00/22.0 20:00/20.0","schedule_thursday":"06:00/12.0 08:00/16.0 18:00/22.0 20:00/20.0","schedule_tuesday":"06:00/12.0 08:00/16.0 18:00/22.0 20:00/20.0","schedule_wednesday":"06:00/12.0 08:00/16.0 18:00/22.0 20:00/20.0","system_mode":"auto"}'                                                                                                     error 2024-02-20 05:14:59: MQTT error: Cannot parse topic                                                                                                                                   error 2024-02-20 05:14:59: MQTT error: Cannot parse topic                                                                                                                                   error 2024-02-20 05:14:59: MQTT error: Invalid header flag bits, must be 0x2 for pubrel packet      
<SOME VALID MESSAGES>
info  2024-02-20 05:15:02: MQTT publish: topic 'zigbee2mqtt/bridge/state', payload '{"state":"offline"}'
info  2024-02-20 05:15:02: Disconnecting from MQTT server
info  2024-02-20 05:15:02: Stopping zigbee-herdsman...
error 2024-02-20 05:15:02: MQTT error: Cannot parse topic
error 2024-02-20 05:15:02: MQTT error: read ECONNRESET
info  2024-02-20 05:15:11: Stopped zigbee-herdsman
info  2024-02-20 05:15:11: Stopped Zigbee2MQTT

The last bit is where the script kicked in to restart it, after doing so everything went back to normal. After last time I've upgraded to: Starting Zigbee2MQTT version 1.35.3 so using latest didn't help.

I-Would-Like-To-Report-A-Bug-Please commented 6 months ago

No one? It happened again...

github-actions[bot] commented 2 weeks ago

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 30 days