Skip to content

Commit fe3be6f

Browse files
Deomid Ryabkovcesantabot
authored andcommitted
BT scan refactoring
* Make scan options configurable * Resturn scan response data (for active scans) * Move scan and other GAP-related code to esp32_bt_gap.c cc @kzyapkov PUBLISHED_FROM=a755b5d35b628be4c37f73ff72fd1e2c76b3808e
1 parent d190acd commit fe3be6f

File tree

7 files changed

+521
-445
lines changed

7 files changed

+521
-445
lines changed

include/esp32/esp32_bt.h

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,33 @@ struct esp32_bt_connection {
4545
uint16_t mtu;
4646
};
4747

48+
/* Scan each channel for 50 ms, change channel every 100 ms; for 5 seconds */
49+
#define MGOS_BT_BLE_DEFAULT_SCAN_WINDOW_MS 50
50+
#define MGOS_BT_BLE_DEFAULT_SCAN_INTERVAL_MS 100
51+
#define MGOS_BT_BLE_DEFAULT_SCAN_DURATION_MS 5000
52+
struct mgos_bt_ble_scan_opts {
53+
bool active;
54+
int window_ms;
55+
int interval_ms;
56+
int duration_ms;
57+
esp_bd_addr_t addr;
58+
struct mg_str name;
59+
};
4860
struct mgos_bt_ble_scan_result {
4961
esp_bd_addr_t addr;
50-
struct mg_str adv_data; /* Raw adv data */
62+
struct mg_str adv_data; /* Raw adv data */
63+
struct mg_str scan_rsp; /* Raw scan response (for active scans) */
5164
char name[MGOS_BT_DEV_NAME_LEN + 1]; /* NUL-terminated */
5265
int rssi;
5366
};
5467
typedef void (*mgos_bt_ble_scan_cb_t)(int num_res,
5568
const struct mgos_bt_ble_scan_result *res,
5669
void *arg);
57-
void mgos_bt_ble_scan(mgos_bt_ble_scan_cb_t cb, void *cb_arg);
58-
void mgos_bt_ble_scan_device_addr(const esp_bd_addr_t addr,
59-
mgos_bt_ble_scan_cb_t cb, void *cb_arg);
60-
void mgos_bt_ble_scan_device_name(const struct mg_str name,
61-
mgos_bt_ble_scan_cb_t cb, void *cb_arg);
70+
void mgos_bt_ble_scan(const struct mgos_bt_ble_scan_opts *opts,
71+
mgos_bt_ble_scan_cb_t cb, void *cb_arg);
72+
73+
#define MGOS_BT_BLE_MAX_SCAN_RSP_DATA_LEN 31
74+
void mgos_bt_ble_set_scan_rsp_data(const struct mg_str scan_rsp_data);
6275

6376
#ifdef __cplusplus
6477
}

include/esp32/esp32_bt_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ bool is_advertising(void);
2323
bool start_advertising(void);
2424

2525
bool esp32_bt_init(void);
26+
bool esp32_bt_gap_init(void);
2627
bool esp32_bt_gatts_init(void);
2728

2829
#ifdef __cplusplus

mos.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ config_schema:
1515
- ["bt.enable", "b", true, {title: "Enable BT"}]
1616
- ["bt.dev_name", "s", "", {title: "Device name; defaults to device.id"}]
1717
- ["bt.adv_enable", "b", true, {title: "Advertise services"}]
18+
- ["bt.scan_rsp_data_hex", "s", "", {title: "Scan response data, hex-encoded"}]
1819
- ["bt.keep_enabled", "b", false, {title: "By default, BT will be disabled once WiFi is configured and connects. Set this to true to keep BT enabled."}]
1920

2021
tags:

0 commit comments

Comments
 (0)