In this technical video we look into using C++ classes in conjunction with BLE on the ESP32. In this instance, the ESP32 is acting as a BLE Peripheral (server). When a BLE peer connects to our ESP32, the goal is to have our ESP32 start issuing notification messages to "push" value changes to the partner. This sample illustrates push notification.
As if that wasn't fun enough ... we also illustrate the use of "Web Bluetooth". If you aren't familiar with that concept, it is the idea that a browser (Chrome in this case) can act as a BLE Central. When I first heard that notion, I had to think about that for a moment ... so here is the broken down scoop.
Imagine a browser. Imagine a browser downloading a web page (HTML). Imagine the HTML containing JavaScript. Imagine the JavaScript scanning BLE, finding a peripheral, connecting to it ... and then reading values, writing values or receiving notifications. Again ... no C, no C++, no other fancy coding ... just HTML and JavaScript in the browser.
https://www.youtube.com/watch?v=WGozJXuQ8dY
[Video] BLE, C++, Notifications and Web Bluetooth
[Video] BLE, C++, Notifications and Web Bluetooth
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
Re: [Video] BLE, C++, Notifications and Web Bluetooth
Very nice video (per usual) Neil. In reading through the BLE spec, it looks like the server is not supposed to send notifications until the client has requested they be turned on. Do you have a mechanism to see when this happens so the notifications are not sent out before that happens?
I'm working on notifications in my app now and noticed in the trace that the client does indeed do a write to the appropriate handle with 1 or 0 as the value to turn them on and off.
Robin
I'm working on notifications in my app now and noticed in the trace that the client does indeed do a write to the appropriate handle with 1 or 0 as the value to turn them on and off.
Robin
Re: [Video] BLE, C++, Notifications and Web Bluetooth
Howdy Robin,
Aha ... that is where the BLE Characteristic descriptor known as Client Characteristic Configuration comes into play. Bluetooth sure has a lot of bits.
Here is what I think is going on.
In an arbitrary BLE Peripheral, it will:
1) Create a service
2) Create characteristics
3) Create descriptors for those characteristics
4) Start the service
A descriptor can "loosely" by thought off as meta data and control data for the characteristic. Some of the descriptors are architected. One such descriptor is 0x2902 (This is its assigned number .. a 16bit representation of the 128 bit UUID). Its full human name is "Client Characteristic Configuration". We can read about it here:
https://www.bluetooth.com/specification ... ration.xml
I am presuming that before a BLE Peripheral executes a notification or indication, it checks it 0x2902 value to see if it is allowed and, only then can execute the indicate or notify. When a remote peer is prepared to accept notifications ... then it will set the bits in the remote (to it) 0x2902.
In the C++ classes we show in the video, we do indeed have the ability to add descriptors to characteristics. And ... for the most common descriptors, we have already sub-classed those for specialization. That's where the video shows the BLE2902 object that I didn't talk about.
That all said ... I did know I had to add a BLE2902 ... however I didn't know WHY ... and your post that the spec says that the peer should explicitly enable it has now lifted a veil from my eyes. THANK YOU SIR.
Aha ... that is where the BLE Characteristic descriptor known as Client Characteristic Configuration comes into play. Bluetooth sure has a lot of bits.
Here is what I think is going on.
In an arbitrary BLE Peripheral, it will:
1) Create a service
2) Create characteristics
3) Create descriptors for those characteristics
4) Start the service
A descriptor can "loosely" by thought off as meta data and control data for the characteristic. Some of the descriptors are architected. One such descriptor is 0x2902 (This is its assigned number .. a 16bit representation of the 128 bit UUID). Its full human name is "Client Characteristic Configuration". We can read about it here:
https://www.bluetooth.com/specification ... ration.xml
I am presuming that before a BLE Peripheral executes a notification or indication, it checks it 0x2902 value to see if it is allowed and, only then can execute the indicate or notify. When a remote peer is prepared to accept notifications ... then it will set the bits in the remote (to it) 0x2902.
In the C++ classes we show in the video, we do indeed have the ability to add descriptors to characteristics. And ... for the most common descriptors, we have already sub-classed those for specialization. That's where the video shows the BLE2902 object that I didn't talk about.
That all said ... I did know I had to add a BLE2902 ... however I didn't know WHY ... and your post that the spec says that the peer should explicitly enable it has now lifted a veil from my eyes. THANK YOU SIR.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
Re: [Video] BLE, C++, Notifications and Web Bluetooth
While testing my gatt server code, I noticed that it allows me to send the notifications even when they are not requested by the client. I now have to manually keep track of whether the client asked or not.
I was looking for code samples for your video and didn't see any. Do you make these available?
I found some nice examples on the web:
https://github.com/WebBluetoothCG/demos
https://github.com/WebBluetoothCG/ble-t ... al-android
https://googlechrome.github.io/samples/web-bluetooth/
Robin
I was looking for code samples for your video and didn't see any. Do you make these available?
I found some nice examples on the web:
https://github.com/WebBluetoothCG/demos
https://github.com/WebBluetoothCG/ble-t ... al-android
https://googlechrome.github.io/samples/web-bluetooth/
Robin
Re: [Video] BLE, C++, Notifications and Web Bluetooth
Howdy Robin, do you mean Web Bluetooth samples or ESP32 C++ BLE samples?
The former ... you have already found a rich set. The latter, I'm still baking those.
For Web Bluetooth, I found the following article to be especially good:
https://developers.google.com/web/updat ... on-the-web
as well as the base spec:
https://webbluetoothcg.github.io/web-bluetooth/
and a Chrome forum on the subject:
https://groups.google.com/a/chromium.or ... -bluetooth
The former ... you have already found a rich set. The latter, I'm still baking those.
For Web Bluetooth, I found the following article to be especially good:
https://developers.google.com/web/updat ... on-the-web
as well as the base spec:
https://webbluetoothcg.github.io/web-bluetooth/
and a Chrome forum on the subject:
https://groups.google.com/a/chromium.or ... -bluetooth
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
Who is online
Users browsing this forum: Google [Bot] and 189 guests