contrib/examples/mqtt/mqtt_example.c | 1 + src/apps/mqtt/mqtt.c | 13 ++++++++++--- src/include/lwip/apps/mqtt.h | 2 ++ test/unit/mqtt/test_mqtt.c | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/contrib/examples/mqtt/mqtt_example.c b/contrib/examples/mqtt/mqtt_example.c index bb277d6f..9cf188df 100644 --- a/contrib/examples/mqtt/mqtt_example.c +++ b/contrib/examples/mqtt/mqtt_example.c @@ -54,6 +54,7 @@ static const struct mqtt_connect_client_info_t mqtt_client_info = 100, /* keep alive */ NULL, /* will_topic */ NULL, /* will_msg */ + 0, /* will_msg_len */ 0, /* will_qos */ 0 /* will_retain */ #if LWIP_ALTCP && LWIP_ALTCP_TLS diff --git a/src/apps/mqtt/mqtt.c b/src/apps/mqtt/mqtt.c index 0da1a405..069cef71 100644 --- a/src/apps/mqtt/mqtt.c +++ b/src/apps/mqtt/mqtt.c @@ -1337,9 +1337,16 @@ mqtt_client_connect(mqtt_client_t *client, const ip_addr_t *ip_addr, u16_t port, LWIP_ERROR("mqtt_client_connect: client_info->will_topic length overflow", len <= 0xFF, return ERR_VAL); LWIP_ERROR("mqtt_client_connect: client_info->will_topic length must be > 0", len > 0, return ERR_VAL); will_topic_len = (u8_t)len; - len = strlen(client_info->will_msg); - LWIP_ERROR("mqtt_client_connect: client_info->will_msg length overflow", len <= 0xFF, return ERR_VAL); - will_msg_len = (u8_t)len; + if (client_info->will_msg_len == 0) + { + len = strlen(client_info->will_msg); + LWIP_ERROR("mqtt_client_connect: client_info->will_msg length overflow", len <= 0xFF, return ERR_VAL); + will_msg_len = (u8_t)len; + } + else + { + will_msg_len = client_info->will_msg_len; + } len = remaining_length + 2 + will_topic_len + 2 + will_msg_len; LWIP_ERROR("mqtt_client_connect: remaining_length overflow", len <= 0xFFFF, return ERR_VAL); remaining_length = (u16_t)len; diff --git a/src/include/lwip/apps/mqtt.h b/src/include/lwip/apps/mqtt.h index bece4005..f1583fc4 100644 --- a/src/include/lwip/apps/mqtt.h +++ b/src/include/lwip/apps/mqtt.h @@ -79,6 +79,8 @@ struct mqtt_connect_client_info_t { const char* will_topic; /** will_msg, see will_topic */ const char* will_msg; + /** will_msg length, 0 to compute length from will_msg string */ + u8_t will_msg_len; /** will_qos, see will_topic */ u8_t will_qos; /** will_retain, see will_topic */ diff --git a/test/unit/mqtt/test_mqtt.c b/test/unit/mqtt/test_mqtt.c index 7cff13ea..9722aa66 100644 --- a/test/unit/mqtt/test_mqtt.c +++ b/test/unit/mqtt/test_mqtt.c @@ -77,7 +77,7 @@ START_TEST(basic_connect) "dumm", NULL, NULL, 10, - NULL, NULL, 0, 0 + NULL, NULL, 0, 0, 0 }; struct pbuf *p; unsigned char rxbuf[] = {0x20, 0x02, 0x00, 0x00};