Skip to content

Commit 73179cb

Browse files
committed
A number of fixes related to advertising cycle
1 parent 3574986 commit 73179cb

File tree

5 files changed

+91
-191
lines changed

5 files changed

+91
-191
lines changed

include/esp32/esp32_bt_internal.h

+1-5
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,11 @@
2727
extern "C" {
2828
#endif
2929

30-
bool esp32_bt_is_scanning(void);
31-
bool esp32_bt_gattc_init(void);
32-
30+
bool esp32_bt_gap_start_advertising(void);
3331
bool esp32_bt_gatts_init(void);
3432
bool esp32_bt_gatts_start(void);
3533
void esp32_bt_restart(void);
3634

37-
void esp32_bt_set_is_advertising(bool is_advertising);
38-
3935
struct ble_gap_event;
4036
int esp32_bt_gatts_event(const struct ble_gap_event *event, void *arg);
4137

mos.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ config_schema:
2222
- ["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."}]
2323
- ["bt.allow_pairing", "b", true, {title: "Allow pairing/bonding with other devices"}]
2424
- ["bt.max_paired_devices", "i", -1, {title: "Max number of paired devices; -1 - no limit"}]
25-
- ["bt.random_address", "b", true, {title: "Use random BT address"}]
25+
# TODO: Random address support on NimBLE
26+
- ["bt.random_address", "b", false, {title: "Use random BT address"}]
2627
- ["bt.gatt_mtu", "i", 500, {title: "Local MTU setting, used when negotiating with clients"}]
2728
- ["bt.gatts", "o", {title: "GATTS settings"}]
2829
- ["bt.gatts.min_sec_level", "i", 0, {title: "0 - no auth required, 1 - encryption reqd, 2 - encryption + MITM reqd"}]

src/esp32/esp32_bt.c

+10-4
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ static void mgos_bt_net_ev(int ev, void *evd, void *arg) {
133133
mgos_sys_config_set_bt_enable(false);
134134
char *msg = NULL;
135135
if (save_cfg(&mgos_sys_config, &msg)) {
136-
// nimble_port_stop();
136+
mgos_bt_stop();
137137
}
138138
(void) arg;
139139
}
@@ -149,7 +149,7 @@ bool mgos_bt_get_device_address(struct mgos_bt_addr *addr) {
149149
int is_nrpa = false;
150150
rc = ble_hs_id_copy_addr(own_addr_type, baddr.val, &is_nrpa);
151151
if (rc != 0) {
152-
LOG(LL_ERROR, ("BLE addr error %d", rc));
152+
LOG(LL_ERROR, ("BLE addr type %d error %d", own_addr_type, rc));
153153
return false;
154154
}
155155
switch (own_addr_type) {
@@ -175,7 +175,6 @@ static void esp32_bt_reset(int reason) {
175175
static void esp32_bt_synced(void) {
176176
int rc;
177177

178-
LOG(LL_INFO, ("BLE started"));
179178
s_state = ESP32_BT_STARTED;
180179

181180
if (!s_should_be_running) {
@@ -198,7 +197,7 @@ static void esp32_bt_synced(void) {
198197
("BLE Device Address: %s",
199198
mgos_bt_addr_to_str(&addr, MGOS_BT_ADDR_STRINGIFY_TYPE, addr_str)));
200199
}
201-
mgos_bt_gap_set_adv_enable(mgos_sys_config_get_bt_adv_enable());
200+
esp32_bt_gap_start_advertising();
202201
}
203202

204203
// Handler callback that executes host events on the mgos task.
@@ -298,6 +297,8 @@ static bool esp32_bt_init(void) {
298297
goto out;
299298
}
300299

300+
mgos_bt_gap_set_adv_enable(mgos_sys_config_get_bt_adv_enable());
301+
301302
LOG(LL_INFO, ("Bluetooth init ok, MTU %d, pairing %s, %d paired devices",
302303
mgos_sys_config_get_bt_gatt_mtu(),
303304
(mgos_bt_gap_get_pairing_enable() ? "enabled" : "disabled"),
@@ -352,6 +353,11 @@ bool mgos_bt_common_init(void) {
352353
LOG(LL_INFO, ("Bluetooth is disabled"));
353354
return true;
354355
}
356+
// TODO(rojer): Figure out random address support under NimBLE.
357+
if (mgos_sys_config_get_bt_random_address()) {
358+
LOG(LL_ERROR, ("Random addresses are not supported, using public"));
359+
mgos_sys_config_set_bt_random_address(false);
360+
}
355361
esp32_bt_init();
356362
// Delay starting the stack until other libraries are initialized
357363
// and services registered to avoid unnecessary restarts.

0 commit comments

Comments
 (0)