memcpy(common_setting.mcu_info.product_name, &data[12], name_len);
common_setting.mcu_info.product_name[name_len] = '\0'; // 确保字符串结尾
common_setting.mcu_info.product_name_len = name_len;
- common_setting.mcu_info_got_flag = 1;
+ // common_setting.mcu_info_got_flag = 1;
net_pairing_reply.content[0]=0x01;
}
uint8_t parse_done = 0;
char wifi_ssid[32+1] = {0};
char wifi_pwd[64+1] = {0};
-
- if (len < 106)
+
+ uint16_t data_total_len = *(uint16_t*)&data[2];
+ if (len < 106 || data_total_len != 102)
{
ESP_LOGW(COMMON_TAG, "wifi conn data too short (%u)\n",len);
net_pairing_reply.send_flag = 1;
net_pairing_reply.content[2] = data[5];
break;
}
-
size_t max_ssid_src = (len > 6) ? len - 6 : 0;
size_t max_pwd_src = (len > 38) ? len - 38 : 0;
size_t wifi_ssid_len = strnlen((const char*)&data[6], max_ssid_src);
else
{
ESP_LOGI(COMMON_TAG, "wifi pair wrong\n");
+ net_pairing_reply.send_flag = 1;
+ net_pairing_reply.len = 3;
+ net_pairing_reply.content[0] = 0x08;
+ net_pairing_reply.content[1] = data[4];
+ net_pairing_reply.content[2] = data[5];
}
}
else
ESP_LOGW(COMMON_TAG, "net pairing 0x16 len too small (%u)", len);
net_pairing_reply.send_flag = 1;
net_pairing_reply.len = 1;
- net_pairing_reply.content[0] = 0x10;
+ net_pairing_reply.content[0] |=0x10;
break;
}
ESP_LOGW(COMMON_TAG, "net pairing 0x16 too big (%u > %u)\n", packet_bytes, len - 13);
net_pairing_reply.send_flag = 1;
net_pairing_reply.len = 1;
- net_pairing_reply.content[0] = 0x10;
+ net_pairing_reply.content[0]|=0x10;
break;
}
-
+ // 2*16+2 =34-9=25 16*1+9 = 25
+ //ff 16 22 00 19 00 c4 b2 01 00 00 19 68 74 74 70 3a 2f 2f 31 39 32 2e 31 36 38 2e 36 36 2e 38 35 3a 38 30 38 39 59
net_pairing_reply.send_flag = 1;
net_pairing_reply.len = 9;
memcpy(net_pairing_reply.content, &data[4], 9);
{
// CRC
uint16_t calc_crc = Crc16_Modbus_Cal((uint8_t*)common_setting.net_pairing_info.http_url, total_len);
- uint16_t packet_crc = (data[7] << 8) | data[8];
+ uint16_t packet_crc = (data[8] << 8) | data[7];//高在后 低在前
ESP_LOGI(COMMON_TAG, "http url: %s (len=%u)\n", common_setting.net_pairing_info.http_url, total_len);
//上一次已经接收完成了一个完整的http url包了,但校验失败了
ESP_LOGI(COMMON_TAG, "http data error\n");
http_end=0;
- memset(common_setting.net_pairing_info.http_url, 0x00, HTTP_URL_MAX_LEN);
+ memset(common_setting.net_pairing_info.http_url, 0x00, HTTP_URL_MAX_LEN+1);
net_pairing_reply.content[5] |= 0x20;
break;//提前退出,等待APP重新发送一个新的http url包过来
}
{
http_end=0;
+ net_pairing_reply.content[5] |= 0x00;
common_setting.net_pairing_info.http_url_length = total_len;
common_setting.net_pairing_info.http_url_flag = 1;
- ESP_LOGI(COMMON_TAG, "http crc success: %s\n", common_setting.net_pairing_info.http_url);
+ ESP_LOGI(COMMON_TAG, "http crc success: %s net_pairing_reply.content[5]:%02x\n", common_setting.net_pairing_info.http_url,net_pairing_reply.content[5]);
}
else
{
http_end=1;
- memset(common_setting.net_pairing_info.http_url, 0x00, HTTP_URL_MAX_LEN);
+ memset(common_setting.net_pairing_info.http_url, 0x00, HTTP_URL_MAX_LEN+1);
net_pairing_reply.content[5] |= 0x20;
common_setting.net_pairing_info.http_url_flag = 0;
- ESP_LOGI(COMMON_TAG, "http CRC: =%04x recv=%04x\n", calc_crc, packet_crc);
+ ESP_LOGI(COMMON_TAG, "http CRC: =%04x recv=%04x 0x%02x\n", calc_crc, packet_crc,net_pairing_reply.content[5]);
}
}
}
{
//
uint16_t calc_crc = Crc16_Modbus_Cal((uint8_t*)common_setting.net_pairing_info.http_token, total_len);
- uint16_t packet_crc = (data[7] << 8) | data[8];
+ uint16_t packet_crc = (data[8] << 8) | data[7];
ESP_LOGI(COMMON_TAG, "correct token: %s (len=%u)\n", common_setting.net_pairing_info.http_token, total_len);
//本次结束后校验出错了,然后又下发最后一包不完整的数据
if(packet_crc == calc_crc)
{
token_end=0;
+ net_pairing_reply.content[5] |= 0x00;
common_setting.net_pairing_info.http_token_length = total_len;
common_setting.net_pairing_info.http_token_flag = 1;
ESP_LOGI(COMMON_TAG, "tokencrc success %s",common_setting.net_pairing_info.http_token);
else if(data[4] == 2) // user_id
{
- // ESP_LOGI(COMMON_TAG, "net pairing 0x16 user_id overflow: start=%u packet=%u", start_b);
+ // ESP_LOGI(COMMON_TAG, "net pairing 0x16 overflow: start=%u packet=%u", start_b);
// if(start_byte >= sizeof(int) || packet_bytes > sizeof(int) || (size_t)start_byte + packet_bytes > sizeof(int))
// {
// ESP_LOGI(COMMON_TAG, "net pairing 0x16 user_id overflow: start=%u packet=%u", start_byte, packet_bytes);
// }
if(start_byte == 0)
{
- common_setting.net_pairing_info.user_id=0;
+ // common_setting.net_pairing_info.user_id=0;
+ memset(common_setting.net_pairing_info.user_id,0x00,sizeof(common_setting.net_pairing_info.user_id));
+ }
+ uint16_t copy_len = (packet_bytes < (USER_ID_MAX_LEN - start_byte)) ? packet_bytes : (USER_ID_MAX_LEN - start_byte);
+ if(total_len > USER_ID_MAX_LEN)
+ {
+ total_len=USER_ID_MAX_LEN;
+ // 类型错误
+ net_pairing_reply.content[5] |= 0x10;
+ ESP_LOGI(COMMON_TAG, "net pair info type err\n");
+ break;
}
- uint16_t copy_len = (packet_bytes < (sizeof(int) - start_byte)) ? packet_bytes : (sizeof(int) - start_byte);
- memcpy(&common_setting.net_pairing_info.user_id, &data[13], copy_len);
+
+ memcpy(common_setting.net_pairing_info.user_id, &data[13], total_len);
+ common_setting.net_pairing_info.user_id[total_len]='\0';
if(data[9] == 1)
{
- if(total_len > sizeof(int))
+ if(total_len > USER_ID_MAX_LEN)
{
- total_len = sizeof(int);
+ total_len = USER_ID_MAX_LEN;
}
- uint16_t calc_crc = Crc16_Modbus_Cal((uint8_t*)&common_setting.net_pairing_info.user_id, total_len);
- uint16_t packet_crc = (data[7] << 8) | data[8];
+ uint16_t calc_crc = Crc16_Modbus_Cal((uint8_t*)common_setting.net_pairing_info.user_id, total_len);
+ uint16_t packet_crc = (data[8] << 8) | data[7];
- ESP_LOGI(COMMON_TAG, "user_id: %08x\n", (unsigned int)common_setting.net_pairing_info.user_id);
+ ESP_LOGI(COMMON_TAG, "user_id: %s %d total_len:%d\n",common_setting.net_pairing_info.user_id,copy_len,total_len);
//本次结束后校验出错了,然后又下发最后一包不完整的数据
if(packet_crc == calc_crc)
{
common_setting.net_pairing_info.user_id_flag = 1;
- ESP_LOGI(COMMON_TAG, "user_id: %08x\n", (unsigned int)common_setting.net_pairing_info.user_id);
+ net_pairing_reply.content[5] |= 0x00;
+ ESP_LOGI(COMMON_TAG, "user_id: %s\n",common_setting.net_pairing_info.user_id);
}
else
{
- common_setting.net_pairing_info.user_id=0;
+ // common_setting.net_pairing_info.user_id=0;
+ memset(common_setting.net_pairing_info.user_id,0,sizeof(common_setting.net_pairing_info.user_id));
common_setting.net_pairing_info.user_id_flag = 0;
// 校验失败
net_pairing_reply.content[5] |= 0x20;
{
if(data[4] == 0) // http配网服务器地址
{
- memset(common_setting.net_pairing_info.http_url, 0x00, NET_PAIRING_INFO_MAX_LEN);
+ memset(common_setting.net_pairing_info.http_url, 0x00, HTTP_URL_MAX_LEN+1);
}
else if(data[4] == 1) // token
{
}
else if(data[4] == 2) // user_id
{
- common_setting.net_pairing_info.user_id = 0;
+ // common_setting.net_pairing_info.user_id = 0;
+ memset(common_setting.net_pairing_info.user_id, 0x00, sizeof(common_setting.net_pairing_info.user_id));
}
// 失败
net_pairing_reply.content[5] |= 0x10;
static uint8_t mqtt_init_task_flag = 0;
static uint8_t mqtt_send_data_count = 0;
static uint8_t mqtt_init_flag = 0;
-static char topic_str[64]={"/property/post"};
-#define MQTT_USER_DEFAULT_TOPIC 1
+static char topic_str[64]={0};
+#define MQTT_USER_DEFAULT_TOPIC 0
static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data)
{
ESP_LOGD(MQTT_TAG, "Event dispatched from event loop base=%s, event_id=%" PRIi32, base, event_id);
snprintf(topic_str,sizeof(topic_str),"%s",MQTT_TOPIC);
msg_id = esp_mqtt_client_subscribe(mqtt_client, topic_str, 0);
#else
- snprintf(topic_str,sizeof(topic_str),"%04X/%s/property/post",common_setting.mcu_info.pid,(char *)common_storage.net_info.serial_number);
+ snprintf(topic_str,sizeof(topic_str),"topic/%s/%04X/property/post",(char *)common_storage.net_info.serial_number,common_setting.mcu_info.pid);
msg_id = esp_mqtt_client_subscribe(mqtt_client, topic_str, 0);
#endif
ESP_LOGI(MQTT_TAG, "send subscribe msg_id=%d topic_str=%s", msg_id,topic_str);
return ESP_FAIL;
}
- if(common_storage.net_info.mqtt_url_len==0)
+ if(common_storage.net_info.mqtt_url_len==0 && common_setting.mcu_info.pid == 0x0000)
{
ESP_LOGI(MQTT_TAG, "mqtt_sub_url == 0");
return ESP_FAIL;
common_setting.mqtt_cfg.broker.verification.certificate = (const char *)common_storage.ssl_cert[SSL_SERVER_CRT].content;
common_setting.mqtt_cfg.credentials.authentication.certificate = (const char *)common_storage.ssl_cert[SSL_CLIENT_CRT].content;
common_setting.mqtt_cfg.credentials.authentication.key = (const char *)common_storage.ssl_cert[SSL_CLIENT_KEY].content;
+ char pid_str[10]={0};
+ sprintf(pid_str,"%04X",common_setting.mcu_info.pid);
#if MQTT_USER_DEFAULT_TOPIC
common_setting.mqtt_cfg.credentials.client_id = "basicPubSub";
#else
- common_setting.mqtt_cfg.credentials.client_id = (const char *)common_storage.net_info.serial_number;
+ common_setting.mqtt_cfg.credentials.client_id = (const char *)pid_str;
#endif
- ESP_LOGI(MQTT_TAG, "Mqtt init %s",(char *)common_storage.net_info.serial_number);
+ ESP_LOGI(MQTT_TAG, "Mqtt init %s",pid_str);
common_setting.mqtt_client_handle = esp_mqtt_client_init(&common_setting.mqtt_cfg);
if(common_setting.mqtt_client_handle == NULL){
ESP_LOGI(MQTT_TAG, "client_handle null\n");
return 0;
}
// MQTT发送按键灯颜色
+static esp_err_t _http_event_handler(esp_http_client_event_t *evt)
+{
+ switch (evt->event_id) {
+ case HTTP_EVENT_ERROR:
+ // ESP_LOGI(HTTP_TAG, "HTTP_EVENT_ERROR");
+ break;
+ case HTTP_EVENT_ON_CONNECTED:
+ // ESP_LOGI(HTTP_TAG, "HTTP_EVENT_ON_CONNECTED");
+ break;
+ case HTTP_EVENT_HEADER_SENT:
+ // ESP_LOGI(HTTP_TAG, "HTTP_EVENT_HEADER_SENT");
+ break;
+ case HTTP_EVENT_ON_HEADER:
+ // ESP_LOGI(HTTP_TAG, "HTTP_EVENT_ON_HEADER, key=%s, value=%s", evt->header_key, evt->header_value);
+ break;
+ case HTTP_EVENT_ON_DATA:
+ // ESP_LOGI(HTTP_TAG, "HTTP_EVENT_ON_DATA, len=%d", evt->data_len);
+ // if (!esp_http_client_is_chunked_response(evt->client))
+ // {
+ // printf("%.*s", evt->data_len, (char*)evt->data);
+ // uint8_t *data = (uint8_t*)evt->data;
+ // for(uint32_t i=0;i<evt->data_len;i++)
+ // {
+ // printf("%02x ", *(data++));
+ // }
+ // printf("\n");
+ // }
+ break;
+ case HTTP_EVENT_ON_FINISH:
+ // ESP_LOGI(HTTP_TAG, "HTTP_EVENT_ON_FINISH");
+ break;
+ case HTTP_EVENT_DISCONNECTED:
+ // ESP_LOGI(HTTP_TAG, "HTTP_EVENT_DISCONNECTED");
+ break;
+ case HTTP_EVENT_REDIRECT:
+ // ESP_LOGI(HTTP_TAG, "HTTP_EVENT_REDIRECT");
+ break;
+ }
+ return ESP_OK;
+}
void Mqtt_Get_Key_Led_Color(uint8_t *color_data,uint16_t color_len)
{
- return;
- ESP_LOG_BUFFER_HEX(MQTT_TAG, color_data, 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;
+
+ }
+
+ // 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
+ // 88 01 05 03 00 46 30 33 43 30 30 89 01 05 03 00 46 46 42 34 30 30 8a 01 05 03 00 39 42 46 46 35 30
+ // 22
uint8_t uart_reply_data[1]={0};
//没有订阅成 没有连接wifi 没有连接mqtt 直接返回NULL
- if(!Mqtt_Get_Connect_Flag() || color_data == NULL || color_len == 0 || color_len < 8)
+ // if(!Mqtt_Get_Connect_Flag() || color_data == NULL || color_len == 0 || color_len < 8)
+ // {
+ // uart_reply_data[0] = REPLY_STATUS_FAIL;
+ // Uart_Reply_Send(COMMON_UART_GET_KEY_COLOR_CMD,uart_reply_data, sizeof(uart_reply_data), HOST_TYPE_UART);
+ // ESP_LOGI(MQTT_TAG, "Mqtt_Get_Key_Led_Color!!!%d\n",color_len);
+ // // ESP_LOG_BUFFER_HEX(MQTT_TAG, color_data, color_len);
+ // return;
+ // }
+ char pid_str[6] = {0};
+ char vid_str[6] = {0};
+ char wifi_soc[15] = {"Unknown"};
+
+ // PID、VID 大写十六进制格式
+ snprintf(pid_str, sizeof(pid_str), "%04X", common_setting.mcu_info.pid);
+ snprintf(vid_str, sizeof(vid_str), "%04X", common_setting.mcu_info.vid);
+
+ // 获取芯片型号
+ uint8_t chip_len = 0;
+ get_chip_info(wifi_soc, &chip_len);
+ if (chip_len == 0) {
+ strcpy(wifi_soc, "Unknown");
+ }
+
+ // 版本号格式化 0x0015 → V0021
+ char fw_ver[8] = {0}, wifi_ver[8] = {0};
+ snprintf(fw_ver, sizeof(fw_ver), "%04u", common_setting.mcu_info.fw_version);
+ snprintf(wifi_ver, sizeof(wifi_ver), "%04u", (unsigned int)FW_VERSION);
+ if(FW_VERSION > 9999)
{
- uart_reply_data[0] = REPLY_STATUS_FAIL;
- Uart_Reply_Send(COMMON_UART_GET_KEY_COLOR_CMD,uart_reply_data, sizeof(uart_reply_data), HOST_TYPE_UART);
- ESP_LOGI(MQTT_TAG, "Mqtt_Get_Key_Led_Color!!!%d\n",color_len);
- // ESP_LOG_BUFFER_HEX(MQTT_TAG, color_data, color_len);
- return;
+
+ snprintf(wifi_ver, sizeof(wifi_ver), "%s","9999");
}
-
- //key==dpid value==color 12*3=36
- // "383":"FF0000",
-
- char key[8]={0};//65535
- char value[10]={0};
+ // ===================== 构建正确的 JSON =====================
cJSON *root = cJSON_CreateObject();
- if(root==NULL)
+ if (root == NULL) return;
+
+
+ // 把设备信息加到里面
+ cJSON_AddStringToObject(root, "pid", pid_str);
+ cJSON_AddStringToObject(root, "vid", vid_str);
+ cJSON_AddStringToObject(root, "wifi_soc", wifi_soc);
+ cJSON_AddStringToObject(root, "fw_version", fw_ver);
+ cJSON_AddStringToObject(root, "wifi_version", wifi_ver);
+ 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)
{
- ESP_LOGI(MQTT_TAG, "is not storage\n");
- uart_reply_data[0] = REPLY_STATUS_FAIL;
- Uart_Reply_Send(COMMON_UART_GET_KEY_COLOR_CMD,uart_reply_data, sizeof(uart_reply_data), HOST_TYPE_UART);
+ if(root != NULL)
+ {
+ cJSON_Delete(root);
+ }
return;
}
- for(int i=0;i<color_len/8;i++)
+ cJSON_AddItemToObject(root,"thingsModelValue",pRoot);
+
+
+ char key[8]={0};//65535
+ uint16_t len = 0;
+
+ char value[32]={0};//8个字节也就是16字符 ff ff ff ff ff ff ff ff
+
+ for(int i=0;i<color_len/11;i++)
{
- uint8_t dpid_h = color_data[i*8 + 0]; // 高8位 0x01
- uint8_t dpid_l = color_data[i*8 + 1]; // 低8位 0x7F
+ uint8_t dpid_h = color_data[i*11 + 0]; // 高8位 0x01
+ uint8_t dpid_l = color_data[i*11 + 1]; // 低8位 0x7F
uint16_t dpid = (dpid_h << 8) | dpid_l; // 0x017F = 383
-
+ //17
snprintf(key,sizeof(key),"%d", dpid);
if(color_data[i*8+2] == 5) //数据类型
{
//
}
- uint8_t d_h = color_data[i*8 + 3]; // 高8位 0x7f
- uint8_t d_l = color_data[i*8 + 4]; // 低8位 0x01
+ uint8_t d_h = color_data[i*11 + 3]; // 高8位 0x7f
+ uint8_t d_l = color_data[i*11 + 4]; // 低8位 0x01
- uint16_t data_len = d_l << 8 |d_h;
+ uint16_t data_len = (d_h << 8) |d_l;
+ ESP_LOGI(MQTT_TAG, "Mqtt_Get_Key_Led_Color!!!%d\n",data_len);
// ESP_LOGI(MQTT_TAG,"COLOR LEN:%d",data_len);
- // uint8_t r = color_data[i*8 + 5];
+ // uint8_t r = color_data[i*8 + 5]; 5 6 7 8 9 10
// uint8_t g = color_data[i*8 + 6];
// uint8_t b = color_data[i*8 + 7];
- // memcpy(value,color_data[]);
- // snprintf(value,sizeof(value),"%02X%02X%02X",r,g,b);
- cJSON_AddStringToObject(root, key, value);
+ if(data_len > 32-1)
+ {
+ data_len=32-1;
+ }
+ memset(value,0,sizeof(value));
+ memcpy(value,&color_data[i*11+5],data_len);
+ value[data_len]='\0';
+ snprintf(key,sizeof(key),"%d",dpid);
+ cJSON_AddStringToObject(pRoot, key, value);
}
char *json_str = cJSON_PrintUnformatted(root);
cJSON_Delete(root);
mqtt_send_msg_t send_msg={0};
memcpy(send_msg.data,json_str,json_str_len);
ESP_LOGI(MQTT_TAG, "key led:%s\n", json_str);
+
+
+ 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/";
+ char url[128] = {0};
+ 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, json_str, strlen(json_str));
+ 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;
+
+ }
free(json_str);
json_str = NULL;
memcpy(send_msg.topic, topic_str, strlen(topic_str));
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);
+
+
// 生成压缩格式JSON(不带换行,HTTP专用)
char *post_data = cJSON_Print(root);
// char *post_data = cJSON_PrintUnformatted(root);