Merge branch 'bugfix/example_blufi_fix_the_send_ble_before_connect_bug' into 'master'

example/blufi: Fix the wrong wifi storage mode and check if ble is connected before sending a ble message.

Closes BCI-120

See merge request espressif/esp-idf!6708
This commit is contained in:
Jiang Jiang Jian 2019-11-18 14:21:40 +08:00
commit 79f578ca41

View File

@ -86,6 +86,7 @@ const int CONNECTED_BIT = BIT0;
/* store the station info for send back to phone */
static bool gl_sta_connected = false;
static bool ble_is_connected = false;
static uint8_t gl_sta_bssid[6];
static uint8_t gl_sta_ssid[32];
static int gl_sta_ssid_len;
@ -111,7 +112,11 @@ static void ip_event_handler(void* arg, esp_event_base_t event_base,
info.sta_bssid_set = true;
info.sta_ssid = gl_sta_ssid;
info.sta_ssid_len = gl_sta_ssid_len;
if (ble_is_connected == true) {
esp_blufi_send_wifi_conn_report(mode, ESP_BLUFI_STA_CONN_SUCCESS, 0, &info);
} else {
BLUFI_INFO("BLUFI BLE is not connected yet\n");
}
break;
}
default:
@ -151,11 +156,15 @@ static void wifi_event_handler(void* arg, esp_event_base_t event_base,
esp_wifi_get_mode(&mode);
/* TODO: get config or information of softap, then set to report extra_info */
if (ble_is_connected == true) {
if (gl_sta_connected) {
esp_blufi_send_wifi_conn_report(mode, ESP_BLUFI_STA_CONN_SUCCESS, 0, NULL);
} else {
esp_blufi_send_wifi_conn_report(mode, ESP_BLUFI_STA_CONN_FAIL, 0, NULL);
}
} else {
BLUFI_INFO("BLUFI BLE is not connected yet\n");
}
break;
case WIFI_EVENT_SCAN_DONE: {
uint16_t apCount = 0;
@ -183,7 +192,13 @@ static void wifi_event_handler(void* arg, esp_event_base_t event_base,
blufi_ap_list[i].rssi = ap_list[i].rssi;
memcpy(blufi_ap_list[i].ssid, ap_list[i].ssid, sizeof(ap_list[i].ssid));
}
if (ble_is_connected == true) {
esp_blufi_send_wifi_list(apCount, blufi_ap_list);
} else {
BLUFI_INFO("BLUFI BLE is not connected yet\n");
}
esp_wifi_scan_stop();
free(ap_list);
free(blufi_ap_list);
@ -207,7 +222,6 @@ static void initialise_wifi(void)
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
ESP_ERROR_CHECK( esp_wifi_start() );
}
@ -236,6 +250,7 @@ static void example_event_callback(esp_blufi_cb_event_t event, esp_blufi_cb_para
break;
case ESP_BLUFI_EVENT_BLE_CONNECT:
BLUFI_INFO("BLUFI ble connect\n");
ble_is_connected = true;
server_if = param->connect.server_if;
conn_id = param->connect.conn_id;
esp_ble_gap_stop_advertising();
@ -243,6 +258,7 @@ static void example_event_callback(esp_blufi_cb_event_t event, esp_blufi_cb_para
break;
case ESP_BLUFI_EVENT_BLE_DISCONNECT:
BLUFI_INFO("BLUFI ble disconnect\n");
ble_is_connected = false;
blufi_security_deinit();
esp_ble_gap_start_advertising(&example_adv_params);
break;