implemented support for non-string type last will messages

This commit is contained in:
Tijn Kooijmans
2017-07-21 21:39:24 +02:00
parent be91ed4a2c
commit fa087cb2fe
4 changed files with 8 additions and 2 deletions

View File

@@ -58,6 +58,7 @@ typedef struct mqtt_settings {
char password[CONFIG_MQTT_MAX_PASSWORD_LEN];
char lwt_topic[CONFIG_MQTT_MAX_LWT_TOPIC];
char lwt_msg[CONFIG_MQTT_MAX_LWT_MSG];
uint32_t lwt_msg_len;
uint32_t lwt_qos;
uint32_t lwt_retain;
uint32_t clean_session;

View File

@@ -93,6 +93,7 @@ typedef struct mqtt_connect_info
char* will_topic;
char* will_message;
int keepalive;
int will_length;
int will_qos;
int will_retain;
int clean_session;

6
mqtt.c
View File

@@ -529,6 +529,10 @@ mqtt_client *mqtt_start(mqtt_settings *settings)
}
memset(client, 0, sizeof(mqtt_client));
if (settings->lwt_msg_len > CONFIG_MQTT_MAX_LWT_MSG) {
mqtt_error("Last will message longer than CONFIG_MQTT_MAX_LWT_MSG!");
}
client->settings = settings;
client->connect_info.client_id = settings->client_id;
client->connect_info.username = settings->username;
@@ -537,7 +541,7 @@ mqtt_client *mqtt_start(mqtt_settings *settings)
client->connect_info.will_message = settings->lwt_msg;
client->connect_info.will_qos = settings->lwt_qos;
client->connect_info.will_retain = settings->lwt_retain;
client->connect_info.will_length = settings->lwt_msg_len;
client->keepalive_tick = settings->keepalive / 2;

View File

@@ -328,7 +328,7 @@ mqtt_message_t* mqtt_msg_connect(mqtt_connection_t* connection, mqtt_connect_inf
if (append_string(connection, info->will_topic, strlen(info->will_topic)) < 0)
return fail_message(connection);
if (append_string(connection, info->will_message, strlen(info->will_message)) < 0)
if (append_string(connection, info->will_message, info->will_length) < 0)
return fail_message(connection);
variable_header->flags |= MQTT_CONNECT_FLAG_WILL;