Skip to content

Commit

Permalink
Merge branch 'feature/optimize_blufi_example' into 'master'
Browse files Browse the repository at this point in the history
blufi: optimize example to send more information

Closes IDFGH-6842 and IDFGH-6809

See merge request espressif/esp-idf!19853
  • Loading branch information
jack0c committed Nov 7, 2022
2 parents 9d7facf + c41ce49 commit 0c8272b
Show file tree
Hide file tree
Showing 11 changed files with 168 additions and 20 deletions.
9 changes: 9 additions & 0 deletions components/bt/common/api/include/api/esp_blufi_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ typedef enum {
typedef enum {
ESP_BLUFI_STA_CONN_SUCCESS = 0x00,
ESP_BLUFI_STA_CONN_FAIL = 0x01,
ESP_BLUFI_STA_CONNECTING = 0x02,
ESP_BLUFI_STA_NO_IP = 0x03,
} esp_blufi_sta_conn_state_t;

/// BLUFI init status
Expand All @@ -75,6 +77,7 @@ typedef enum {
ESP_BLUFI_MAKE_PUBLIC_ERROR,
ESP_BLUFI_DATA_FORMAT_ERROR,
ESP_BLUFI_CALC_MD5_ERROR,
ESP_BLUFI_WIFI_SCAN_FAIL,
} esp_blufi_error_state_t;

/**
Expand All @@ -98,6 +101,12 @@ typedef struct {
bool softap_max_conn_num_set; /*!< is max connection number of softap interface set */
uint8_t softap_channel; /*!< channel of softap interface */
bool softap_channel_set; /*!< is channel of softap interface set */
uint8_t sta_max_conn_retry; /*!< max retry of sta establish connection */
bool sta_max_conn_retry_set; /*!< is max retry of sta establish connection set */
uint8_t sta_conn_end_reason; /*!< reason of sta connection end */
bool sta_conn_end_reason_set; /*!< is reason of sta connection end set */
int8_t sta_conn_rssi; /*!< rssi of sta connection */
bool sta_conn_rssi_set; /*!< is rssi of sta connection set */
} esp_blufi_extra_info_t;

/** @brief Description of an WiFi AP */
Expand Down
30 changes: 30 additions & 0 deletions components/bt/common/btc/profile/esp/blufi/blufi_prf.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,21 @@ static void btc_blufi_wifi_conn_report(uint8_t opmode, uint8_t sta_conn_state, u
*p++ = 1;
*p++ = info->softap_channel;
}
if (info->sta_max_conn_retry_set) {
*p++ = BLUFI_TYPE_DATA_SUBTYPE_STA_MAX_CONN_RETRY;
*p++ = 1;
*p++ = info->sta_max_conn_retry;
}
if (info->sta_conn_end_reason_set) {
*p++ = BLUFI_TYPE_DATA_SUBTYPE_STA_CONN_END_REASON;
*p++ = 1;
*p++ = info->sta_conn_end_reason;
}
if (info->sta_conn_rssi_set) {
*p++ = BLUFI_TYPE_DATA_SUBTYPE_STA_CONN_RSSI;
*p++ = 1;
*p++ = info->sta_conn_rssi;
}
}
if (p - data > data_len) {
BTC_TRACE_ERROR("%s len error %d %d\n", __func__, (int)(p - data), data_len);
Expand Down Expand Up @@ -706,6 +721,21 @@ void btc_blufi_call_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
dst->wifi_conn_report.extra_info->softap_channel = src_info->softap_channel;
dst->wifi_conn_report.extra_info_len += (1 + 2);
}
if (src_info->sta_max_conn_retry_set) {
dst->wifi_conn_report.extra_info->sta_max_conn_retry_set = src_info->sta_max_conn_retry_set;
dst->wifi_conn_report.extra_info->sta_max_conn_retry = src_info->sta_max_conn_retry;
dst->wifi_conn_report.extra_info_len += (1 + 2);
}
if (src_info->sta_conn_end_reason_set) {
dst->wifi_conn_report.extra_info->sta_conn_end_reason_set = src_info->sta_conn_end_reason_set;
dst->wifi_conn_report.extra_info->sta_conn_end_reason = src_info->sta_conn_end_reason;
dst->wifi_conn_report.extra_info_len += (1 + 2);
}
if (src_info->sta_conn_rssi_set) {
dst->wifi_conn_report.extra_info->sta_conn_rssi_set = src_info->sta_conn_rssi_set;
dst->wifi_conn_report.extra_info->sta_conn_rssi = src_info->sta_conn_rssi;
dst->wifi_conn_report.extra_info_len += (1 + 2);
}
break;
}
case BTC_BLUFI_ACT_SEND_WIFI_LIST:{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#if (BLUFI_INCLUDED == TRUE)

#define BTC_BLUFI_GREAT_VER 0x01 //Version + Subversion
#define BTC_BLUFI_SUB_VER 0x02 //Version + Subversion
#define BTC_BLUFI_SUB_VER 0x03 //Version + Subversion
#define BTC_BLUFI_VERSION ((BTC_BLUFI_GREAT_VER<<8)|BTC_BLUFI_SUB_VER) //Version + Subversion

typedef UINT8 tGATT_IF;
Expand Down Expand Up @@ -121,6 +121,9 @@ extern tBLUFI_ENV *blufi_env_ptr;
#define BLUFI_TYPE_DATA_SUBTYPE_WIFI_LIST 0x11
#define BLUFI_TYPE_DATA_SUBTYPE_ERROR_INFO 0x12
#define BLUFI_TYPE_DATA_SUBTYPE_CUSTOM_DATA 0x13
#define BLUFI_TYPE_DATA_SUBTYPE_STA_MAX_CONN_RETRY 0x14
#define BLUFI_TYPE_DATA_SUBTYPE_STA_CONN_END_REASON 0x15
#define BLUFI_TYPE_DATA_SUBTYPE_STA_CONN_RSSI 0x16
#define BLUFI_TYPE_IS_CTRL(type) (BLUFI_GET_TYPE((type)) == BLUFI_TYPE_CTRL)
#define BLUFI_TYPE_IS_DATA(type) (BLUFI_GET_TYPE((type)) == BLUFI_TYPE_DATA)

Expand Down
1 change: 1 addition & 0 deletions components/esp_wifi/include/esp_wifi_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@ typedef struct {
uint8_t ssid_len; /**< SSID length of disconnected AP */
uint8_t bssid[6]; /**< BSSID of disconnected AP */
uint8_t reason; /**< reason of disconnection */
int8_t rssi; /**< rssi of disconnection */
} wifi_event_sta_disconnected_t;

/** Argument structure for WIFI_EVENT_STA_AUTHMODE_CHANGE event */
Expand Down
19 changes: 17 additions & 2 deletions docs/en/api-guides/blufi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,11 @@ The format of ACK Frame:
* 0x02: SoftAP
* 0x03: SoftAP & STA

data[1]: connection state of the STA device. 0x0 indicates a connection state, and others represent a disconnected state;
data[1]: connection state of the STA device. 0x0 indicates a connection state with IP address, 0x1 represent a disconnected state, 0x2 indicates a connecting state, and 0x3 indicates a connection state but no IP address.

data[2]: connection state of SoftAP. That is, how many STA devices have been connected.

data[3] and the subsequent is in accordance with the format of SSID/BSSID information.
data[3] and the subsequent is in accordance with the format of SSID/BSSID information. If device is in connecting state, maximum Wi-Fi reconnecting time would be included here. If device is in disconnected state, Wi-Fi connection end reason and RSSI would be included here.
* - 0x10 (b’010000)
- Version
-
Expand All @@ -347,10 +347,25 @@ The format of ACK Frame:
* 0x06: dh param error
* 0x07: read param error
* 0x08: make public error
* 0x09: data format error
* 0x0a: calculate MD5 error
* 0x0b: Wi-Fi scan error
* - 0x13 (b’010011)
- Custom Data
- To send or receive custom data.
- The data frame supports to be sent into fragments if the data length is too long.
* - 0x14 (b’010100)
- Set the maximum Wi-Fi reconnecting time.
-
- data[0] represents the maximum Wi-Fi reconnecting time.
* - 0x15 (b’010101)
- Set the Wi-Fi connection end reason.
-
- data[0] represents the Wi-Fi connection end reason, whose type shall be same with struct `wifi_err_reason_t`.
* - 0x16 (b’010110)
- Set the RSSI at Wi-Fi connection end.
-
- data[0] represents the RSSI at Wi-Fi connection end. If there is no meaningful RSSI in the connection end, this value shall be the meaningless one, which is `-128`.

.. note::

Expand Down
19 changes: 17 additions & 2 deletions docs/zh_CN/api-guides/blufi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,11 @@ ACK 帧格式(8 bit):
* 0x02: SoftAP
* 0x03: SoftAP & STA

data[1]:STA 设备的连接状态。0x0 表示处于连接状态,其他表示处于非连接状态;
data[1]:STA 设备的连接状态。0x0 表示处于连接状态且获得 IP 地址,0x1 表示处于非连接状态, 0x2 表示处于正在连接状态,0x3 表示处于连接状态但未获得 IP 地址。

data[2]:SoftAP 的连接状态,即表示有多少 STA 设备已经连接。

data[3]及后面的数据是按照 SSID/BSSID 格式提供的信息。
data[3]及后面的数据是按照 SSID/BSSID 格式提供的信息。 如果 Wi-Fi 处于正在连接状态,这里将会包含最大重连次数;如果 Wi-Fi 处于非连接状态,这里将会包含 Wi-Fi 断开连接原因和 RSSI 信息。
* - 0x10 (b’010000)
- 版本
-
Expand All @@ -347,10 +347,25 @@ ACK 帧格式(8 bit):
* 0x06: dh param error
* 0x07: read param error
* 0x08: make public error
* 0x09: data format error
* 0x0a: calculate MD5 error
* 0x0b: Wi-Fi scan error
* - 0x13 (b’010011)
- 自定义数据
- 用户发送或者接收自定义数据。
- 数据较长时可分片发送。
* - 0x14 (b’010100)
- 设置最大 Wi-Fi 重连次数。
-
- data[0] 表示 Wi-Fi 最大重连次数。
* - 0x15 (b’010101)
- 设置 Wi-Fi 连接失败原因。
-
- data[0] 表示 Wi-Fi 连接失败原因,它的类型应该和 `wifi_err_reason_t` 一致。
* - 0x16 (b’010110)
- 设置 Wi-Fi 连接失败的 RSSI 。
-
- data[0] 表示在 Wi-Fi 连接失败时的 RSSI。 如果在连接结束时没有有意义的 RSSI , 这个值应该为一个无意义值 `-128`。

.. note::

Expand Down
2 changes: 1 addition & 1 deletion examples/bluetooth/.build-test-rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ examples/bluetooth/bluedroid/coex/gattc_gatts_coex:

examples/bluetooth/blufi:
enable:
- if: IDF_TARGET in ["esp32", "esp32c3"]
- if: IDF_TARGET in ["esp32", "esp32c2", "esp32c3", "esp32s3"]
temporary: true
reason: the other targets are not tested yet

Expand Down
6 changes: 3 additions & 3 deletions examples/bluetooth/blufi/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
| Supported Targets | ESP32 | ESP32-C3 |
| ----------------- | ----- | -------- |
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-S3 |
| ----------------- | ----- | -------- | -------- | -------- |

# ESP-IDF Blufi Example

Expand Down Expand Up @@ -27,7 +27,7 @@ Blufi is completely open source, here is the download link:

### Hardware Required

* A development board with ESP32/ESP32-C3 SoC (e.g., ESP32-DevKitC, ESP-WROVER-KIT, etc.)
* A development board with ESP32/ESP32-C3/ESP32-S3/ESP32-C2 SoC (e.g., ESP32-DevKitC, ESP-WROVER-KIT, etc.)
* A USB cable for Power supply and programming

See [Development Boards](https://www.espressif.com/en/products/devkits) for more information about it.
Expand Down
10 changes: 10 additions & 0 deletions examples/bluetooth/blufi/main/Kconfig.projbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
menu "Example Configuration"

config EXAMPLE_WIFI_CONNECTION_MAXIMUM_RETRY
int "WiFi connection maximum retry"
range 0 255
default 2
help
WiFi connection maximum retry, from 0 to 255.

endmenu
Loading

0 comments on commit 0c8272b

Please sign in to comment.