From: d15521469561 <1731678236@qq.com> Date: Mon, 27 Apr 2026 03:09:33 +0000 (+0800) Subject: 修复wifi密码crc32校验为大端序 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=4d5654efae5d8f958aed2e7995b392aeffcce2b5;p=mirrors%2Fmqtt_wglt_iot.git 修复wifi密码crc32校验为大端序 --- diff --git a/main/project_common.c b/main/project_common.c index 6b5cc7c..66d526d 100644 --- a/main/project_common.c +++ b/main/project_common.c @@ -414,8 +414,13 @@ void Ble_Pairing_Handle(uint8_t *data ,uint16_t len, uint8_t host_type) { wifi_pwd_len = 64; } - - if(Crc32_JAMCRC_Cal(&data[38], 64) != *(uint32_t*)&data[102]) // 校验密文完整性 + // 要大端序 + uint32_t recv_crc = ((uint32_t)data[102] << 24) | + ((uint32_t)data[103] << 16) | + ((uint32_t)data[104] << 8) | + (uint32_t)data[105]; + + if(Crc32_JAMCRC_Cal(&data[38], 64) != recv_crc) // 校验密文完整性 { net_pairing_reply.send_flag = 1; net_pairing_reply.len = 3; diff --git a/main/project_common.h b/main/project_common.h index 8deb0f5..e2fb3a3 100644 --- a/main/project_common.h +++ b/main/project_common.h @@ -62,7 +62,7 @@ // 最终对外版本 #define FW_VERSION (FW_VERSION_B) // 固件版本 //10.22 // 固件版本 //10.22 // 固件版本 //10.22 // 固件版本 //0A00 10.00 10.21 -#define BUILD_VERSION (0x0008) // 编译测试版本 +#define BUILD_VERSION (0x0009) // 编译测试版本 #define DEVICE_VID (0x36E6) // 设备厂商代码 #define DEVICE_PID (0xEC01) // 设备型号代码 #define LWIP_LOCAL_HOSTNAME "PXN-Device" // WIFI本地主机名称 diff --git a/main/user_flash.c b/main/user_flash.c index 301f1ba..75679c9 100644 --- a/main/user_flash.c +++ b/main/user_flash.c @@ -15,7 +15,7 @@ void User_Flash_Check(void) //寻找分区表 partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_ANY, PARA_FLASH_NAME); assert(partition != NULL); - // User_Erase_Nimble_NetWork_Infor(); + User_Erase_Nimble_NetWork_Infor(); //读取flash数据到common_storage if(User_Flash_Read_Check(UF_OFFSET_USER_CONFIG_INFO_ADDR, UF_OFFSET_USER_CONFIG_INFO_FLAG, &common_storage.net_info, sizeof(NET_INFO_T)) != ESP_OK) diff --git a/main/user_mqtt.c b/main/user_mqtt.c index f22ee59..0fc93a7 100644 --- a/main/user_mqtt.c +++ b/main/user_mqtt.c @@ -258,57 +258,8 @@ static esp_err_t _http_event_handler(esp_http_client_event_t *evt) } void Mqtt_Get_Key_Led_Color(uint8_t *color_data,uint16_t color_len) { - esp_http_client_config_t http_config = - { - .event_handler = _http_event_handler, - .disable_auto_redirect = true, - .keep_alive_enable = true, - }; - const char path[] = "/iot/device/"; - memset(url, 0x00, sizeof(url)); - //PATH 10 255-10 - // if(common_setting.net_pairing_info.http_url_length < (sizeof(url) - sizeof(path))){ - // memcpy(url, common_setting.net_pairing_info.http_url, sizeof(url)-common_setting.net_pairing_info.http_url_length); - // memcpy(&url[common_setting.net_pairing_info.http_url_length], path, strlen(path)); - // } - snprintf(url,sizeof(url)-1,"%s",path); - esp_http_client_handle_t http_client = NULL; - http_config.url = url; - http_client = esp_http_client_init(&http_config); - if(http_client == NULL) - { - - ESP_LOGI(MQTT_TAG, "%s http_config.url = %s",__func__, http_config.url); - - - } - esp_http_client_set_header(http_client, "Authorization", (const char*)common_setting.net_pairing_info.http_token); - esp_http_client_set_method(http_client, HTTP_METHOD_PUT); - esp_http_client_set_header(http_client, "Content-Type", "application/json"); - - esp_http_client_set_post_field(http_client, post_data, strlen(post_data)); - esp_err_t err = esp_http_client_perform(http_client); - int result = 0; - if (err == ESP_OK) - { - int status_code = esp_http_client_get_status_code(http_client); - int read_len = esp_http_client_get_content_length(http_client); - if(status_code == 200) - { - result = 1; - } - else - { - result = 2; - } - ESP_LOGI(MQTT_TAG, "PUT Status = %d, content_length = %d", status_code, read_len); - } - else - { - result = 2; - - } - + return; + // f2 0d 84 7f 01 05 03 00 36 34 30 30 41 30 80 0105 03 00 34 36 43 33 44 43 81 01 05 03 00 46 41 35 35 30 30 // 82 01 05 03 00 46 46 30 30 30 30 83 01 05 03 00 30 30 46 46 30 30 84 01 05 03 00 30 30 30 30 46 46 // 85 01 05 03 00 46 30 35 41 36 3986 01 05 03 00 38 32 46 41 41 46 87 01 05 03 0041 46 30 30 38 43 @@ -414,7 +365,7 @@ void Mqtt_Get_Key_Led_Color(uint8_t *color_data,uint16_t color_len) char *json_str = cJSON_PrintUnformatted(root); cJSON_Delete(root); uint16_t json_str_len = strlen(json_str); - if(json_str_len == 0 || json_str_len >= MQTT_SEND_DATA_BUF_SIZE) + if(json_str_len == 0 || json_str_len >= MQTT_SEND_RECV_DATA_BUF_SIZE) { ESP_LOGI(MQTT_TAG, "key led is large:%s %d\n", json_str,strlen(json_str)); if(json_str != NULL) @@ -557,14 +508,14 @@ void Mqtt_Send_Mcu_Info(void) cJSON_AddStringToObject(root, "serial_id", (char *)common_storage.net_info.serial_number); cJSON_AddNumberToObject(root, "connected_platform", 2); cJSON_AddNumberToObject(root, "power_on", 0); - cJSON *pRoot = cJSON_CreateObject(); - // cJSON_AddItemToObject(root,""thingsModelValue": "string","); - if(pRoot == NULL) - { - cJSON_Delete(root); - return; - } - cJSON_AddItemToObject(root,"thingsModelValue",pRoot); + // cJSON *pRoot = cJSON_CreateObject(); + // // cJSON_AddItemToObject(root,""thingsModelValue": "string","); + // if(pRoot == NULL) + // { + // cJSON_Delete(root); + // return; + // } + // cJSON_AddItemToObject(root,"thingsModelValue",pRoot); // 生成压缩格式JSON(不带换行,HTTP专用) @@ -575,7 +526,7 @@ void Mqtt_Send_Mcu_Info(void) if (post_data == NULL) return; - if(strlen(post_data) >= MQTT_SEND_DATA_BUF_SIZE) + if(strlen(post_data) >= MQTT_SEND_RECV_DATA_BUF_SIZE) { ESP_LOGI(MQTT_TAG, "len large %d", strlen(post_data)); free(post_data); @@ -771,6 +722,8 @@ void Mqtt_Init_Task(void) // } mqtt_recv_queue_handle = xQueueCreateStatic(MQTT_RECV_QUEUE_LENGTH, MQTT_RECV_QUEUE_ITEM_SIZE, mqtt_recv_queue_storage, &mqtt_recv_queue_buffer); mqtt_send_queue_handle = xQueueCreateStatic(MQTT_SEND_QUEUE_LENGTH, MQTT_SEND_QUEUE_ITEM_SIZE, mqtt_send_queue_storage, &mqtt_send_queue_buffer); + + mqtt_connect_task_handler = xTaskCreateStatic(Mqtt_Init_Task_Cb, "mqtt_task", MQTT_CONNECT_TASK_STACK, NULL, 2, mqtt_connect_task_stack, &mqtt_connect_task_tcb); } diff --git a/main/user_mqtt.h b/main/user_mqtt.h index 0cf22b0..978671d 100644 --- a/main/user_mqtt.h +++ b/main/user_mqtt.h @@ -4,14 +4,16 @@ #define ENABLE_MQTT_FUNC 1 #if ENABLE_MQTT_FUNC +#define MQTT_SEND_RECV_DATA_BUF_SIZE 512 + #define MQTT_TOPIC "sdk/test/python" #define MQTT_TOPIC_LEN 64 #define MQTT_MAX_TRY_CONNECT_TIME 10 -#define MQTT_DATA_BUF_SIZE 256 +#define MQTT_DATA_BUF_SIZE MQTT_SEND_RECV_DATA_BUF_SIZE #define MQTT_RECV_QUEUE_LENGTH 4 #define MQTT_SEND_QUEUE_LENGTH 4 -#define MQTT_SEND_MSG_MAX_LEN 512 +#define MQTT_SEND_MSG_MAX_LEN MQTT_SEND_RECV_DATA_BUF_SIZE #define MQTT_PUT_URL_LEN 255 @@ -25,16 +27,16 @@ typedef struct { } mqtt_recv_msg_t; // 发送消息结构体 -#define MQTT_SEND_DATA_BUF_SIZE 1024 + typedef struct { char topic[MQTT_TOPIC_LEN+1]; - char data[MQTT_SEND_DATA_BUF_SIZE]; + char data[MQTT_SEND_RECV_DATA_BUF_SIZE]; } mqtt_send_msg_t; #define MQTT_RECV_QUEUE_ITEM_SIZE sizeof(mqtt_recv_msg_t) #define MQTT_SEND_QUEUE_ITEM_SIZE sizeof(mqtt_send_msg_t) -#define MQTT_CONNECT_TASK_STACK (2*1024) +#define MQTT_CONNECT_TASK_STACK (4*1024) extern TaskHandle_t mqtt_connect_task_handler; extern StackType_t mqtt_connect_task_stack[MQTT_CONNECT_TASK_STACK]; extern StaticTask_t mqtt_connect_task_tcb;