}
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
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)
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专用)
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);
// }
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);
}
#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
} 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;