-
Notifications
You must be signed in to change notification settings - Fork 707
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
Provide raw data settings for advertising and scan response #196
Comments
Howdy, can you clarify some of the wording. What do we mean by "raw data"? Is this a suggested functional enhancement? What would the new/changed API look like? How would it be used by a BLE programmer? |
At the moment advertising data is set "under hood". We can set few parameters with functions like setTXPower, addService, etc. But esp ble stack has capability to set raw value to be advertised with http://esp-idf.readthedocs.io/en/latest/api-reference/bluetooth/esp_gap_ble.html?highlight=config_adv_data_raw#_CPPv231esp_ble_gap_config_adv_data_rawP7uint8_t8uint32_t. In there we dont have known values like name, UUID, TX power etc. just bunch of bytes set by user. More can be found here: https://github.com/espressif/esp-idf/blob/master/examples/bluetooth/gatt_server/main/gatts_demo.c and here https://github.com/espressif/esp-idf/tree/master/examples/bluetooth/ble_ibeacon. I see it in form one or 2 additional functions: |
A suggestion, instead of overloading setAdvertisingRawData(advertisingData) the first would set the advertising data to be the raw data encapsulated in an instance of BLEAdvertisingData while the second call (the one that is passed a nullptr) would clear the raw advertising data resulting in "default" advertising. |
Its not bad idea. But only one type of data can be advertised, raw data or default and user need to make choice, or it can be done by checking if |
As always, I could be horribly wrong on this. It is my understanding that BLE advertised data must be well formed and contains "records" of a finite number of types as described in the BLE specification (Core Specification Supplement - Part A). Each "Record" is composed of:
the records are then concatenated together in memory. The distinct types of records can also be found here: https://www.bluetooth.com/specifications/assigned-numbers/generic-access-profile What this means is that we can create an "advertisement" using one or more of these codes plus data. However, we can't just "make up our own" ... which means that there is a finite number of them. Rather than have users compose the records themselves, we can create a class that is a BLEAdvertisingData with methods corresponding to each one of these types. For example, we see type 0x24 is a browser/web URI ... we could exposed a method on BLEAdvertisingData of the form: setURI(std::string uri) The order in which the "setters" are called would be the order that they are exposed in the raw data. I'm not seeing any obvious reason why the BLE programmer needs to compose their own binary blob of raw data to send when we can increase the abstraction by one level and provide setters for this finite number of architected advertising types. It looks like there are 62 distinct types. We could define the most common ones and add the others on demand as and when users request them. For example:
|
You are corect. Advertising is has finite number of records just like you described. In our case its just 2 records. One is flags, with legth 2 bytes and in most cases value 0x06 and the other record is raw data, with legth n bytes 1 to 28 bytes ( we cant exced 31 bytes in total). Raw data is formed by user. Edit: |
Is there any way to implement iBeacon yet? |
Work has started on raw advertising data and scan response settings. Here is an example of the new API:
At a high level, we have a new class called BLEAdvertisementData. Against an instance of this object we can set the possible records in an advert or scan response. Once done, we can associate the object with advertisement data or the scan response data. Only a couple of the possible records are supported. These currently are:
Others will be added on demand or as time permits. |
Added |
Added |
In principle, we now have exposed all the APIs needed to become an iBeacon. At a high level the logic would be:
|
Could someone give an example of some valid contents for what could go in std::string beaconData? |
See also #271 |
Try this, im not 100% sure, but it should be good: |
Any tips on a concise way of getting 0x0201061AFF004C15020xFDA50693A4E24FB1AFCFC6EB0764782512345678C5 into std::string beaconData? |
By including BLEAdvertising.h you will now find you have a new class called BLEBeacon(). This is a representation of an BLE beacon advert. Example:
|
Thanks for that, I have it running but a beacon scanner app on my phone doesn't detect it. A BLE scanner app does see it though. Has anyone had it working as an ibeacon and willing to share their code? |
Trying out some different ibeacon scanner apps on my phone, another one (iBeaconDetector) gives some more details. It can see the ESP32 but says its not an iBeacon. It dumps out a packet of something that looks like: |
By any chance are you running Android on your phone? If so, can you list the apps you are testing with? We can try and recreate/test. I'm afraid I personally have no Apple products to test with ... and have not actually tried to test Beacon technology ... all Ive been running with has been theory. |
It works now! Change to use the BLEBeacon class instead of the raw bytes and the phone apps now identify it as an iBeacon. Terrific, thanks! Something isn't perfect yet though as the fields don't match what the app sees. I am using Android, trying several apps but this one seems ok - https://play.google.com/store/apps/details?id=de.flurp.beaconscanner.app The code I'm trying with is here: https://github.com/HarringayMakerSpace/ESP32iBeacon/blob/master/esp32iBeacon/esp32iBeacon.ino With the values in that code for uuid/major/minor the phone app shows different values: |
This app still says its not an iBeacon. Also the previously mentioned Beacon Scanner app is actually showing the UUID set in the sketch but the bytes are reversed, in the sketch the uuid is: |
Is it possible to send a beacon "on demand"? i.e. when an input pin changes, send a short beacon containing the state of the pin? |
Yes. You can start and stop advertising whenever you want/need. If you learn more about esp32 you will see that you can put esp32 into deep sleep mode and wake it up from pin and advertise that data for some time and get back to deep sleep to conserve battery. |
If I keep the esp32 awake and running, what is the minimum time possible between the pin change and the beacon actually going out? Would I have to stop & restart the advertising? How soon after advertising start does the first beacon actually get sent? |
Well, you are asking very hard questions i dont know answer. I only can answer on one question:
Other questions are hard to answer because it vary and depends on your code. If you turn off debugging then it will be faster, i can only guess it can be between 1-3s when you can receive advertising packet after wake up(just guessing). |
The function setManufacturerData(std::string) has parameter std::string. I need to advertise any binary array like: {0x03, 0x00, 0x00,0x4C}. Is it possible? With std::string only 0x03 will be advertised. |
I think the only option is to modify library. Few weeks ago i did it myself or i changed advertised device to read manufacturer data (dont remember now). https://stackoverflow.com/questions/2845769/can-a-stdstring-contain-embedded-nulls You can always check with |
I think the library modification will be very useful. The alternative way
is to send as 2 ASCII characters for each byte but this doubles payload!
чт, 17 окт. 2019 г. в 00:19, chegewara <notifications@github.com>:
… I think the only option is to modify library.
Few weeks ago i did it myself or i changed advertised device to read
manufacturer data (dont remember now).
https://stackoverflow.com/questions/2845769/can-a-stdstring-contain-embedded-nulls
You can always check with getPayload().length() how many bytes has been
set in advertisement data object (BLEAdvertisementData).
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#196?email_source=notifications&email_token=ANQIAB33WLETMRU3LMNZKRLQO6APLA5CNFSM4EDRILZKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBN7BLY#issuecomment-542896303>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ANQIABZIWEZDL3TGFCTWTT3QO6APLANCNFSM4EDRILZA>
.
|
Hello,
This way, I'm able in my loop() function to recover the data, and "recreate" it as much as I want
Maybe something you could look at implementing ? (if it does not create to many complications) |
BLE ibeacon requires to advertise raw data and such it requires to add this functionality(optionaly) to resolve issue #195.
The text was updated successfully, but these errors were encountered: