|
@ -26,6 +26,8 @@ |
|
|
#include "nvs_flash.h" |
|
|
#include "nvs_flash.h" |
|
|
#include "esp_bt.h" |
|
|
#include "esp_bt.h" |
|
|
#include "driver/timer.h" |
|
|
#include "driver/timer.h" |
|
|
|
|
|
#include "cJSON.h" |
|
|
|
|
|
#include "cJSON_Utils.h" |
|
|
|
|
|
|
|
|
#include "esp_gap_ble_api.h" |
|
|
#include "esp_gap_ble_api.h" |
|
|
#include "esp_gatts_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) |
|
|
if ((bluetooth_rx_buffer_len + param->write.len) > profile_b_buffer_size) |
|
|
{ |
|
|
{ |
|
|
ESP_LOGW(GATTS_TAG, "Array out of bounds"); |
|
|
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); |
|
|
example_write_event_env(gatts_if, &b_prepare_write_env, param); |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
timer_set_pause_and_counter_zero(TIMER_GROUP_0, TIMER_0); |
|
|
timer_set_pause_and_counter_zero(TIMER_GROUP_0, TIMER_0); |
|
|
timer_start(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() |
|
|
void bluetooth_gatts_try_process_data() |
|
|
{ |
|
|
{ |
|
|
|
|
|
cJSON *json_tmp; |
|
|
|
|
|
cJSON *ch; |
|
|
|
|
|
uint8_t json_temp_size = 0; |
|
|
//接收完毕 |
|
|
//接收完毕 |
|
|
if (bluetooth_rx_buffer_processing) |
|
|
if (bluetooth_rx_buffer_processing) |
|
|
{ |
|
|
{ |
|
@ -907,6 +913,52 @@ void bluetooth_gatts_try_process_data() |
|
|
ESP_LOGI(GATTS_TAG, "%s", &bluetooth_rx_buffer[0]); |
|
|
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置0 |
|
|
buffer_all_init(); |
|
|
buffer_all_init(); |
|
|