homebridge-mqttthing
homebridge-mqttthing copied to clipboard
MQTT Client-ID not accepted by all brokers
The MQTT Client-ID that is generated by homebridge-mqttthing is not supported by all MQTT broker.
MQTT specification states:
The Server MUST allow ClientID’s which are between 1 and 23 UTF-8 encoded bytes in length, and that contain only the characters "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" [MQTT-3.1.3-5].
The Server MAY allow ClientID’s that contain more than 23 encoded bytes. The Server MAY allow ClientID’s that contain characters not included in the list given above.
As homebridge-mqttthing includes underscores and more than 23 characters in its client-ID, it might be rejected by some servers:
[09/05/2021, 08:34:04] [ThermostatMQTT] MQTT options: {"keepalive":10,"clientId":"mqttthing_ThermostatMQTT_30c56e2b","protocolId":"MQTT","protocolVersion":4,"clean":true,"reconnectPeriod":1000,"connectTimeout":30000,"will":{"topic":"WillMsg","payload":"mqtt-thing [ThermostatMQTT] has stopped","qos":0,"retain":false},"rejectUnauthorized":false}
[09/05/2021, 08:34:04] [ThermostatMQTT] MQTT Error: Error: Connection refused: Identifier rejected
Workaround: Client-ID can be overriden manually by defining mqttOptions in the accessory:
"mqttOptions": {
"clientId": "mqttthingThermostatMQTT"
}
Fix: It would be nice (enhancement) if homebridge-mqttthing matches to the minimum requirements of the client-ID as defined in MQTT specification. That would increase out-of-the-box compatibility with more MQTT brokers, without applying any workarounds.
Good spot, thanks.