diff --git a/board/EVB_LN882x/BSP/Src/mqtt_task.c b/board/EVB_LN882x/BSP/Src/mqtt_task.c index 4c0461c8..d1b765c9 100644 --- a/board/EVB_LN882x/BSP/Src/mqtt_task.c +++ b/board/EVB_LN882x/BSP/Src/mqtt_task.c @@ -9,45 +9,43 @@ static void tos_topic_handler(void* client, message_data_t* msg) { (void) client; - LOG_I("-----------------------------------------------------------------------------------"); - LOG_I("%s:%d %s()...\ntopic: %s, qos: %d. \nmessage:\n\t%s\n", __FILE__, __LINE__, __FUNCTION__, + MQTT_LOG_I("-----------------------------------------------------------------------------------"); + MQTT_LOG_I("%s:%d %s()...\ntopic: %s, qos: %d. \nmessage:\n\t%s\n", __FILE__, __LINE__, __FUNCTION__, msg->topic_name, msg->message->qos, (char*)msg->message->payload); - LOG_I("-----------------------------------------------------------------------------------\n"); + MQTT_LOG_I("-----------------------------------------------------------------------------------\n"); } - -mqtt_client_t client; -client_init_params_t init_params; - extern void TCPIP_Init(void); void mqtt_iothub(void) { int error; char buf[80] = { 0 }; + + mqtt_client_t *client = NULL; + mqtt_message_t msg; memset(&msg, 0, sizeof(msg)); sprintf(buf, "welcome to mqttclient, this is a publish test..."); - init_params.read_buf_size = 1024; - init_params.write_buf_size = 1024; - init_params.connect_params.network_params.addr = "iotcloud-mqtt.gz.tencentdevices.com"; - init_params.connect_params.network_params.port = "1883"; - init_params.connect_params.user_name = "RUAP1R610Vsupowang;12010126;FTDC9;1623108655"; - init_params.connect_params.password = "29e68d809ac4ac0e41bf30cc77cd377d30e7af03f3c76b0c50fa27a2c59e174b;hmacsha256"; - init_params.connect_params.client_id = "RUAP1R610Vsupowang"; - init_params.connect_params.clean_session = 1; + mqtt_log_init(); - log_init(); - - mqtt_init(&client, &init_params); - - error = mqtt_connect(&client); + client = mqtt_lease(); - LOG_D("mqtt connect error is %#x", error); + mqtt_set_port(client, "1883"); + mqtt_set_host(client, "iotcloud-mqtt.gz.tencentdevices.com"); + mqtt_set_client_id(client, "RUAP1R610Vsupowang"); + mqtt_set_user_name(client, "RUAP1R610Vsupowang;12010126;FTDC9;1623108655"); + mqtt_set_password(client, "29e68d809ac4ac0e41bf30cc77cd377d30e7af03f3c76b0c50fa27a2c59e174b;hmacsha256"); + mqtt_set_clean_session(client, 1); - mqtt_subscribe(&client, "RUAP1R610V/supowang/data", QOS0, tos_topic_handler); + + error = mqtt_connect(client); + + MQTT_LOG_D("mqtt connect error is %#x", error); + + mqtt_subscribe(client, "RUAP1R610V/supowang/data", QOS0, tos_topic_handler); memset(&msg, 0, sizeof(msg)); @@ -56,7 +54,7 @@ void mqtt_iothub(void) msg.qos = QOS0; msg.payload = (void *) buf; - mqtt_publish(&client, "RUAP1R610V/supowang/data", &msg); + mqtt_publish(client, "RUAP1R610V/supowang/data", &msg); tos_task_delay(4000); } diff --git a/board/EVB_LN882x/KEIL/mqtt_client/TencentOS_tiny.uvoptx b/board/EVB_LN882x/KEIL/mqtt_client/TencentOS_tiny.uvoptx index f2446d5c..7d1d66fe 100644 --- a/board/EVB_LN882x/KEIL/mqtt_client/TencentOS_tiny.uvoptx +++ b/board/EVB_LN882x/KEIL/mqtt_client/TencentOS_tiny.uvoptx @@ -100,7 +100,10 @@ 1 0 0 - 6 + 1 + 0 + 0 + 4 @@ -231,11 +234,19 @@ 0 - - - 0 + 0 + 0 + + + + + + + + 1 + 0 0 2 10000000 @@ -2192,12 +2203,12 @@ 26 146 - 5 + 1 0 0 0 - ..\..\..\..\components\connectivity\mqttclient\common\error.h - error.h + ..\..\..\..\components\connectivity\mqttclient\common\mqtt_list.c + mqtt_list.c 0 0 @@ -2208,20 +2219,20 @@ 0 0 0 - ..\..\..\..\components\connectivity\mqttclient\common\log.h - log.h + ..\..\..\..\components\connectivity\mqttclient\common\mqtt_log.h + mqtt_log.h 0 0 26 148 - 1 + 5 0 0 0 - ..\..\..\..\components\connectivity\mqttclient\common\list.c - list.c + ..\..\..\..\components\connectivity\mqttclient\common\mqtt_error.h + mqtt_error.h 0 0 @@ -2245,6 +2256,30 @@ 0 0 + + 27 + 150 + 1 + 0 + 0 + 0 + ..\..\..\..\components\connectivity\mqttclient\network\nettype_tls.c + nettype_tls.c + 0 + 0 + + + 27 + 151 + 1 + 0 + 0 + 0 + ..\..\..\..\components\connectivity\mqttclient\network\nettype_tcp.c + nettype_tcp.c + 0 + 0 + @@ -2255,7 +2290,7 @@ 0 28 - 150 + 152 1 0 0 @@ -2267,7 +2302,7 @@ 28 - 151 + 153 1 0 0 @@ -2279,7 +2314,7 @@ 28 - 152 + 154 1 0 0 @@ -2289,30 +2324,6 @@ 0 0 - - 28 - 153 - 1 - 0 - 0 - 0 - ..\..\..\..\components\connectivity\mqttclient\platform\TencentOS-tiny\platform_nettype_tcp.c - platform_nettype_tcp.c - 0 - 0 - - - 28 - 154 - 1 - 0 - 0 - 0 - ..\..\..\..\components\connectivity\mqttclient\platform\TencentOS-tiny\platform_nettype_tls.c - platform_nettype_tls.c - 0 - 0 - 28 155 diff --git a/board/EVB_LN882x/KEIL/mqtt_client/TencentOS_tiny.uvprojx b/board/EVB_LN882x/KEIL/mqtt_client/TencentOS_tiny.uvprojx index 2001a485..eda6d5ec 100644 --- a/board/EVB_LN882x/KEIL/mqtt_client/TencentOS_tiny.uvprojx +++ b/board/EVB_LN882x/KEIL/mqtt_client/TencentOS_tiny.uvprojx @@ -10,7 +10,8 @@ TencentOS_tiny 0x4 ARM-ADS - 5060061::V5.06 update 1 (build 61)::ARMCC + 5060750::V5.06 update 6 (build 750)::ARMCC + 0 ARMCM4_FP @@ -183,6 +184,7 @@ 0 0 2 + 0 0 0 8 @@ -323,11 +325,15 @@ 0 0 1 + 0 0 1 1 1 1 + 0 + 0 + 0 LN882x,ARM_MATH_CM4 @@ -345,6 +351,7 @@ 0 0 0 + 0 @@ -497,11 +504,15 @@ 2 2 2 + 2 2 0 0 2 2 + 2 + 2 + 2 @@ -994,11 +1005,15 @@ 2 2 2 + 2 2 0 0 2 2 + 2 + 2 + 2 @@ -1320,19 +1335,19 @@ ..\..\..\..\components\connectivity\mqttclient\common\random.c - error.h - 5 - ..\..\..\..\components\connectivity\mqttclient\common\error.h - - - log.h - 5 - ..\..\..\..\components\connectivity\mqttclient\common\log.h - - - list.c + mqtt_list.c 1 - ..\..\..\..\components\connectivity\mqttclient\common\list.c + ..\..\..\..\components\connectivity\mqttclient\common\mqtt_list.c + + + mqtt_log.h + 5 + ..\..\..\..\components\connectivity\mqttclient\common\mqtt_log.h + + + mqtt_error.h + 5 + ..\..\..\..\components\connectivity\mqttclient\common\mqtt_error.h @@ -1344,6 +1359,16 @@ 1 ..\..\..\..\components\connectivity\mqttclient\network\network.c + + nettype_tls.c + 1 + ..\..\..\..\components\connectivity\mqttclient\network\nettype_tls.c + + + nettype_tcp.c + 1 + ..\..\..\..\components\connectivity\mqttclient\network\nettype_tcp.c + @@ -1364,16 +1389,6 @@ 1 ..\..\..\..\components\connectivity\mqttclient\platform\TencentOS-tiny\platform_net_socket.c - - platform_nettype_tcp.c - 1 - ..\..\..\..\components\connectivity\mqttclient\platform\TencentOS-tiny\platform_nettype_tcp.c - - - platform_nettype_tls.c - 1 - ..\..\..\..\components\connectivity\mqttclient\platform\TencentOS-tiny\platform_nettype_tls.c - platform_thread.c 1 diff --git a/board/EVB_LN882x/TOS-CONFIG/mqtt_config.h b/board/EVB_LN882x/TOS-CONFIG/mqtt_config.h index 4599bc94..759a483a 100644 --- a/board/EVB_LN882x/TOS-CONFIG/mqtt_config.h +++ b/board/EVB_LN882x/TOS-CONFIG/mqtt_config.h @@ -1,40 +1,41 @@ /* * @Author: jiejie * @Github: https://github.com/jiejieTop - * @Date: 2019-12-15 00:42:16 - * @LastEditTime: 2020-02-25 09:25:35 + * @LastEditTime: 2020-06-17 19:31:41 * @Description: the code belongs to jiejie, please keep the author information and source code according to the license. */ #ifndef _MQTT_CONFIG_H_ #define _MQTT_CONFIG_H_ -//#define LOG_IS_SALOF +//#define MQTT_LOG_IS_SALOF -#define LOG_LEVEL DEBUG_LEVEL //WARN_LEVEL DEBUG_LEVEL +//#define MQTT_NETSOCKET_USING_AT -#ifdef LOG_IS_SALOF - #define USE_LOG (1U) - #define USE_SALOF (1U) - #define SALOF_OS USE_TENCENTOS - #define USE_IDLE_HOOK (0U) - #define LOG_COLOR (0U) - #define LOG_TS (0U) - #define LOG_TAR (0U) - #define SALOF_BUFF_SIZE (512U) - #define SALOF_FIFO_SIZE (1024U) - #define SALOF_TASK_STACK_SIZE (1024U) - #define SALOF_TASK_TICK (50U) +#define MQTT_LOG_LEVEL MQTT_LOG_DEBUG_LEVEL //MQTT_LOG_WARN_LEVEL MQTT_LOG_DEBUG_LEVEL + +#ifdef MQTT_LOG_IS_SALOF + #define SALOF_USING_LOG (1U) + #define SALOF_USING_SALOF (1U) + #define SALOF_LOG_LEVEL MQTT_LOG_LEVEL + #define SALOF_OS SALOF_USING_TENCENTOS + #define SALOF_USING_IDLE_HOOK (0U) + #define SALOF_LOG_COLOR (1U) + #define SALOF_LOG_TS (0U) + #define SALOF_LOG_TAR (0U) + #define SALOF_BUFF_SIZE 512 + #define SALOF_FIFO_SIZE 4096 + #define SALOF_TASK_STACK_SIZE 1024 + #define SALOF_TASK_TICK 50 #endif - #define MQTT_MAX_PACKET_ID (0xFFFF - 1) #define MQTT_TOPIC_LEN_MAX 64 #define MQTT_ACK_HANDLER_NUM_MAX 64 #define MQTT_DEFAULT_BUF_SIZE 1024 -#define MQTT_DEFAULT_CMD_TIMEOUT 4000 +#define MQTT_DEFAULT_CMD_TIMEOUT 5000 #define MQTT_MAX_CMD_TIMEOUT 20000 #define MQTT_MIN_CMD_TIMEOUT 1000 -#define MQTT_KEEP_ALIVE_INTERVAL 100 // unit: second +#define MQTT_KEEP_ALIVE_INTERVAL 50 // unit: second #define MQTT_VERSION 4 // 4 is mqtt 3.1.1 #define MQTT_RECONNECT_DEFAULT_DURATION 1000 #define MQTT_THREAD_STACK_SIZE 2048 @@ -42,6 +43,6 @@ #define MQTT_THREAD_TICK 50 -//#define MQTT_NETWORK_TYPE_TLS +#define MQTT_NETWORK_TYPE_NO_TLS -#endif /* _MQTT_CONFIG_H_ */ +#endif /* _MQTT_CONFIG_H_ */ \ No newline at end of file