Skip to content

custom event handlers #711

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
chegewara opened this issue Nov 5, 2018 · 1 comment
Closed

custom event handlers #711

chegewara opened this issue Nov 5, 2018 · 1 comment

Comments

@chegewara
Copy link
Collaborator

chegewara commented Nov 5, 2018

I am planing to implement functions to register custom events handlers, one for each type(GAP, GATTS and GATTC). Usage will be similar to register notify callback. Add/register custom handler:

BLEDevice::setCustomGapHandler(my_gap_event_handler);

and function to handle events:

static void my_gap_event_handler(esp_gap_ble_cb_event_t  event, esp_ble_gap_cb_param_t* param) {
	ESP_LOGW(LOG_TAG, "custom gap event handler, GAP event: %d", (uint8_t)event);
}

Function in action (logs):

W (608) SampleServer: custom gap event handler, GAP event: 0  // <-- ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT
W (608) SampleServer: custom gap event handler, GAP event: 1  // <-- ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT
W (608) SampleServer: custom gap event handler, GAP event: 6  // <-- ESP_GAP_BLE_ADV_START_COMPLETE_EVT
W (9198) SampleServer: custom gap event handler, GAP event: 20  // <-- ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT
W (9318) SampleServer: custom gap event handler, GAP event: 20
W (9488) SampleServer: custom gap event handler, GAP event: 20
W (15848) SampleServer: custom gap event handler, GAP event: 10  // <-- ESP_GAP_BLE_SEC_REQ_EVT
W (16008) SampleServer: custom gap event handler, GAP event: 20
W (16038) BT_SMP: FOR LE SC LTK IS USED INSTEAD OF STK
W (16068) SampleServer: custom gap event handler, GAP event: 9  // <-- ESP_GAP_BLE_KEY_EVT
W (16068) SampleServer: custom gap event handler, GAP event: 9
W (16068) SampleServer: custom gap event handler, GAP event: 9
W (16078) SampleServer: custom gap event handler, GAP event: 9
W (16098) SampleServer: custom gap event handler, GAP event: 9
W (16248) SampleServer: custom gap event handler, GAP event: 9
W (16258) SampleServer: custom gap event handler, GAP event: 8  // <-- ESP_GAP_BLE_AUTH_CMPL_EVT
W (16928) SampleServer: custom gap event handler, GAP event: 20

This will allow to make library more flexible without increasing complexity and size. We can for example catch congestion events and take proper actions when we know that notify/indication cant be send.

@chegewara
Copy link
Collaborator Author

Few more logs. Maybe its not much, but we would be allowed to override build in mechanism to achieve better performance or add something that is missing in this library. I will for sure use it to debug code.

Just a few lines of code:

....
static void my_gap_event_handler(esp_gap_ble_cb_event_t  event, esp_ble_gap_cb_param_t* param) {
	ESP_LOGW(LOG_TAG, "custom gap event handler, GAP event: %d", (uint8_t)event);
}

static void my_gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t* param) {
	ESP_LOGW(LOG_TAG, "custom gattc event handler, GAP event: %d", (uint8_t)event);
}

static void my_gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gatts_cb_param_t* param) {
	ESP_LOGW(LOG_TAG, "custom gatts event handler, GAP event: %d", (uint8_t)event);
}
....
BLEDevice::setCustomGapHandler(my_gap_event_handler);
BLEDevice::setCustomGattsHandler(my_gatts_event_handler);
BLEDevice::setCustomGattcHandler(my_gattc_event_handler);
BLEDevice::init("My32");

Logs:

W (573) SampleServer: custom gatts event handler, GAP event: 0
W (583) SampleServer: custom gatts event handler, GAP event: 7
W (603) SampleServer: custom gatts event handler, GAP event: 9
W (603) SampleServer: custom gatts event handler, GAP event: 10
W (613) SampleServer: custom gatts event handler, GAP event: 12
W (623) SampleServer: custom gap event handler, GAP event: 0
W (623) SampleServer: custom gap event handler, GAP event: 1
W (633) SampleServer: custom gap event handler, GAP event: 6
W (111763) SampleServer: custom gatts event handler, GAP event: 14
W (112403) SampleServer: custom gap event handler, GAP event: 20
W (112513) SampleServer: custom gap event handler, GAP event: 20
W (112713) SampleServer: custom gap event handler, GAP event: 20
W (119553) SampleServer: custom gatts event handler, GAP event: 1
W (119553) SampleServer: custom gatts event handler, GAP event: 21
W (145813) SampleServer: custom gatts event handler, GAP event: 2
W (145813) SampleServer: custom gatts event handler, GAP event: 21
W (145813) SampleServer: custom gatts event handler, GAP event: 5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant