diff --git a/examples/tencent_firmware_mqtt/tencent_firmware_mqtt.c b/examples/tencent_firmware_mqtt/tencent_firmware_mqtt.c index a33266e7..f14a9ac9 100644 --- a/examples/tencent_firmware_mqtt/tencent_firmware_mqtt.c +++ b/examples/tencent_firmware_mqtt/tencent_firmware_mqtt.c @@ -4,7 +4,7 @@ void mqtt_demo_task(void) { - char payload[256]; + char payload[256] = {0}; mqtt_state_t state; @@ -26,54 +26,54 @@ void mqtt_demo_task(void) strncpy(dev_info.device_serc, key, DEVICE_SERC_MAX_SIZE); tos_tf_module_info_set(&dev_info, TLS_MODE_PSK); - mqtt_param_t init_params = DEFAULT_MQTT_PARAMS; - if (tos_tf_module_mqtt_conn(init_params) != 0) { - printf("module mqtt conn fail\n"); - } else { - printf("module mqtt conn success\n"); - } + mqtt_param_t init_params = DEFAULT_MQTT_PARAMS; + if (tos_tf_module_mqtt_conn(init_params) != 0) { + printf("module mqtt conn fail\n"); + } else { + printf("module mqtt conn success\n"); + } if (tos_tf_module_mqtt_state_get(&state) != -1) { printf("MQTT: %s\n", state == MQTT_STATE_CONNECTED ? "CONNECTED" : "DISCONNECTED"); } - static char topic_name[TOPIC_MAX_SIZE] = {0}; - int size = snprintf(topic_name, TOPIC_MAX_SIZE, "%s/%s/data", product_id, device_name); + static char topic_name[TOPIC_MAX_SIZE] = {0}; + int size = snprintf(topic_name, TOPIC_MAX_SIZE, "%s/%s/data", product_id, device_name); - if (size < 0 || size > sizeof(topic_name) - 1) { - printf("topic content length not enough! content size:%d buf size:%d", size, (int)sizeof(topic_name)); - } - if (tos_tf_module_mqtt_sub(topic_name, QOS0) != 0) { - printf("module mqtt sub fail\n"); - } else { - printf("module mqtt sub success\n"); - } + if (size < 0 || size > sizeof(topic_name) - 1) { + printf("topic content length not enough! content size:%d buf size:%d", size, (int)sizeof(topic_name)); + } + if (tos_tf_module_mqtt_sub(topic_name, QOS0) != 0) { + printf("module mqtt sub fail\n"); + } else { + printf("module mqtt sub success\n"); + } - while (1) { - HAL_Delay(1000); + while (1) { + HAL_Delay(1000); /* use AT+PUB AT command */ - memset(payload, 0, 256); + memset(payload, 0, sizeof(payload)); strncpy(payload, "{\\\"type\\\":\\\"get\\\"\\, \\\"clientToken\\\":\\\"03UKNYBUZG-0\\\"}", sizeof(payload)); - printf("message publish: %s\n", payload); - if (tos_tf_module_mqtt_pub(topic_name, QOS0, payload) != 0) { - printf("module mqtt pub fail\n"); - break; - } else { - printf("module mqtt pub success\n"); - } + printf("message publish: %s\n", payload); + if (tos_tf_module_mqtt_pub(topic_name, QOS0, payload) != 0) { + printf("module mqtt pub fail\n"); + break; + } else { + printf("module mqtt pub success\n"); + } /* use AT+PUBL AT command */ - memset(payload, 0, 256); + memset(payload, 0, sizeof(payload)); strncpy(payload, "\"{\\\"type\\\":\\\"get\\\"\\, \\\"clientToken\\\":\\\"03UKNYBUZG-0\\\"}\"", sizeof(payload)); - if (tos_tf_module_mqtt_publ(topic_name, QOS0, payload) != 0) { - printf("module mqtt publ fail\n"); - break; - } else { - printf("module mqtt publ success\n"); - } - } + if (tos_tf_module_mqtt_publ(topic_name, QOS0, payload) != 0) { + printf("module mqtt publ fail\n"); + break; + } else { + printf("module mqtt publ success\n"); + } + } } void application_entry(void *arg) @@ -84,4 +84,3 @@ void application_entry(void *arg) tos_task_delay(1000); } } -