ESP AT BLE can not enable notification or indication

staibiii
Posts: 7
Joined: Mon Feb 28, 2022 12:16 pm

ESP AT BLE can not enable notification or indication

Postby staibiii » Wed Mar 02, 2022 2:13 pm

Hello everybody,
I encountered the following problem using BLE AT. I got two modules. One as a BLE client (ESP32-WROOM-32) and one as a BLE server (ESP32-C3-WROOM). I am sending AT commands via UART. Everything works fine until i want to enable notification or indication. Therefore I want the client to wirte 0x0001 or 0x0002 to the corresponding discriptor. Like this: AT+BLEGATTCWR=0,4,1,1,2\r\n > '2''0' (note: these are integer not ascii values). However not matter how many bytes or which value I try to write I always receive +WRITE:0,2,1,1,2,'1''0'\r\n on the server side. I fllowed the example on https://docs.espressif.com/projects/esp ... e-services. If I use the nRF Connect App on my phone to enable notification or indication everything works properly. I can also write characteristic values without any problems. Only that one dosent seem to work.

Steps to repropduce
1. Step: init server and client
Server
--> AT+BLEINIT=2
--> AT+BLEADDR? --> +BLEADDR:"7c:df:a1:b2:a2:6e"
--> AT+BLEGATTSSRVCRE
--> AT+BLEGATTSSRVSTART
--> AT+BLEGATTSCHAR? --> +BLEGATTSCHAR:"char",1,1,0x2A2B,0x12
+BLEGATTSCHAR:"desc",1,1,1,0x2902
+BLEGATTSCHAR:"char",2,1,0x2700,0x3a
+BLEGATTSCHAR:"desc",2,1,1,0x2902
+BLEGATTSCHAR:"desc",2,1,2,0x2901
+BLEGATTSCHAR:"char",2,2,0x2700,0x02
+BLEGATTSCHAR:"desc",2,2,1,0x2901
--> AT+BLEADVPARAM=100,200,0,0,7
--> AT+BLEADVSTART

Client
--> AT+BLEINIT=1
--> AT+BLESCAN=1,3 --> +BLESCAN:"7c:df:a1:b2:a2:6e",-32,,,0

2. Step: Connect divices
Client
--> AT+BLECONN=0,"7c:df:a1:b2:a2:6e" --> +BLECONN:0,"7c:df:a1:b2:a2:6e"

3. Step: Write to CCCD
Client
--> AT+BLEGATTCPRIMSRV=0 --> +BLEGATTCPRIMSRV:0,1,0x1801,1
+BLEGATTCPRIMSRV:0,2,0x1800,1
+BLEGATTCPRIMSRV:0,3,0x1805,1
+BLEGATTCPRIMSRV:0,4,0x2D59D6C1C1CE4A1AAAACF59BD3F057DB,1

--> AT+BLEGATTCCHAR=0,4 --> +BLEGATTCCHAR:"char",0,4,1,0x2700,0x3a
+BLEGATTCCHAR:"desc",0,4,1,1,0x2902
+BLEGATTCCHAR:"desc",0,4,1,2,0x2901
+BLEGATTCCHAR:"char",0,4,2,0x2700,0x02
+BLEGATTCCHAR:"desc",0,4,2,1,0x2901

--> AT+BLEGATTCWR=0,4,1,1,2 --> '>'
-->'0''2' --> OK

Server
+WRITE:0,2,1,1,2,'1''0'
Attachments
Service.csv
(546 Bytes) Downloaded 317 times

ESP_Sun
Posts: 288
Joined: Thu Dec 30, 2021 9:52 am

Re: ESP AT BLE can not enable notification or indication

Postby ESP_Sun » Thu Mar 03, 2022 6:47 am

Hi, It seems that you wrote it wrong here. The target feature value written is CCC, and the AT will automatically correct the written value according to the target's prop.If you are interested, you can read chapter 3.4.5 of this document (https://blog.csdn.net/espressif/article ... /105048087).

staibiii
Posts: 7
Joined: Mon Feb 28, 2022 12:16 pm

Re: ESP AT BLE can not enable notification or indication

Postby staibiii » Mon Mar 07, 2022 10:25 am

ESP_Sun wrote:
Thu Mar 03, 2022 6:47 am
Hi, It seems that you wrote it wrong here. The target feature value written is CCC, and the AT will automatically correct the written value according to the target's prop.If you are interested, you can read chapter 3.4.5 of this document (https://blog.csdn.net/espressif/article ... /105048087).
Thank you for your help. Unfortunately I reveive a timeout tyring to open this link https://blog.csdn.net/espressif/article ... /105048087. Can you please tell me how to enable notifications then. That would be great.

ESP_Sun
Posts: 288
Joined: Thu Dec 30, 2021 9:52 am

Re: ESP AT BLE can not enable notification or indication

Postby ESP_Sun » Mon Mar 07, 2022 11:17 am

3.4.5 Client: Register Notification
On top of read and write, BLE characteristics contain notify and indicate, which are used when the server sends data to the client. For successful data transmission, the client needs to register notification in advance, or in other words write the value of CCC.

For notify, please write 0x1; for indicate, please write 0x2 (to description 0x2902).

For example, in default ESP-AT services, the property of 0xC305 is notify, and the property of 0xC306 is indicate. We write to descriptor 0x2902 in the two characteristics respectively:

Code: Select all

// client
AT+BLEGATTCWR=0,3,6,1,2
>    // write 0x01
OK
// server
+WRITE:0,1,6,1,2,<0x01>,<0x00>

AT+BLEGATTCWR=0,3,7,1,2
>    // write 0x02
OK
// server
+WRITE:0,1,6,1,2,<0x02>,<0x00>
Writing CCC value is necessary for the server to notify and indicate.
Tips

- ESP-AT will internally convert wrong values written to descriptors to the right ones.
3.4.6 Server: Send Data to the Client
Once CCC value has been written, we can send data using notify and indicate.

Code: Select all

// server
AT+BLEGATTSNTFY=0,1,6,8
> //enter 123456789
OK

// client
+NOTIFY:0,3,6,8,12345678

// server
AT+BLEGATTSIND=0,1,7,9
> //enter aaabbbccc
OK

// client
+INDICATE:0,3,7,9,aaabbbccc
For meanings of above parameters, please refer to the command set.(https://docs.espressif.com/projects/esp ... t-commands

staibiii
Posts: 7
Joined: Mon Feb 28, 2022 12:16 pm

Re: ESP AT BLE can not enable notification or indication

Postby staibiii » Wed Mar 09, 2022 11:59 am

Thank you for your help. I really appreciate that. I understood that I have to write the value of the CCC to enable indication or notification. My problem is just that it seems I am write the wrong values. For example:

Code: Select all

//Frist example:
//Client
AT+BLEGATTCWR=0,4,1,1,2
>  <0x00><0x02> //write 0x0002 
OK

//Server
+WRITE:0,2,1,1,2,<0x01>,<0x00> //wrong value! It schould be <0x02>,<0x00>

//Second example:
//Client
AT+BLEGATTCWR=0,4,1,1,2
>  <0x00><0x00> //write 0x0000 
OK

//Server
+WRITE:0,2,1,1,2,<0x01>,<0x00> //wrong value! It schould be <0x00>,<0x00>
Since
The target feature value written is CCC, and the AT will automatically correct the written value according to the target's prop.
What I am doing wronge then?

staibiii
Posts: 7
Joined: Mon Feb 28, 2022 12:16 pm

Re: ESP AT BLE can not enable notification or indication

Postby staibiii » Thu Apr 14, 2022 4:01 pm

Little Update:

I found out that, if the characteristic got the property indication, the value will always be 0x02. If the characteristic got the property notification the value will always be 0x01. If the Characteristic got both of the properties the vaule will be 0x01. So on the one hand I can enable one of them, but on the other hand I can't disable it .

ESP_Sun
Posts: 288
Joined: Thu Dec 30, 2021 9:52 am

Re: ESP AT BLE can not enable notification or indication

Postby ESP_Sun » Tue Apr 19, 2022 3:09 am

You can try compiling AT firmware with the following library (
esp32.rar
(252.25 KiB) Downloaded 368 times
), if the characteristic got the property indication, the value will always be 0x02. If the characteristic got the property notification the value will always be 0x01. If the Characteristic got both of the properties the vaule will be 0x03.

RickARM
Posts: 4
Joined: Tue Jun 06, 2023 6:23 pm

Re: ESP AT BLE can not enable notification or indication

Postby RickARM » Fri Jun 09, 2023 7:00 am

Did you solve the issue? How did you do?
I have same problem:
viewtopic.php?f=2&t=34000

Who is online

Users browsing this forum: No registered users and 12 guests