1010
1111#define RC_STR (rc ) (rc == TC_PASS ? PASS : FAIL)
1212
13+ #define CLIENTID "zephyr"
14+ #define CLIENTID_LEN 6
15+ #define TOPIC "sensors"
16+ #define TOPIC_LEN 7
17+ #define WILL_TOPIC "quitting"
18+ #define WILL_TOPIC_LEN 8
19+ #define USERNAME "zephyr1"
20+ #define USERNAME_LEN 7
21+
1322/* MQTT messages in this test are under 256 bytes */
1423#define BUF_SIZE 256
1524static uint8_t buf [BUF_SIZE ];
@@ -220,7 +229,9 @@ uint8_t connect1[] = {0x10, 0x12, 0x00, 0x04, 0x4d, 0x51, 0x54, 0x54,
220229 0x70 , 0x68 , 0x79 , 0x72 };
221230
222231static struct mqtt_connect_msg msg_connect1 = {
223- .clean_session = 1 , .client_id = "zephyr" , .will_flag = 0 ,
232+ .clean_session = 1 , .client_id = CLIENTID ,
233+ .client_id_len = CLIENTID_LEN ,
234+ .will_flag = 0 ,
224235 .will_qos = 0 , .will_retain = 0 , .will_topic = NULL ,
225236 .will_msg = NULL , .will_msg_len = 0 ,
226237 .keep_alive = 0 , .user_name = NULL ,
@@ -240,7 +251,9 @@ uint8_t connect2[] = {0x10, 0x12, 0x00, 0x04, 0x4d, 0x51, 0x54, 0x54,
240251 0x70 , 0x68 , 0x79 , 0x72 };
241252
242253static struct mqtt_connect_msg msg_connect2 = {
243- .clean_session = 1 , .client_id = "zephyr" , .will_flag = 0 ,
254+ .clean_session = 1 , .client_id = CLIENTID ,
255+ .client_id_len = CLIENTID_LEN ,
256+ .will_flag = 0 ,
244257 .will_qos = 0 , .will_retain = 0 , .will_topic = NULL ,
245258 .will_msg = NULL , .will_msg_len = 0 ,
246259 .keep_alive = 365 , .user_name = NULL ,
@@ -265,8 +278,11 @@ uint8_t connect3[] = {0x10, 0x21, 0x00, 0x04, 0x4d, 0x51, 0x54, 0x54,
265278 0x62 , 0x79 , 0x65 };
266279
267280static struct mqtt_connect_msg msg_connect3 = {
268- .clean_session = 1 , .client_id = "zephyr" , .will_flag = 1 ,
269- .will_qos = 0 , .will_retain = 0 , .will_topic = "quitting" ,
281+ .clean_session = 1 , .client_id = CLIENTID ,
282+ .client_id_len = CLIENTID_LEN ,
283+ .will_flag = 1 ,
284+ .will_qos = 0 , .will_retain = 0 , .will_topic = WILL_TOPIC ,
285+ .will_topic_len = WILL_TOPIC_LEN ,
270286 .will_msg = "bye" , .will_msg_len = 3 ,
271287 .keep_alive = 0 , .user_name = NULL ,
272288 .password = NULL , .password_len = 0
@@ -288,8 +304,11 @@ uint8_t connect4[] = {0x10, 0x21, 0x00, 0x04, 0x4d, 0x51, 0x54, 0x54,
288304 0x62 , 0x79 , 0x65 };
289305
290306static struct mqtt_connect_msg msg_connect4 = {
291- .clean_session = 1 , .client_id = "zephyr" , .will_flag = 1 ,
292- .will_qos = 0 , .will_retain = 1 , .will_topic = "quitting" ,
307+ .clean_session = 1 , .client_id = CLIENTID ,
308+ .client_id_len = CLIENTID_LEN ,
309+ .will_flag = 1 ,
310+ .will_qos = 0 , .will_retain = 1 , .will_topic = WILL_TOPIC ,
311+ .will_topic_len = WILL_TOPIC_LEN ,
293312 .will_msg = "bye" , .will_msg_len = 3 ,
294313 .keep_alive = 0 , .user_name = NULL ,
295314 .password = NULL , .password_len = 0
@@ -311,8 +330,11 @@ uint8_t connect5[] = {0x10, 0x21, 0x00, 0x04, 0x4d, 0x51, 0x54, 0x54,
311330 0x62 , 0x79 , 0x65 };
312331
313332static struct mqtt_connect_msg msg_connect5 = {
314- .clean_session = 1 , .client_id = "zephyr" , .will_flag = 1 ,
315- .will_qos = 1 , .will_retain = 0 , .will_topic = "quitting" ,
333+ .clean_session = 1 , .client_id = CLIENTID ,
334+ .client_id_len = CLIENTID_LEN ,
335+ .will_flag = 1 ,
336+ .will_qos = 1 , .will_retain = 0 , .will_topic = WILL_TOPIC ,
337+ .will_topic_len = WILL_TOPIC_LEN ,
316338 .will_msg = "bye" , .will_msg_len = 3 ,
317339 .keep_alive = 0 , .user_name = NULL ,
318340 .password = NULL , .password_len = 0
@@ -334,8 +356,11 @@ uint8_t connect6[] = {0x10, 0x21, 0x00, 0x04, 0x4d, 0x51, 0x54, 0x54,
334356 0x62 , 0x79 , 0x65 };
335357
336358static struct mqtt_connect_msg msg_connect6 = {
337- .clean_session = 1 , .client_id = "zephyr" , .will_flag = 1 ,
338- .will_qos = 1 , .will_retain = 1 , .will_topic = "quitting" ,
359+ .clean_session = 1 , .client_id = CLIENTID ,
360+ .client_id_len = CLIENTID_LEN ,
361+ .will_flag = 1 ,
362+ .will_qos = 1 , .will_retain = 1 , .will_topic = WILL_TOPIC ,
363+ .will_topic_len = WILL_TOPIC_LEN ,
339364 .will_msg = "bye" , .will_msg_len = 3 ,
340365 .keep_alive = 0 , .user_name = NULL ,
341366 .password = NULL , .password_len = 0
@@ -360,10 +385,14 @@ uint8_t connect7[] = {0x10, 0x34, 0x00, 0x04, 0x4d, 0x51, 0x54, 0x54,
360385 0x73 , 0x73 , 0x77 , 0x6f , 0x72 , 0x64 };
361386
362387static struct mqtt_connect_msg msg_connect7 = {
363- .clean_session = 1 , .client_id = "zephyr" , .will_flag = 1 ,
364- .will_qos = 1 , .will_retain = 1 , .will_topic = "quitting" ,
388+ .clean_session = 1 , .client_id = CLIENTID ,
389+ .client_id_len = CLIENTID_LEN ,
390+ .will_flag = 1 ,
391+ .will_qos = 1 , .will_retain = 1 , .will_topic = WILL_TOPIC ,
392+ .will_topic_len = WILL_TOPIC_LEN ,
365393 .will_msg = "bye" , .will_msg_len = 3 ,
366- .keep_alive = 0 , .user_name = "zephyr1" ,
394+ .keep_alive = 0 , .user_name = USERNAME ,
395+ .user_name_len = USERNAME_LEN ,
367396 .password = "password" , .password_len = 8
368397};
369398
@@ -382,7 +411,8 @@ uint8_t publish1[] = {0x30, 0x0b, 0x00, 0x07, 0x73, 0x65, 0x6e, 0x73,
382411 0x6f , 0x72 , 0x73 , 0x4f , 0x4b };
383412
384413static struct mqtt_publish_msg msg_publish1 = {
385- .dup = 0 , .qos = 0 , .retain = 0 , .topic = "sensors" ,
414+ .dup = 0 , .qos = 0 , .retain = 0 , .topic = TOPIC ,
415+ .topic_len = TOPIC_LEN ,
386416 .pkt_id = 0 , .msg = "OK" , .msg_len = 2 ,
387417};
388418
@@ -398,7 +428,8 @@ uint8_t publish2[] = {0x31, 0x0b, 0x00, 0x07, 0x73, 0x65, 0x6e, 0x73,
398428 0x6f , 0x72 , 0x73 , 0x4f , 0x4b };
399429
400430static struct mqtt_publish_msg msg_publish2 = {
401- .dup = 0 , .qos = 0 , .retain = 1 , .topic = "sensors" ,
431+ .dup = 0 , .qos = 0 , .retain = 1 , .topic = TOPIC ,
432+ .topic_len = TOPIC_LEN ,
402433 .pkt_id = 0 , .msg = "OK" , .msg_len = 2
403434};
404435
@@ -414,7 +445,8 @@ uint8_t publish3[] = {0x33, 0x0d, 0x00, 0x07, 0x73, 0x65, 0x6e, 0x73,
414445 0x6f , 0x72 , 0x73 , 0x00 , 0x01 , 0x4f , 0x4b };
415446
416447static struct mqtt_publish_msg msg_publish3 = {
417- .dup = 0 , .qos = 1 , .retain = 1 , .topic = "sensors" ,
448+ .dup = 0 , .qos = 1 , .retain = 1 , .topic = TOPIC ,
449+ .topic_len = TOPIC_LEN ,
418450 .pkt_id = 1 , .msg = "OK" , .msg_len = 2
419451};
420452
@@ -429,7 +461,8 @@ static
429461uint8_t publish4 [] = {0x34 , 0x0d , 0x00 , 0x07 , 0x73 , 0x65 , 0x6e , 0x73 ,
430462 0x6f , 0x72 , 0x73 , 0x00 , 0x01 , 0x4f , 0x4b };
431463static struct mqtt_publish_msg msg_publish4 = {
432- .dup = 0 , .qos = 2 , .retain = 0 , .topic = "sensors" ,
464+ .dup = 0 , .qos = 2 , .retain = 0 , .topic = TOPIC ,
465+ .topic_len = TOPIC_LEN ,
433466 .pkt_id = 1 , .msg = "OK" , .msg_len = 2
434467};
435468
0 commit comments