moving toward ESPIDF events for BLE actions
This commit is contained in:
parent
6467f21fca
commit
0b4522bf7e
1 changed files with 8 additions and 3 deletions
|
|
@ -226,19 +226,24 @@ static int ble_gap_event(struct ble_gap_event *event, void *arg) {
|
||||||
ESP_ERROR_CHECK(ble_hs_adv_parse_fields(&fields, event->disc.data, event->disc.length_data));
|
ESP_ERROR_CHECK(ble_hs_adv_parse_fields(&fields, event->disc.data, event->disc.length_data));
|
||||||
|
|
||||||
if(fields.name != NULL) {
|
if(fields.name != NULL) {
|
||||||
char *name = (char*)malloc(fields.name_len);
|
char *name = (char*)malloc(fields.name_len + 1);
|
||||||
memcpy(name, (uint8_t*)fields.name, fields.name_len);
|
snprintf(name, fields.name_len + 1, "%s", fields.name);
|
||||||
name[fields.name_len] = '\0';
|
|
||||||
ESP_LOGI(TAG, "DISCOVERY: %s", name);
|
ESP_LOGI(TAG, "DISCOVERY: %s", name);
|
||||||
|
|
||||||
// we'll party at any bar
|
// we'll party at any bar
|
||||||
if(strstr(name, "BAR") >= 0) {
|
if(strstr(name, "BAR") >= 0) {
|
||||||
ESP_LOGI(TAG, "Let's Party!");
|
ESP_LOGI(TAG, "Let's Party!");
|
||||||
|
/*
|
||||||
|
* No longer want to automatically connect
|
||||||
|
* Actions can be taken based on discovery
|
||||||
uint8_t addr_type;
|
uint8_t addr_type;
|
||||||
ble_gap_disc_cancel();
|
ble_gap_disc_cancel();
|
||||||
|
|
||||||
ESP_ERROR_CHECK(ble_hs_id_infer_auto(0, &addr_type));
|
ESP_ERROR_CHECK(ble_hs_id_infer_auto(0, &addr_type));
|
||||||
ESP_ERROR_CHECK(ble_gap_connect(addr_type, &event->disc.addr, 30000, NULL, ble_gap_event, NULL));
|
ESP_ERROR_CHECK(ble_gap_connect(addr_type, &event->disc.addr, 30000, NULL, ble_gap_event, NULL));
|
||||||
|
*/
|
||||||
|
|
||||||
|
esp_event_post(EVENT_BAROS_BLE, BAROS_BLE_DISC, name, fields.name_len + 1, portMAX_DELAY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue