BLE beacons Receiving #30
Replies: 3 comments 5 replies
-
This library doesn't officially support it, but all the tools you need are there in the fake_ble module. Have a look at the source code for https://github.com/floe/BTLE library. Most importantly, remember that the nRF24L01 can only capture 32 bytes and the BLE payloads occupy a large chunk of that in an arbitrary Mac address and 24-bit CRC (not to mention the required data structures used by various BLE specifications). Last time I printed out all the incoming BLE data, I was overwhelmed and gave up. You will definitely need to write a function that decodes the BLE data structures present in the incoming BLE payload (after comparing the included CRC with the rest of the payload, then dewhitening the payload using |
Beta Was this translation helpful? Give feedback.
-
I put together a example script that should better describe the initial process using a constructed payload from the fake_ble_test example. Please note that I ran this script using my rf24-network branch (2 optional parameters have been added to from nrf24l01_fake_ble_test import * # we'll use some assets from the example
from circuitpython_nrf24l01.fake_ble import crc24_ble, reverse_bits
from circuitpython_nrf24l01.rf24 import address_repr # for readable results
print("Preparing an outgoing payload to examine")
pl = nrf._make_payload(chunk(battery_service.buffer, 0x16))
print("raw payload data including CRC:\n\t", address_repr(pl, False, " "))
white = nrf.whiten(pl)
print("whitened payload data (using active channel):\n\t", address_repr(white, False, " "))
rev = reverse_bits(white)
print("reversed payload data:\n\t", address_repr(rev, False, " "))
print("data is now ready for transmitting to BLE reciever\n")
print("using payload data to re-assemble raw payload data as if it was received")
rev2 = reverse_bits(rev)
print("reversed payload data:\n\t", address_repr(rev2, False, " "))
dewhite = nrf.whiten(rev2)
print("dewhitened payload data (using same active channel):\n\t", address_repr(dewhite, False, " "))
print("comparing CRC from payload to a re-calculated CRC")
print("checksum", "validated" if crc24_ble(dewhite[:-3]) == dewhite[-3:] else "is invalid") This script's output is
From there, you know for sure that the first 8 bytes will be the BLE spec's required flags (first 2 bytes) and the randomly generated 6 byte MAC address (bytes 3 - 8). The last 3 bytes are the CRC checksum. Everything in between is BLE data structures. In fact the second byte (byte 2) is the total size of the BLE data. This size does include the size of the MAC address, but it does not include the 24-bit CRC and the first 2 bytes of the payload. Knowledge for decoding data structuresAll BLE data structures begin with a byte that describes the size of the entire structure (as an
Above is the required flags that describe the BLE device. About Service Data StructuresUsually Service Data structures proceed to have the service data UUID number (in little endian) after the byte about chunk type. The FakeBLE module only uses 3 service data specifications (which all use 2 byte long UUID numbers) because that's all that can be crammed into a 32 byte payload. I used the >>> address_repr(chunk(battery_service.buffer, 0x16), False, " ")
'04 16 0f 18 55'
Non-Service data structuresThe BLE device name and TX-ing PA Level also follow this structure as they are data defined by the BLE general specs (not individual Service Data specs). However, instead of passing 0x16 or 0xFF to >>> chunk(b'fake ble', 0x08)
bytearray(b'\t\x08fake ble')
>>> address_repr(chunk(b'fake ble', 0x08), False, " ")
'09 08 66 61 6b 65 20 62 6c 65' |
Beta Was this translation helpful? Give feedback.
-
Preliminary support for receiving BLE data is now supported in v2.1.0 of this lib. |
Beta Was this translation helpful? Give feedback.
-
Hi,
I am wondering if NRF24L01 can be used to receive other (standard) BLE beacons?
If it is possible, any guidelines to implement it ?
Beta Was this translation helpful? Give feedback.
All reactions