Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ settings:
"min_sec_level": 0, // Minimum security level for all attributes of all services.
// 0 - no auth required, 1 - encryption reqd, 2 - encryption + MITM reqd
"require_pairing": false // Require taht device is paired before accessing services
},
"gap": {
"include_name": true, // Include dev_name in advertisements
"service_uuid": "" // Advertise this service uuid
}
}
```
Expand Down
3 changes: 3 additions & 0 deletions mos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ config_schema:
- ["bt.gatts", "o", {title: "GATTS settings"}]
- ["bt.gatts.min_sec_level", "i", 0, {title: "0 - no auth required, 1 - encryption reqd, 2 - encryption + MITM reqd"}]
- ["bt.gatts.require_pairing", "b", false, {title: "Require device to be paired before accessing services"}]
- ["bt.gap", "o", {title: "GAP settings"}]
- ["bt.gap.include_name", "b", true, {title: "Include name in advertisements"}]
- ["bt.gap.service_uuid", "s", "", {title: "Service UUID to advertise"}]

tags:
- bt
Expand Down
18 changes: 18 additions & 0 deletions src/esp32/esp32_bt_gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ static bool s_advertising = false;
static bool s_pairing_enable = false;
static bool s_scanning = false;
static int s_scan_duration_sec = 3;
static uint8_t s_service_uuid[16] = {0};

static esp_ble_adv_data_t s_adv_data = {
.set_scan_rsp = false,
Expand Down Expand Up @@ -76,6 +77,23 @@ bool esp32_bt_is_scanning(void) {
static bool start_advertising(void) {
if (s_advertising) return true;
if (!s_adv_enable || esp32_bt_is_scanning()) return false;

s_adv_data.include_name = mgos_sys_config_get_bt_gap_include_name();

struct mg_str service_uuid_str =
mg_mk_str(mgos_sys_config_get_bt_gap_service_uuid());
struct mgos_bt_uuid service_uuid;
if (service_uuid_str.p &&
mgos_bt_uuid_from_str(service_uuid_str, &service_uuid) &&
service_uuid.len == sizeof(service_uuid.uuid.uuid128)) {
memcpy(s_service_uuid, service_uuid.uuid.uuid128, service_uuid.len);
s_adv_data.service_uuid_len = service_uuid.len;
s_adv_data.p_service_uuid = s_service_uuid;
} else {
s_adv_data.service_uuid_len = 0;
s_adv_data.p_service_uuid = NULL;
}

const char *dev_name = mgos_sys_config_get_bt_dev_name();
if (dev_name == NULL) dev_name = mgos_sys_config_get_device_id();
if (dev_name == NULL) {
Expand Down