From 6b0c56eab7cfd4ea9a4f6c0bc5f89e72f77ca710 Mon Sep 17 00:00:00 2001 From: jiejietop Date: Tue, 23 Jun 2020 08:51:11 +0800 Subject: [PATCH] fix mqttclient sample compilation error of board-TencentOS_tiny_EVB_MX_Plus ... --- .../BSP/Src/mqttclient.c | 50 ++++++------- .../KEIL/mqttclient/TencentOS_tiny.uvoptx | 70 +++++++++---------- .../KEIL/mqttclient/TencentOS_tiny.uvprojx | 42 +++++------ .../TOS-CONFIG/mqtt_config.h | 42 +++++------ 4 files changed, 97 insertions(+), 107 deletions(-) diff --git a/board/TencentOS_tiny_EVB_MX_Plus/BSP/Src/mqttclient.c b/board/TencentOS_tiny_EVB_MX_Plus/BSP/Src/mqttclient.c index 5f7dd127..93dda2f4 100644 --- a/board/TencentOS_tiny_EVB_MX_Plus/BSP/Src/mqttclient.c +++ b/board/TencentOS_tiny_EVB_MX_Plus/BSP/Src/mqttclient.c @@ -16,16 +16,13 @@ void mqtt_set_esp8266_port(hal_uart_port_t port) { } #endif -mqtt_client_t client; -client_init_params_t init_params; - 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"); } @@ -35,6 +32,8 @@ void mqttclient_task(void) char buf[100] = { 0 }; + mqtt_client_t *client = NULL; + mqtt_message_t msg; memset(&msg, 0, sizeof(msg)); @@ -49,33 +48,24 @@ void mqttclient_task(void) bc35_28_95_sal_init(HAL_UART_PORT_0); #endif - init_params.read_buf_size = 256; - init_params.write_buf_size = 256; - -#ifdef MQTT_NETWORK_TYPE_TLS - init_params.connect_params.network_params.network_ssl_params.ca_crt = test_ca_get(); - init_params.connect_params.network_params.port = "8883"; -#else - init_params.connect_params.network_params.port = "1883"; -#endif - init_params.connect_params.network_params.addr = "111.230.189.156"; //"47.95.164.112";//"jiejie01.top"; //"129.204.201.235"; //"192.168.1.101"; + mqtt_log_init(); - init_params.connect_params.user_name = "RUAP1R610Vsupowang;12010126;80LJ2;1621294860"; // random_string(10); //"jiejietop-acer1"; - init_params.connect_params.password = "2e90a9f1e604f2f0473355228c3d59276951aa8e6ed4d27f270f05ee8a4d0983;hmacsha256"; //random_string(10); // "123456"; - init_params.connect_params.client_id = "RUAP1R610Vsupowang";; //random_string(10); // "clientid-acer1"; - init_params.connect_params.clean_session = 1; - - 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, "111.230.189.156"); + mqtt_set_client_id(client, "RUAP1R610Vsupowang"); + mqtt_set_user_name(client, "RUAP1R610Vsupowang;12010126;80LJ2;1621294860"); + mqtt_set_password(client, "2e90a9f1e604f2f0473355228c3d59276951aa8e6ed4d27f270f05ee8a4d0983;hmacsha256"); + mqtt_set_clean_session(client, 1); + + error = mqtt_connect(client); - mqtt_subscribe(&client, "RUAP1R610V/supowang/data", QOS0, tos_topic_handler); + MQTT_LOG_D("mqtt connect error is %#x", error); - LOG_D("mqtt subscribe error is %#x", error); + mqtt_subscribe(client, "RUAP1R610V/supowang/data", QOS0, tos_topic_handler); + + MQTT_LOG_D("mqtt subscribe error is %#x", error); memset(&msg, 0, sizeof(msg)); @@ -86,7 +76,7 @@ void mqttclient_task(void) msg.qos = QOS0; msg.payload = (void *) buf; - error = mqtt_publish(&client, "RUAP1R610V/supowang/data", &msg); + error = mqtt_publish(client, "RUAP1R610V/supowang/data", &msg); tos_task_delay(4000); } diff --git a/board/TencentOS_tiny_EVB_MX_Plus/KEIL/mqttclient/TencentOS_tiny.uvoptx b/board/TencentOS_tiny_EVB_MX_Plus/KEIL/mqttclient/TencentOS_tiny.uvoptx index 3db15e9b..380fa5e4 100644 --- a/board/TencentOS_tiny_EVB_MX_Plus/KEIL/mqttclient/TencentOS_tiny.uvoptx +++ b/board/TencentOS_tiny_EVB_MX_Plus/KEIL/mqttclient/TencentOS_tiny.uvoptx @@ -1493,8 +1493,8 @@ 0 0 0 - ..\..\..\..\components\connectivity\mqttclient\common\list.c - list.c + ..\..\..\..\components\connectivity\mqttclient\common\random.c + random.c 0 0 @@ -1505,8 +1505,8 @@ 0 0 0 - ..\..\..\..\components\connectivity\mqttclient\common\random.c - random.c + ..\..\..\..\components\connectivity\mqttclient\common\mqtt_list.c + mqtt_list.c 0 0 @@ -1517,8 +1517,8 @@ 0 0 0 - ..\..\..\..\components\connectivity\mqttclient\common\error.h - error.h + ..\..\..\..\components\connectivity\mqttclient\common\mqtt_log.h + mqtt_log.h 0 0 @@ -1529,8 +1529,8 @@ 0 0 0 - ..\..\..\..\components\connectivity\mqttclient\common\log.h - log.h + ..\..\..\..\components\connectivity\mqttclient\common\mqtt_error.h + mqtt_error.h 0 0 @@ -1554,6 +1554,30 @@ 0 0 + + 18 + 98 + 1 + 0 + 0 + 0 + ..\..\..\..\components\connectivity\mqttclient\network\nettype_tls.c + nettype_tls.c + 0 + 0 + + + 18 + 99 + 1 + 0 + 0 + 0 + ..\..\..\..\components\connectivity\mqttclient\network\nettype_tcp.c + nettype_tcp.c + 0 + 0 + @@ -1564,7 +1588,7 @@ 0 19 - 98 + 100 1 0 0 @@ -1576,7 +1600,7 @@ 19 - 99 + 101 1 0 0 @@ -1588,7 +1612,7 @@ 19 - 100 + 102 1 0 0 @@ -1598,30 +1622,6 @@ 0 0 - - 19 - 101 - 1 - 0 - 0 - 0 - ..\..\..\..\components\connectivity\mqttclient\platform\TencentOS-tiny\platform_nettype_tcp.c - platform_nettype_tcp.c - 0 - 0 - - - 19 - 102 - 1 - 0 - 0 - 0 - ..\..\..\..\components\connectivity\mqttclient\platform\TencentOS-tiny\platform_nettype_tls.c - platform_nettype_tls.c - 0 - 0 - 19 103 diff --git a/board/TencentOS_tiny_EVB_MX_Plus/KEIL/mqttclient/TencentOS_tiny.uvprojx b/board/TencentOS_tiny_EVB_MX_Plus/KEIL/mqttclient/TencentOS_tiny.uvprojx index b881cabf..c5ef3a3b 100644 --- a/board/TencentOS_tiny_EVB_MX_Plus/KEIL/mqttclient/TencentOS_tiny.uvprojx +++ b/board/TencentOS_tiny_EVB_MX_Plus/KEIL/mqttclient/TencentOS_tiny.uvprojx @@ -16,7 +16,7 @@ STM32L431RCTx STMicroelectronics - Keil.STM32L4xx_DFP.2.0.0 + Keil.STM32L4xx_DFP.2.2.0 http://www.keil.com/pack IRAM(0x20000000-0x2000FFFF) IROM(0x8000000-0x803FFFF) CLOCK(8000000) FPU2 CPUTYPE("Cortex-M4") @@ -922,25 +922,25 @@ mqttclient/common - - list.c - 1 - ..\..\..\..\components\connectivity\mqttclient\common\list.c - random.c 1 ..\..\..\..\components\connectivity\mqttclient\common\random.c - error.h - 5 - ..\..\..\..\components\connectivity\mqttclient\common\error.h + mqtt_list.c + 1 + ..\..\..\..\components\connectivity\mqttclient\common\mqtt_list.c - log.h + mqtt_log.h 5 - ..\..\..\..\components\connectivity\mqttclient\common\log.h + ..\..\..\..\components\connectivity\mqttclient\common\mqtt_log.h + + + mqtt_error.h + 5 + ..\..\..\..\components\connectivity\mqttclient\common\mqtt_error.h @@ -952,6 +952,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 + @@ -972,16 +982,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/TencentOS_tiny_EVB_MX_Plus/TOS-CONFIG/mqtt_config.h b/board/TencentOS_tiny_EVB_MX_Plus/TOS-CONFIG/mqtt_config.h index c2caeb53..2e953d69 100644 --- a/board/TencentOS_tiny_EVB_MX_Plus/TOS-CONFIG/mqtt_config.h +++ b/board/TencentOS_tiny_EVB_MX_Plus/TOS-CONFIG/mqtt_config.h @@ -1,48 +1,48 @@ /* * @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 #define MQTT_THREAD_PRIO 5 #define MQTT_THREAD_TICK 50 -#define MQTT_NETSOCKET_USE_AT -//#define MQTT_NETWORK_TYPE_TLS +#define MQTT_NETWORK_TYPE_NO_TLS #endif /* _MQTT_CONFIG_H_ */