From 2b59665f2bea173926ad5c919ff70cef21b475f4 Mon Sep 17 00:00:00 2001 From: zwsd Date: Sat, 9 Jul 2022 15:55:44 +0800 Subject: [PATCH] bugfixed --- main/gatts_demo.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/main/gatts_demo.c b/main/gatts_demo.c index 84042f6..280d40b 100644 --- a/main/gatts_demo.c +++ b/main/gatts_demo.c @@ -26,6 +26,8 @@ #include "nvs_flash.h" #include "esp_bt.h" #include "driver/timer.h" +#include "cJSON.h" +#include "cJSON_Utils.h" #include "esp_gap_ble_api.h" #include "esp_gatts_api.h" @@ -619,10 +621,11 @@ static void gatts_profile_b_event_handler(esp_gatts_cb_event_t event, esp_gatt_i if ((bluetooth_rx_buffer_len + param->write.len) > profile_b_buffer_size) { ESP_LOGW(GATTS_TAG, "Array out of bounds"); + timer_set_counter_value(TIMER_GROUP_0, TIMER_0, 0); example_write_event_env(gatts_if, &b_prepare_write_env, param); break; } - + timer_set_pause_and_counter_zero(TIMER_GROUP_0, TIMER_0); timer_start(TIMER_GROUP_0, TIMER_0); @@ -898,6 +901,9 @@ void app_main(void) void bluetooth_gatts_try_process_data() { + cJSON *json_tmp; + cJSON *ch; + uint8_t json_temp_size = 0; //接收完毕 if (bluetooth_rx_buffer_processing) { @@ -907,6 +913,52 @@ void bluetooth_gatts_try_process_data() ESP_LOGI(GATTS_TAG, "%s", &bluetooth_rx_buffer[0]); //处理数据 + json_tmp = cJSON_Parse(&bluetooth_rx_buffer[0]); + + //打印json_temp + ch = json_tmp->child; + for (int i = 0; i < json_temp_size; i++) + { + ESP_LOGI("JSON", "type:%d", ch->type); + if (ch->type == cJSON_Invalid) + { + } + + if (ch->type == cJSON_False) + { + } + + if (ch->type == cJSON_True) + { + } + + if (ch->type == cJSON_NULL) + { + } + + if (ch->type == cJSON_Number) + { + ESP_LOGI("JSON NUMBER", "name:%s ,value :%d", ch->string, ch->valueint); + } + + if (ch->type == cJSON_String) + { + ESP_LOGI("JSON STRING", "name:%s ,value :%s", ch->string, ch->valuestring); + } + + if (ch->type == cJSON_Array) + { + } + + if (ch->type == cJSON_Object) + { + } + + if (ch->type == cJSON_Raw) + { + } + ch = ch->next; + } // buffer置0 buffer_all_init();