mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'bugfix/fix_blufi_example_softap_current_connection_equal_zero_issue' into 'master'
bluetooth:fix two blufi example bugs Closes IDFGH-6621 See merge request espressif/esp-idf!18298
This commit is contained in:
commit
cfa3b03d8e
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
*/
|
*/
|
||||||
@ -19,6 +19,7 @@
|
|||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
#include "freertos/event_groups.h"
|
#include "freertos/event_groups.h"
|
||||||
#include "esp_system.h"
|
#include "esp_system.h"
|
||||||
|
#include "esp_mac.h"
|
||||||
#include "esp_wifi.h"
|
#include "esp_wifi.h"
|
||||||
#include "esp_event.h"
|
#include "esp_event.h"
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
@ -51,6 +52,19 @@ static bool ble_is_connected = false;
|
|||||||
static uint8_t gl_sta_bssid[6];
|
static uint8_t gl_sta_bssid[6];
|
||||||
static uint8_t gl_sta_ssid[32];
|
static uint8_t gl_sta_ssid[32];
|
||||||
static int gl_sta_ssid_len;
|
static int gl_sta_ssid_len;
|
||||||
|
static wifi_sta_list_t gl_sta_list;
|
||||||
|
|
||||||
|
static int softap_get_current_connection_number(void)
|
||||||
|
{
|
||||||
|
esp_err_t ret;
|
||||||
|
ret = esp_wifi_ap_get_sta_list(&gl_sta_list);
|
||||||
|
if (ret == ESP_OK)
|
||||||
|
{
|
||||||
|
return gl_sta_list.num;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void ip_event_handler(void* arg, esp_event_base_t event_base,
|
static void ip_event_handler(void* arg, esp_event_base_t event_base,
|
||||||
int32_t event_id, void* event_data)
|
int32_t event_id, void* event_data)
|
||||||
@ -70,7 +84,7 @@ static void ip_event_handler(void* arg, esp_event_base_t event_base,
|
|||||||
info.sta_ssid = gl_sta_ssid;
|
info.sta_ssid = gl_sta_ssid;
|
||||||
info.sta_ssid_len = gl_sta_ssid_len;
|
info.sta_ssid_len = gl_sta_ssid_len;
|
||||||
if (ble_is_connected == true) {
|
if (ble_is_connected == true) {
|
||||||
esp_blufi_send_wifi_conn_report(mode, ESP_BLUFI_STA_CONN_SUCCESS, 0, &info);
|
esp_blufi_send_wifi_conn_report(mode, ESP_BLUFI_STA_CONN_SUCCESS, softap_get_current_connection_number(), &info);
|
||||||
} else {
|
} else {
|
||||||
BLUFI_INFO("BLUFI BLE is not connected yet\n");
|
BLUFI_INFO("BLUFI BLE is not connected yet\n");
|
||||||
}
|
}
|
||||||
@ -115,9 +129,9 @@ static void wifi_event_handler(void* arg, esp_event_base_t event_base,
|
|||||||
/* TODO: get config or information of softap, then set to report extra_info */
|
/* TODO: get config or information of softap, then set to report extra_info */
|
||||||
if (ble_is_connected == true) {
|
if (ble_is_connected == true) {
|
||||||
if (gl_sta_connected) {
|
if (gl_sta_connected) {
|
||||||
esp_blufi_send_wifi_conn_report(mode, ESP_BLUFI_STA_CONN_SUCCESS, 0, NULL);
|
esp_blufi_send_wifi_conn_report(mode, ESP_BLUFI_STA_CONN_SUCCESS, softap_get_current_connection_number(), NULL);
|
||||||
} else {
|
} else {
|
||||||
esp_blufi_send_wifi_conn_report(mode, ESP_BLUFI_STA_CONN_FAIL, 0, NULL);
|
esp_blufi_send_wifi_conn_report(mode, ESP_BLUFI_STA_CONN_FAIL, softap_get_current_connection_number(), NULL);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
BLUFI_INFO("BLUFI BLE is not connected yet\n");
|
BLUFI_INFO("BLUFI BLE is not connected yet\n");
|
||||||
@ -161,6 +175,17 @@ static void wifi_event_handler(void* arg, esp_event_base_t event_base,
|
|||||||
free(blufi_ap_list);
|
free(blufi_ap_list);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case WIFI_EVENT_AP_STACONNECTED: {
|
||||||
|
wifi_event_ap_staconnected_t* event = (wifi_event_ap_staconnected_t*) event_data;
|
||||||
|
BLUFI_INFO("station "MACSTR" join, AID=%d", MAC2STR(event->mac), event->aid);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case WIFI_EVENT_AP_STADISCONNECTED: {
|
||||||
|
wifi_event_ap_stadisconnected_t* event = (wifi_event_ap_stadisconnected_t*) event_data;
|
||||||
|
BLUFI_INFO("station "MACSTR" leave, AID=%d", MAC2STR(event->mac), event->aid);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -174,6 +199,8 @@ static void initialise_wifi(void)
|
|||||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||||
esp_netif_t *sta_netif = esp_netif_create_default_wifi_sta();
|
esp_netif_t *sta_netif = esp_netif_create_default_wifi_sta();
|
||||||
assert(sta_netif);
|
assert(sta_netif);
|
||||||
|
esp_netif_t *ap_netif = esp_netif_create_default_wifi_ap();
|
||||||
|
assert(ap_netif);
|
||||||
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &wifi_event_handler, NULL));
|
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &wifi_event_handler, NULL));
|
||||||
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &ip_event_handler, NULL));
|
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &ip_event_handler, NULL));
|
||||||
|
|
||||||
@ -242,15 +269,17 @@ static void example_event_callback(esp_blufi_cb_event_t event, esp_blufi_cb_para
|
|||||||
|
|
||||||
esp_wifi_get_mode(&mode);
|
esp_wifi_get_mode(&mode);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (gl_sta_connected) {
|
if (gl_sta_connected) {
|
||||||
memset(&info, 0, sizeof(esp_blufi_extra_info_t));
|
memset(&info, 0, sizeof(esp_blufi_extra_info_t));
|
||||||
memcpy(info.sta_bssid, gl_sta_bssid, 6);
|
memcpy(info.sta_bssid, gl_sta_bssid, 6);
|
||||||
info.sta_bssid_set = true;
|
info.sta_bssid_set = true;
|
||||||
info.sta_ssid = gl_sta_ssid;
|
info.sta_ssid = gl_sta_ssid;
|
||||||
info.sta_ssid_len = gl_sta_ssid_len;
|
info.sta_ssid_len = gl_sta_ssid_len;
|
||||||
esp_blufi_send_wifi_conn_report(mode, ESP_BLUFI_STA_CONN_SUCCESS, 0, &info);
|
esp_blufi_send_wifi_conn_report(mode, ESP_BLUFI_STA_CONN_SUCCESS, softap_get_current_connection_number(), &info);
|
||||||
} else {
|
} else {
|
||||||
esp_blufi_send_wifi_conn_report(mode, ESP_BLUFI_STA_CONN_FAIL, 0, NULL);
|
esp_blufi_send_wifi_conn_report(mode, ESP_BLUFI_STA_CONN_FAIL, softap_get_current_connection_number(), NULL);
|
||||||
}
|
}
|
||||||
BLUFI_INFO("BLUFI get wifi status from AP\n");
|
BLUFI_INFO("BLUFI get wifi status from AP\n");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user