FakeBle¶
rf24_py.FakeBle ¶
FakeBle(radio: RF24)
A class to use the nRF24L01 as a Fake BLE beacon.
See also
This implementation is subject to Limitations.
Use ble_config() to properly configure the radio for
BLE compatibility.
from rf24_py import RF24, FakeBle, ble_config
radio = RF24(22, 0)
radio.begin()
radio.with_config(ble_config())
ble = FakeBle(radio)
radio.print_details()
show_pa_level
property
writable
¶
show_pa_level: bool
Enable or disable the inclusion of the radio's PA level in advertisements.
Enabling this feature occupies 3 bytes of the 18 available bytes in advertised payloads.
name
property
writable
¶
name: str | None
Set or get the BLE device's name for included in advertisements.
Setting a BLE device name will occupy more bytes from the
18 available bytes in advertisements. The exact number of bytes occupied
is the length of the given name string plus 2.
The maximum supported name length is 10 bytes. So, up to 12 bytes (10 + 2) will be used in the advertising payload.
mac_address
property
writable
¶
mac_address: bytes
Set or get the BLE device's MAC address.
A MAC address is required by BLE specifications. Use this attribute to uniquely identify the BLE device.
hop_channel ¶
hop_channel() -> None
Hop the radio's current channel to the next BLE compliant frequency.
Use this function after FakeBle.send() to comply with BLE specifications.
This is not required, but it is recommended to avoid bandwidth pollution.
This function should not be called in RX mode. To ensure proper radio behavior, the caller must ensure that the radio is in TX mode.
len_available ¶
How many bytes are available in an advertisement payload?
The hypothetical parameter shall be the same value passed to FakeBle.send().
In addition to the given hypothetical payload length, this function also
accounts for the current state of FakeBle.name and
FakeBle.show_pa_level.
If the returned value is less than 0, then the hypothetical payload will not
be broadcasted.
send ¶
Send a BLE advertisement
The buf parameter takes a buffer that has been already formatted for
BLE specifications.
See convenient API to
- advertise a Battery's remaining change level: BatteryService
- advertise a Temperature measurement: TemperatureService
- advertise a URL: UrlService
For a custom/proprietary BLE service, the given buf must adopt compliance with BLE specifications.
For example, a buffer of n bytes shall be formed as follows:
| index | value |
|---|---|
0 |
n - 1 |
1 |
0xFF |
2 ... n - 1 |
custom data |
read ¶
read() -> BlePayload | None
Read the first available payload from the radio's RX FIFO
and decode it into a BlePayload.
Warning
The payload must be decoded while the radio is on the same channel that it received the data. Otherwise, the decoding process will fail.
Use RF24.available to
check if there is data in the radio's RX FIFO.
If the payload was somehow malformed or incomplete,
then this function returns an None value.