Closed 2bndy5 closed 2 years ago
@wohali I added the ability to set address_length
to 2 bytes when configuring with input value outside [3, 5] domain.
Other more advanced stuff can be done with RF24._reg_write_byte(register_offset, register_value)
yeah, I've been busy adding/improving this lib (yet again)... As always docs are hosted at rtfd.io.
You may notice that the docs' theme has changed slightly. This is due to the use of the new sphinx-immaterial theme. This theme allows for both light and dark themed color palettes (which can be sought from the system settings by the internet browser).
BLE can now receive
the fake_ble module now has a new class called
QueueElement
which is used to decode incoming BLE data as it goes from theFakeBLE
class' newrx_cache
buffer and is saved in the newrx_queue
attribute. The existing example has been updated to demonstrate this additional API (which includes a new overriddenavailable()
&read()
).QueueElement
object will always contain the MAC address of the transmitting BLE deviceQueueElement.data
list (as a bytearray). All supported service data will coexist in thedata
attribute/list as objects that can be used for transmitting BLE data.ServiceData
based classes have their own__repr__()
method that will allow printing human-readable encapsulated data.RF24Network & RF24Mesh
The C++ libraries that were ported to pure python are a freaking beast. Many of the compile time macros used in C++ could not be used in python (same goes for ALL the overloaded C++ functions). Instead, I had to utilize inheritance to limit consumed memory resources, but some C++ features that were hard-coded at compile-time are straight-up dynamic attributes in this lib. Instead of listing all the features, I will list the differences between C++ libs and this pure python lib's modules.
Instead of writing numerous examples that are almost identical, there is only 1 new example for networking. It demonstrates both fragmented and un-fragmented payloads as well as
RF24Network
,RF24Mesh
, andRF24MeshNoMaster
classes. Note, I had to diverge from using the typicalmaster()
andslave()
named functions as to not confuse with network node operations; this example usesemit()
andidle()
functions instead.context manager
As always I've kept compatibility with python's context management system (the
with
statements). Thus you can use the same radio to take a break from networking and quickly do BLE or basic RF24 operations. This will prove even more useful when using the radio to participate in separate networks on different channels and/or using different physical address "seeds".RF24Network
address_prefix
andaddress_suffix
attributes (bothbytearrays
). There is a quick tutorial in the docs' topology page about using different physical address "seeds" for 2 networks coexisting on the same channel.DISABLE_USER_PAYLOADS
exists in this lib as base class thatRF24Network
class inherits from calledRF24NetworkRoutingOnly
. In practice this may be used for routing nodes or possibly RF24Ethernet in the future (I need to better understand TCP/IP protocol first).write(header, message)
function is calledsend()
in this lib due to lack of function overloading, However, users can pass entire frames to be sent using this lib'swrite(frame, traffic_direct)
function.collections
module because it doesn't have what I need in CircuitPython.NETWORK_EXTERNAL_DATA
message types do not get put into their own queue. This may change with the introduction of RF24Ethernet/RF24Gateway in the future.MAX_PAYLOAD_SIZE
is a dynamically set attribute callmax_message_length
bool
attribute calledfragmentation
. Changing this attribute will reduce some memory (but not that much), and also resets themax_message_length
attribute accordingly.begin()
function is basically an attribute in this lib callednode_address
. The RF24Network class' constructor takes thisnode_address
as a required parameter, so there is very little need to set the attribute after instantiation.networkFlags
member is replaced with a private boolean called_parenthood
(which is only used byRF24Mesh.allow_children
member). All othernetworkFlags
are not necessary for this lib (or they were not actually used in the original C++ libs).RF24Mesh
All RF24Network functionality is inherited into RF24Mesh.
MESH_NO_MASTER
macro exists as a base class calledRF24MeshNoMaster
. Obviously, this is meant for nodes that don't need the code that mesh master nodes use.node_address
attribute cannot be set (it is read-only in RF24Mesh) because mesh nodes need to be automatically assigned an address from the mesh network master node per the uniquenode_id
number. Thenode_id
number can be changed though doing so will disconnect the node from the network (if it is connected)dhcp_dict
in this lib's RF24Mesh class. Currently, I'm not supporting persistence on Circuitpython MCUs because it requires a write-accessible file system or using circuitpython'snvm
module (every write to NVM should be carefully controlled by the user because those chips have a limited lifetime of write cycles).dhcp_dict
can be saved/loaded to/from a JSON file. This is not automatically done like it is in the C++ lib however.DHCP()
function is private function in this lib, and it is automatically called when needed on master nodes.Examples revisited
All examples have been slightly modified to use constant-type names for the
SPI_BUS
,CE_PIN
, &CSN_PIN
.New Wrappers
SpiDev
from pypi.org. This module is much faster than using CircuiPython'spureio
module, thus it is encouraged to usespidev.SpiDev
objects instead ofboard.SPI
objects on Linux.