Help on BLE Notify

frax84
Posts: 42
Joined: Thu Jan 07, 2016 11:26 am

Help on BLE Notify

Postby frax84 » Mon Jan 30, 2017 10:30 am

Hello,
i'm working on "gatt_server" example using ESP32 as BLE server and Android app "BLEscanner" as BLE client. I have been able to make the basic code work so i can discovery and connect. I'm making experiments to improve my ESP-IDF knowledge (i'm using the esp-idf 2.0 RC) adding some features to the example but i'm having hard time with notifications. Let me explain with code:

I started declaring a variable:

Code: Select all

uint8_t experiment = 0xEE;
I use this variable as a check for the code for reading operation i use, the following one:

Code: Select all

case ESP_GATTS_READ_EVT: {
		esp_gatt_rsp_t rsp;
		memset(&rsp, 0, sizeof(esp_gatt_rsp_t));
		rsp.attr_value.handle = param->read.handle;
		rsp.attr_value.len = 1;
		rsp.attr_value.value[0] = experiment;
		esp_ble_gatts_send_response(gatts_if, param->read.conn_id,
				param->read.trans_id, ESP_GATT_OK, &rsp);
		break;
With this when i click on "READ" on a characteristic on the app i read the value 0xEE.
About the write operation i tried write this code:

Code: Select all

case ESP_GATTS_WRITE_EVT: {
		if (param->write.handle== gl_profile_tab[0].char_handle) {      //[0] because i'm using profile A
			experiment = (uint8_t)*param->write.value;
		} else if (param->write.handle== gl_profile_tab[0].descr_handle) {
			esp_ble_gatts_set_attr_value(gl_profile_tab[0].descr_handle, param->write.len,(uint8_t*) param->write.value);
			experiment=0xBB;
		}
		esp_ble_gatts_send_response(gatts_if, param->write.conn_id,param->write.trans_id, ESP_GATT_OK, NULL);
	break;
With this code i (TRY) to use the "write.handle" to filter the request. If i write the characteristic the program run the first if and the following READ reads the new "experiment" value. But if i click on NOTIFY experiment value doesn't change to "0xBB".

What i'm doing wrong? Any suggestion would be appreciated!

Regards,
Frax

frax84
Posts: 42
Joined: Thu Jan 07, 2016 11:26 am

Re: Help on BLE Notify

Postby frax84 » Tue Jan 31, 2017 10:33 am

Don't leave me alone! It's cold outside!

MarkIngle
Posts: 30
Joined: Wed Jan 18, 2017 4:48 am

Re: Help on BLE Notify

Postby MarkIngle » Thu Feb 23, 2017 6:09 pm

This looks similar to what I am trying to learn. I am going work on understanding your code so that we can understand this together. Thanks for posting this!

frax84
Posts: 42
Joined: Thu Jan 07, 2016 11:26 am

Re: Help on BLE Notify

Postby frax84 » Sun Feb 26, 2017 4:20 pm

Glad if my work fan help you. Let me know if you fine out something.

Frax

AnthonyPhan
Posts: 3
Joined: Sun Jun 18, 2017 12:27 pm

Re: Help on BLE Notify

Postby AnthonyPhan » Sun Jun 18, 2017 12:35 pm

I am also working on a similar problem. I will post here if I make any progress.

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Help on BLE Notify

Postby kolban » Wed Jun 21, 2017 4:42 am

Can you describe in more detail the nature of your puzzle/problem?
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

Who is online

Users browsing this forum: metala and 130 guests