diff --git a/board/LTE_DTU_EC20_SIM7600CE/BSP/Src/mqtt_client.c b/board/LTE_DTU_EC20_SIM7600CE/BSP/Src/mqtt_client.c index 5125571a..b21bf819 100644 --- a/board/LTE_DTU_EC20_SIM7600CE/BSP/Src/mqtt_client.c +++ b/board/LTE_DTU_EC20_SIM7600CE/BSP/Src/mqtt_client.c @@ -7,16 +7,13 @@ #define USE_EC20 -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"); } @@ -25,6 +22,7 @@ void mqttclient_task(void) int error; char buf[100] = { 0 }; + mqtt_client_t *client = NULL; mqtt_message_t msg; @@ -37,36 +35,28 @@ void mqttclient_task(void) #ifdef USE_EC20 ec20_sal_init(HAL_UART_PORT_2); #endif + mqtt_log_init(); + + client = mqtt_lease(); - init_params.read_buf_size = 256; - init_params.write_buf_size = 256; + 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;OQHZL;1626061655"); + mqtt_set_password(client, "ed41ae0cdf9100ce2aa5d5874566f8f4f77b1eab80b19ede4d1419eafe92eb54;hmacsha256"); + mqtt_set_clean_session(client, 1); + mqtt_set_read_buf_size(client, 256); + mqtt_set_write_buf_size(client, 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"; - - init_params.connect_params.user_name = "RUAP1R610Vsupowang;12010126;OQHZL;1626061655"; // random_string(10); //"jiejietop-acer1"; - init_params.connect_params.password = "ed41ae0cdf9100ce2aa5d5874566f8f4f77b1eab80b19ede4d1419eafe92eb54;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); + error = mqtt_connect(client); - LOG_D("mqtt connect error is %#x", error); + MQTT_LOG_D("mqtt connect error is %#x", error); //mqtt_set_interceptor_handler(&client,tos_topic_handler); - mqtt_subscribe(&client, "RUAP1R610V/supowang/data", QOS0, tos_topic_handler); + mqtt_subscribe(client, "RUAP1R610V/supowang/data", QOS0, tos_topic_handler); - LOG_D("mqtt subscribe error is %#x", error); + MQTT_LOG_D("mqtt subscribe error is %#x", error); memset(&msg, 0, sizeof(msg)); @@ -77,7 +67,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/LTE_DTU_EC20_SIM7600CE/KEIL/mqtt_client/TencentOS_Tiny.uvoptx b/board/LTE_DTU_EC20_SIM7600CE/KEIL/mqtt_client/TencentOS_Tiny.uvoptx index 50d2d829..b7bf3c8a 100644 --- a/board/LTE_DTU_EC20_SIM7600CE/KEIL/mqtt_client/TencentOS_Tiny.uvoptx +++ b/board/LTE_DTU_EC20_SIM7600CE/KEIL/mqtt_client/TencentOS_Tiny.uvoptx @@ -223,7 +223,7 @@ Application/User - 1 + 0 0 0 0 @@ -1007,7 +1007,7 @@ mqttclient - 0 + 1 0 0 0 @@ -1027,7 +1027,7 @@ mqttclient/mqtt - 0 + 1 0 0 0 @@ -1155,7 +1155,7 @@ mqttclient/salof - 0 + 1 0 0 0 @@ -1223,7 +1223,7 @@ mqttclient/common - 0 + 1 0 0 0 @@ -1234,23 +1234,23 @@ 0 0 0 - ..\..\..\..\components\connectivity\mqttclient\common\list.c - list.c - 0 - 0 - - - 16 - 77 - 1 - 0 - 0 - 0 ..\..\..\..\components\connectivity\mqttclient\common\random.c random.c 0 0 + + 16 + 77 + 1 + 0 + 0 + 0 + ..\..\..\..\components\connectivity\mqttclient\common\mqtt_list.c + mqtt_list.c + 0 + 0 + 16 78 @@ -1258,8 +1258,8 @@ 0 0 0 - ..\..\..\..\components\connectivity\mqttclient\common\error.h - error.h + ..\..\..\..\components\connectivity\mqttclient\common\mqtt_error.h + mqtt_error.h 0 0 @@ -1270,8 +1270,8 @@ 0 0 0 - ..\..\..\..\components\connectivity\mqttclient\common\log.h - log.h + ..\..\..\..\components\connectivity\mqttclient\common\mqtt_log.h + mqtt_log.h 0 0 @@ -1279,7 +1279,7 @@ mqttclient/network - 0 + 1 0 0 0 @@ -1295,17 +1295,41 @@ 0 0 + + 17 + 81 + 1 + 0 + 0 + 0 + ..\..\..\..\components\connectivity\mqttclient\network\nettype_tls.c + nettype_tls.c + 0 + 0 + + + 17 + 82 + 1 + 0 + 0 + 0 + ..\..\..\..\components\connectivity\mqttclient\network\nettype_tcp.c + nettype_tcp.c + 0 + 0 + mqttclient/platform - 0 + 1 0 0 0 18 - 81 + 83 1 0 0 @@ -1317,7 +1341,7 @@ 18 - 82 + 84 1 0 0 @@ -1329,7 +1353,7 @@ 18 - 83 + 85 1 0 0 @@ -1339,30 +1363,6 @@ 0 0 - - 18 - 84 - 1 - 0 - 0 - 0 - ..\..\..\..\components\connectivity\mqttclient\platform\TencentOS-tiny\platform_nettype_tcp.c - platform_nettype_tcp.c - 0 - 0 - - - 18 - 85 - 1 - 0 - 0 - 0 - ..\..\..\..\components\connectivity\mqttclient\platform\TencentOS-tiny\platform_nettype_tls.c - platform_nettype_tls.c - 0 - 0 - 18 86 @@ -1391,7 +1391,7 @@ mqttclient/config - 0 + 1 0 0 0 diff --git a/board/LTE_DTU_EC20_SIM7600CE/KEIL/mqtt_client/TencentOS_Tiny.uvprojx b/board/LTE_DTU_EC20_SIM7600CE/KEIL/mqtt_client/TencentOS_Tiny.uvprojx index ac7fcea2..5ac9bf0b 100644 --- a/board/LTE_DTU_EC20_SIM7600CE/KEIL/mqtt_client/TencentOS_Tiny.uvprojx +++ b/board/LTE_DTU_EC20_SIM7600CE/KEIL/mqtt_client/TencentOS_Tiny.uvprojx @@ -16,7 +16,7 @@ STM32F103RB STMicroelectronics - Keil.STM32F1xx_DFP.2.2.0 + Keil.STM32F1xx_DFP.2.3.0 http://www.keil.com/pack/ IRAM(0x20000000-0x20004FFF) IROM(0x8000000-0x801FFFF) CLOCK(8000000) CPUTYPE("Cortex-M3") @@ -832,25 +832,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_error.h 5 - ..\..\..\..\components\connectivity\mqttclient\common\log.h + ..\..\..\..\components\connectivity\mqttclient\common\mqtt_error.h + + + mqtt_log.h + 5 + ..\..\..\..\components\connectivity\mqttclient\common\mqtt_log.h @@ -862,6 +862,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 + @@ -882,16 +892,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/LTE_DTU_EC20_SIM7600CE/TOS_CONFIG/mqtt_config.h b/board/LTE_DTU_EC20_SIM7600CE/TOS_CONFIG/mqtt_config.h index c2caeb53..2e953d69 100644 --- a/board/LTE_DTU_EC20_SIM7600CE/TOS_CONFIG/mqtt_config.h +++ b/board/LTE_DTU_EC20_SIM7600CE/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_ */