Skip to content

Commit

Permalink
anavi-thermometer-sw.ino: Reduce ClientID length
Browse files Browse the repository at this point in the history
Reduce the ClientID length and try to keep it below 23 bytes.

According to MQTT protocol version 5.0, the MQTT broker must allow
23 UTF-8 encoded bytes for ClientID. Some brokers MAY allow a
longer ClientID:
https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901059

This commit fixes GitHub issue #43:
#43

Reported-by: Antonio Tapiador <[email protected]>
Signed-off-by: Leon Anavi <[email protected]>
  • Loading branch information
leon-anavi committed Mar 22, 2020
1 parent 3a479ec commit e900f4f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions anavi-thermometer-sw/anavi-thermometer-sw.ino
Original file line number Diff line number Diff line change
Expand Up @@ -539,13 +539,20 @@ void MQTTStatus::publish_online(bool force_update)
}

MQTTConnection::MQTTConnection()
: espClient(), mqttClient(espClient), requested(false), status_list(0)
: espClient(), mqttClient(espClient), requested(false),
status_list(0), client_id(PRODUCT)
{
}

void MQTTConnection::set_spec(const MQTTSpec *spec)
{
client_id = String("anavi-thermometer-") + machineId + "-" + spec->topic;
String minId(machineId);
if (minId.length() > 5)
{
minId = minId.substring(minId.length() - 5);
}
client_id = String("anavi-") + minId + "-" + spec->topic;
Serial.println("set_spec client_id: " + client_id);
}

void MQTTConnection::connect()
Expand Down

0 comments on commit e900f4f

Please sign in to comment.