### Install Package from Source Source: https://github.com/nrf24/pyrf24/blob/main/README.rst Install the package from the current directory after configuration. ```bash python -m pip install . -v ``` -------------------------------- ### Build and install from source Source: https://github.com/nrf24/pyrf24/blob/main/README.rst Commands to clone the repository and install the package locally. ```bash git clone --recurse-submodules https://github.com/nRF24/pyRF24.git cd pyRF24 python -m pip install . -v ``` -------------------------------- ### Install Built Wheel Source: https://github.com/nrf24/pyrf24/blob/main/README.rst Install the generated wheel file using pip. ```bash python -m pip install dist/pyrf24-MAJOR.MINOR.PATCH-cp3X-cp3X-linux_ARCH.whl ``` -------------------------------- ### Install Build Dependencies Source: https://github.com/nrf24/pyrf24/blob/main/README.rst Install required build-time dependencies from the repository root. ```bash python -m pip install -r requirements-build.txt ``` -------------------------------- ### Install Sphinx requirements Source: https://github.com/nrf24/pyrf24/blob/main/README.rst Install the necessary Python packages for building documentation. ```bash python -m pip install -r docs/requirements.txt ``` -------------------------------- ### Install pyRF24 via pip Source: https://github.com/nrf24/pyrf24/blob/main/README.rst Standard installation command for the pyRF24 package from PyPI. ```python python -m pip install pyrf24 ``` -------------------------------- ### RF24 Multiceiver Demo Example Source: https://github.com/nrf24/pyrf24/blob/main/docs/examples.rst An example demonstrating the 'Multiceiver' feature to receive data from multiple transmitting nRF24L01 transceivers simultaneously. ```python from pyrf24 import RF24 # Initialize the RF24 module radio = RF24(22, 0) if not radio.begin(): raise IOError("NRF24L01 hardware not found") radio.print_details() # Configure radio for multiceiver mode radio.set_channel(76) radio.set_pa_level(RF24.PA_MAX) radio.set_datarate(RF24.BR_2MBPS) # Open reading pipes for multiple clients radio.open_reading_pipe(1, b'node1') radio.open_reading_pipe(2, b'node2') radio.open_reading_pipe(3, b'node3') radio.open_reading_pipe(4, b'node4') radio.open_reading_pipe(5, b'node5') radio.start_listening() print("Radio configured for multiceiver mode. Listening for data from multiple nodes...") while True: if radio.available(): # Check which pipe the data came from pipe_num = radio.pipe_num buffer = radio.read() print('Received from pipe {}: {}'.format(pipe_num, buffer.decode('utf-8'))) # Send an acknowledgement back to the sender radio.write(b'ACK') print('Sent ACK') radio.delay_ms(10) ``` -------------------------------- ### Install Graphviz Source: https://github.com/nrf24/pyrf24/blob/main/README.rst System command to install the Graphviz dependency required for documentation graphs. ```shell sudo apt-get install graphviz ``` -------------------------------- ### Install build dependencies Source: https://github.com/nrf24/pyrf24/blob/main/README.rst Required when building from source or on architectures not supported by pre-built binary wheels. ```bash sudo apt install python3-dev cmake ``` -------------------------------- ### Generic Network Test Example Source: https://github.com/nrf24/pyrf24/blob/main/docs/examples.rst A generic example demonstrating the differences in code for using RF24Network or RF24Mesh APIs. This helps in understanding how to switch between the two. ```python from pyrf24 import RF24, RF24Network, RF24Mesh # Initialize the RF24 module radio = RF24(22, 0) # Initialize both network and mesh (for comparison) network = RF24Network(radio) mesh = RF24Mesh(radio) if not radio.begin(): raise IOError("NRF24L01 hardware not found") radio.print_details() # Configure common settings radio.set_channel(76) radio.set_pa_level(RF24.PA_MAX) radio.set_datarate(RF24.BR_2MBPS) # --- RF24Network Example --- print("--- RF24Network Example ---") network.begin() network.set_channel(76) # Ensure same channel # Example: Send a message using RF24Network # network.send(RF24Network.NODE_BROADCAST, b'Network Test Message') # print("Sent message via RF24Network") # --- RF24Mesh Example --- print("\n--- RF24Mesh Example ---") mesh.begin() mesh.set_channel(76) # Ensure same channel # Example: Send a message using RF24Mesh # mesh.send(RF24Mesh.NODE_BROADCAST, b'Mesh Test Message') # print("Sent message via RF24Mesh") print("\nGeneric network test setup complete. Uncomment send commands to test.") while True: # You would typically choose one network to operate with # For demonstration, we can check availability in both if needed if network.available(): message = network.read() print(f"[Network] Received from {message.from_node}: {message.data.decode('utf-8')}") if mesh.available(): message = mesh.read() print(f"[Mesh] Received from {message.from_node}: {message.data.decode('utf-8')}") network.update() mesh.update() network.delay_ms(10) ``` -------------------------------- ### Basic RF24 Usage Example Source: https://github.com/nrf24/pyrf24/blob/main/docs/examples.rst A fundamental example showcasing the basic usage of the RF24 class for radio communication. ```python from pyrf24 import RF24 # Initialize the RF24 module radio = RF24(22, 0) # Using BCM pin numbers for CE and CSN # Start the radio if not radio.begin(): raise IOError("NRF24L01 hardware not found") radio.print_details() # Print details about the radio configuration # Set the transmit power and data rate radio.set_pa_level(RF24.PA_MAX) radio.set_datarate(RF24.BR_2MBPS) # Set the channel and addresses radio.set_channel(76) radio.open_reading_pipe(1, b'node1') radio.open_writing_pipe(b'node2') # Start listening for data radio.start_listening() print("Radio initialized. Listening for data...") while True: if radio.available(): # Read the received data buffer = radio.read() print('Received: {}'.format(buffer.decode('utf-8'))) # Send an acknowledgement (optional) radio.write(b'ACK') print('Sent ACK') # Example of sending data (uncomment to send) # if radio.write(b'Hello World'): # print('Sent Hello World successfully') # else: # print('Send failed') # Add a small delay to prevent busy-waiting radio.delay_ms(10) ``` -------------------------------- ### RF24Network Master Node Example Source: https://github.com/nrf24/pyrf24/blob/main/docs/examples.rst A basic example of using the RF24Network library to operate an nRF24L01 as the master node in a network. This node manages the network. ```python from pyrf24 import RF24, RF24Network # Initialize the RF24 module radio = RF24(22, 0) # Initialize the network network = RF24Network(radio) if not radio.begin(): raise IOError("NRF24L01 hardware not found") radio.print_details() # Configure network settings network.begin() network.set_channel(76) network.set_pa_level(RF24.PA_MAX) network.set_datarate(RF24.BR_2MBPS) # Master node ID is 0 print("Starting RF24Network master node (ID 0)") while True: # Check for incoming messages from child nodes if network.available(): message = network.read() print(f"Received message from node {message.from_node}: {message.data.decode('utf-8')}") # Example: Reply to the child node reply_payload = f"ACK from Master Node 0".encode('utf-8') network.send(message.from_node, reply_payload) print(f"Sent ACK to node {message.from_node}") # Example: Broadcast a message to all child nodes periodically # if network.send(RF24Network.NODE_BROADCAST, b'Hello Children!'): # print("Broadcasted message to all nodes") # else: # print("Failed to broadcast message") network.update() # Update network status network.delay_ms(10) ``` -------------------------------- ### RF24Network Child Node Example Source: https://github.com/nrf24/pyrf24/blob/main/docs/examples.rst A basic example of using the RF24Network library to operate an nRF24L01 as a non-master (child) node in a network. Requires a master node to be running. ```python from pyrf24 import RF24, RF24Network # Initialize the RF24 module radio = RF24(22, 0) # Initialize the network network = RF24Network(radio) if not radio.begin(): raise IOError("NRF24L01 hardware not found") radio.print_details() # Configure network settings network.begin() network.set_channel(76) network.set_pa_level(RF24.PA_MAX) network.set_datarate(RF24.BR_2MBPS) # Assign a node ID (0 is typically the master) # Child nodes should have IDs greater than 0 node_id = 1 print(f"Starting RF24Network child node with ID: {node_id}") while True: # Check for incoming messages if network.available(): message = network.read() print(f"Received message from node {message.from_node}: {message.data.decode('utf-8')}") # Example: Reply to the master node if message.from_node == 0: # Assuming master is node 0 reply_payload = f"Hello Master from Node {node_id}".encode('utf-8') network.send(RF24Network.NODE_BROADCAST, reply_payload) # Send to broadcast print(f"Sent reply to broadcast") # Example: Send a message to the master node periodically # if network.send(0, f"Ping from Node {node_id}".encode('utf-8')): # print(f"Sent ping to master") # else: # print(f"Failed to send ping to master") network.update() # Update network status network.delay_ms(10) ``` -------------------------------- ### RF24 Streaming Data Example Source: https://github.com/nrf24/pyrf24/blob/main/docs/examples.rst A simple example illustrating how to stream data using the RF24 class. This is useful for continuous data transfer. ```python from pyrf24 import RF24 # Initialize the RF24 module radio = RF24(22, 0) if not radio.begin(): raise IOError("NRF24L01 hardware not found") radio.print_details() # Configure radio for streaming radio.set_channel(76) radio.set_pa_level(RF24.PA_MAX) radio.set_datarate(RF24.BR_2MBPS) radio.open_writing_pipe(b'stream') print("Radio configured for streaming data.") counter = 0 while True: # Prepare data to stream data_to_stream = f"Data packet {counter}".encode('utf-8') # Write the data if radio.write(data_to_stream): print('Sent: {}'.format(data_to_stream.decode('utf-8'))) counter += 1 else: print('Send failed') radio.delay_ms(100) # Adjust delay as needed for streaming rate ``` -------------------------------- ### Install gpiod dependency Source: https://github.com/nrf24/pyrf24/blob/main/README.rst Required only when using the radio's IRQ pin for interrupt-based configurations. ```bash sudo apt install python3-dev pip install gpiod ``` -------------------------------- ### RF24Mesh Child Node Example Source: https://github.com/nrf24/pyrf24/blob/main/docs/examples.rst An example of using the RF24Mesh library to operate an nRF24L01 as a child node in a mesh network. This node will connect to the mesh. ```python from pyrf24 import RF24, RF24Mesh # Initialize the RF24 module radio = RF24(22, 0) # Initialize the mesh mesh = RF24Mesh(radio) if not radio.begin(): raise IOError("NRF24L01 hardware not found") radio.print_details() # Configure mesh settings mesh.begin() mesh.set_channel(76) mesh.set_pa_level(RF24.PA_MAX) mesh.set_datarate(RF24.BR_2MBPS) print("Starting RF24Mesh child node.") while True: # Check for incoming messages if mesh.available(): message = mesh.read() print(f"Received message from node {message.from_node}: {message.data.decode('utf-8')}") # Example: Reply to the sender reply_payload = f"ACK from Mesh Node".encode('utf-8') mesh.send(message.from_node, reply_payload) print(f"Sent ACK to node {message.from_node}") # Example: Send a message to the master node periodically # if mesh.send(mesh.address_master(), b'Ping from Mesh Node'): # print("Sent ping to master") # else: # print("Failed to send ping to master") mesh.update() # Update mesh status mesh.delay_ms(10) ``` -------------------------------- ### Fake BLE Beacon Example Source: https://github.com/nrf24/pyrf24/blob/main/docs/examples.rst An example demonstrating how to use the nRF24L01 as a fake BLE beacon. This involves sending specific data packets that mimic BLE advertising. ```python from pyrf24 import RF24 # Initialize the RF24 module radio = RF24(22, 0) if not radio.begin(): raise IOError("NRF24L01 hardware not found") radio.print_details() # Configure radio for broadcasting (like a BLE beacon) radio.set_channel(76) radio.set_pa_level(RF24.PA_MAX) radio.set_datarate(RF24.BR_2MBPS) radio.open_writing_pipe(b'beacon') # Use a fixed address for broadcasting # Example BLE advertising data (replace with your actual data) # This is a simplified representation ble_data = b'\x02\x01\x06\x11\xFF\x4C\x00\x02\x15\xCA\xFE\xBE\xEF\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C' print("Starting fake BLE beacon...") while True: # Send the BLE advertising data if radio.write(ble_data): print('Sent BLE beacon data') else: print('Send failed') radio.delay_ms(1000) # Send beacon data every second ``` -------------------------------- ### RF24 Manual Acknowledgements Example Source: https://github.com/nrf24/pyrf24/blob/main/docs/examples.rst Shows how to receive a payload and then send a responding payload as a manual acknowledgement, without using the hardware ACK payload feature. ```python from pyrf24 import RF24 # Initialize the RF24 module radio = RF24(22, 0) if not radio.begin(): raise IOError("NRF24L01 hardware not found") radio.print_details() # Configure radio for receiving radio.set_channel(76) radio.set_pa_level(RF24.PA_MAX) radio.set_datarate(RF24.BR_2MBPS) radio.open_reading_pipe(1, b'serv1') radio.start_listening() print("Radio configured for manual acknowledgements.") while True: if radio.available(): # Read the received data buffer = radio.read() print('Received: {}'.format(buffer.decode('utf-8'))) # Prepare and send a manual acknowledgement payload ack_payload = b'Manual ACK from server' if radio.write(ack_payload): print('Manual ACK sent successfully') else: print('Failed to send manual ACK') radio.delay_ms(10) ``` -------------------------------- ### RF24Mesh Master Node Example Source: https://github.com/nrf24/pyrf24/blob/main/docs/examples.rst An example of using the RF24Mesh library to operate an nRF24L01 as the master node in a mesh network. This node acts as the central point for the mesh. ```python from pyrf24 import RF24, RF24Mesh # Initialize the RF24 module radio = RF24(22, 0) # Initialize the mesh mesh = RF24Mesh(radio) if not radio.begin(): raise IOError("NRF24L01 hardware not found") radio.print_details() # Configure mesh settings mesh.begin() mesh.set_channel(76) mesh.set_pa_level(RF24.PA_MAX) mesh.set_datarate(RF24.BR_2MBPS) print("Starting RF24Mesh master node.") while True: # Check for incoming messages from child nodes if mesh.available(): message = mesh.read() print(f"Received message from node {message.from_node}: {message.data.decode('utf-8')}") # Example: Reply to the child node reply_payload = f"ACK from Mesh Master".encode('utf-8') mesh.send(message.from_node, reply_payload) print(f"Sent ACK to node {message.from_node}") # Example: Broadcast a message to all connected nodes periodically # if mesh.send(RF24Mesh.NODE_BROADCAST, b'Hello Mesh Nodes!'): # print("Broadcasted message to all mesh nodes") # else: # print("Failed to broadcast message") mesh.update() # Update mesh status mesh.delay_ms(10) ``` -------------------------------- ### RF24 Interrupt Configuration Example Source: https://github.com/nrf24/pyrf24/blob/main/docs/examples.rst Demonstrates how to use the nRF24L01's IRQ pin to catch different interrupt request events. This allows for event-driven communication. ```python from pyrf24 import RF24 import RPi.GPIO as GPIO import time # Define the IRQ pin (example using BCM numbering) IRQ_PIN = 24 # Initialize the RF24 module radio = RF24(22, 0) if not radio.begin(): raise IOError("NRF24L01 hardware not found") radio.print_details() # Configure radio for receiving radio.set_channel(76) radio.set_pa_level(RF24.PA_MAX) radio.set_datarate(RF24.BR_2MBPS) radio.open_reading_pipe(1, b'int') # Setup GPIO for IRQ pin GPIO.setmode(GPIO.BCM) GPIO.setup(IRQ_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Callback function for IRQ def irq_handler(channel): radio.what_interrupt() # Check which interrupt occurred if radio.interrupt_has_rx_dr(): print("RX Data Ready interrupt detected!") buffer = radio.read() print('Received: {}'.format(buffer.decode('utf-8'))) radio.clear_interrupts_rx_dr() # Clear the interrupt flag elif radio.interrupt_has_tx_ds(): print("TX Data Sent interrupt detected!") radio.clear_interrupts_tx_ds() # Clear the interrupt flag elif radio.interrupt_has_max_rt(): print("Maximum Retransmission interrupt detected!") radio.clear_interrupts_max_rt() # Clear the interrupt flag # Add event detection on the IRQ pin GPIO.add_event_detect(IRQ_PIN, GPIO.FALLING, callback=irq_handler, bouncetime=100) # Enable interrupts radio.set_interrupts(True, True, True) radio.start_listening() print("Radio configured for interrupts. Waiting for events...") try: while True: time.sleep(1) # Keep the script running except KeyboardInterrupt: print("Exiting...") finally: GPIO.cleanup() ``` -------------------------------- ### RF24 Acknowledgement Payload Example Source: https://github.com/nrf24/pyrf24/blob/main/docs/examples.rst Demonstrates how to attach an Acknowledgement (ACK) payload to automatically generated ACK packets. ```python from pyrf24 import RF24 # Initialize the RF24 module radio = RF24(22, 0) if not radio.begin(): raise IOError("NRF24L01 hardware not found") radio.print_details() # Configure radio for receiving with ACK payloads radio.set_channel(76) radio.set_pa_level(RF24.PA_MAX) radio.set_datarate(RF24.BR_2MBPS) radio.open_reading_pipe(1, b'serv1') radio.start_listening() print("Radio configured for receiving with ACK payloads.") while True: if radio.available(): # Read the received data buffer = radio.read() print('Received: {}'.format(buffer.decode('utf-8'))) # Prepare the ACK payload ack_payload = b'ACK_DATA_FROM_SERVER' # Attach the ACK payload to the next ACK packet if radio.write(ack_payload): print('ACK payload sent successfully') else: print('Failed to send ACK payload') radio.delay_ms(10) ``` -------------------------------- ### Build documentation Source: https://github.com/nrf24/pyrf24/blob/main/README.rst Commands to navigate to the docs directory and execute the Sphinx build process. ```bash cd docs sphinx-build -E -W . _build ``` -------------------------------- ### Build and Clean Package Artifacts Source: https://github.com/nrf24/pyrf24/blob/main/README.rst Commands to build the wheel and purge previous build artifacts. ```bash python -m pip wheel -w dist . ``` ```bash rm -r build/ dist/ ``` -------------------------------- ### Configure CMake Build Arguments Source: https://github.com/nrf24/pyrf24/blob/main/README.rst Set environment variables to specify RF24 drivers, debug flags, or GPIO chip configurations before building. ```bash export CMAKE_ARGS="-DRF24_DRIVER=RPi" ``` ```bash export CMAKE_ARGS="-DRF24MESH_DEBUG=ON -DRF24NETWORK_DEBUG=ON" ``` ```bash export CMAKE_ARGS="-DRF24_LINUX_GPIO_CHIP=/dev/gpiochip4" ``` -------------------------------- ### Migration Import Patterns Source: https://github.com/nrf24/pyrf24/blob/main/README.rst Comparison of import statements between old individual wrappers and the unified pyrf24 package. ```python from RF24 import RF24, RF24_PA_LOW ``` ```python from pyrf24 import RF24, RF24_PA_LOW ``` ```python from RF24 import RF24 from RF24Network import RF24Network, RF24NetworkHeader ``` ```python from pyrf24 import RF24, RF24Network, RF24NetworkHeader ``` ```python from RF24 import RF24 ``` -------------------------------- ### RF24Mesh Class - Basic API Source: https://github.com/nrf24/pyrf24/blob/main/docs/rf24_mesh_api.rst Core methods for initializing and managing the RF24Mesh node. ```APIDOC ## RF24Mesh Class - Basic API ### Description Provides fundamental methods for initializing and operating an RF24Mesh node. ### Methods - `__init__()`: Constructor for the RF24Mesh class. - `begin()`: Initializes the mesh network. - `update()`: Updates the mesh network status. - `write(message, node_id)`: Writes a message to a specific node. - `renew_address()`: Renews the node's address within the mesh. ### Attributes - `node_id`: The unique identifier for the current node. ``` -------------------------------- ### Importing pyrf24 modules Source: https://github.com/nrf24/pyrf24/blob/main/README.rst Initial module imports for RF24 functionality. ```python from RF24Network import RF24Network from RF24Mesh import RF24Mesh ``` ```python from pyrf24 import RF24, RF24Network, RF24Mesh ``` -------------------------------- ### API Naming Conventions Source: https://github.com/nrf24/pyrf24/blob/main/README.rst Demonstrates the availability of both PEP8-compliant snake_case and legacy camelCase methods. ```python radio.print_details() # documented # can also be invoked as radio.printDetails() # not documented ``` -------------------------------- ### Property-based API Access Source: https://github.com/nrf24/pyrf24/blob/main/README.rst Shows how parameterless C++ functions are wrapped as class properties. ```python radio.listen = False # is equivalent to radio.stopListening() # not documented radio.listen = True # is equivalent to radio.startListening() # not documented ``` -------------------------------- ### External Systems or Applications Source: https://github.com/nrf24/pyrf24/blob/main/docs/rf24_network_api.rst Configuration for integrating with external systems and handling system messages. ```APIDOC ## External Systems or Applications ### Description Attributes related to external system integration and network message flags. ### Attributes - `return_sys_msgs` (bool): Whether to return system messages. - `network_flags` (int): Flags for network behavior. ``` -------------------------------- ### RF24Network Class - Basic API Source: https://github.com/nrf24/pyrf24/blob/main/docs/rf24_network_api.rst Provides an overview of the fundamental methods for interacting with the RF24Network. ```APIDOC ## RF24Network Class - Basic API ### Description Basic methods for initializing and managing the RF24Network. ### Methods - `__init__()`: Initializes the RF24Network. - `begin()`: Starts the network. - `update()`: Updates the network status. - `available()`: Checks if there is an available message. - `peek()`: Peeks at the next message without reading it. - `read()`: Reads the next available message. - `write(message, header)`: Writes a message to the network. ``` -------------------------------- ### Service Data Classes Source: https://github.com/nrf24/pyrf24/blob/main/docs/ble_api.rst Documentation for abstract parent and derivative children classes related to BLE Service Data. ```APIDOC ## Service Related Classes ### Abstract Parent: `pyrf24.fake_ble.ServiceData` #### Description An abstract base class for service data in BLE. #### Members - `__len__()`: Returns the length of the service data. - `__repr__()`: Returns a string representation of the service data. - `data`: The raw data payload of the service. ### Service Data UUID Numbers Constants representing 16-bit UUID numbers for common BLE services: - `TEMPERATURE_UUID` = 0x1809 - `BATTERY_UUID` = 0x180F - `EDDYSTONE_UUID` = 0xFEAA ### Derivative Children #### `pyrf24.fake_ble.TemperatureServiceData` ##### Description Represents temperature service data in BLE. ##### Members - `data`: The temperature data. #### `pyrf24.fake_ble.BatteryServiceData` ##### Description Represents battery service data in BLE. ##### Members - `data`: The battery level data. #### `pyrf24.fake_ble.UrlServiceData` ##### Description Represents URL service data in BLE. ##### Members - `pa_level_at_1_meter`: Power level at 1 meter. - `data`: The URL data. ``` -------------------------------- ### pyrf24.fake_ble Module Overview Source: https://github.com/nrf24/pyrf24/blob/main/docs/ble_api.rst This section covers the core components and helper functions within the pyrf24.fake_ble module. ```APIDOC ## pyrf24.fake_ble Module ### Description Provides functionality to use the nRF24 radio as a fake Bluetooth Low Energy (BLE) Beacon. ### Module Contents #### Helper Functions - `address_repr()`: Represents a BLE address. - `swap_bits()`: Swaps bits within a byte. - `reverse_bits()`: Reverses the order of bits in a byte. - `crc24_ble()`: Calculates the BLE CRC-24 checksum. - `chunk()`: Chunks data into specified sizes. - `whitener()`: Applies a whitener function to data. #### Data - `BLE_FREQ`: The frequency used for BLE communication. ``` -------------------------------- ### QueueElement Class Source: https://github.com/nrf24/pyrf24/blob/main/docs/ble_api.rst Details about the QueueElement class used for managing data in the BLE queue. ```APIDOC ## pyrf24.fake_ble.QueueElement ### Description A class representing an element in the BLE queue. ### Members - `__init__(self, data, address)`: Initializes a QueueElement. - `data`: The data payload of the queue element. - `address`: The target address for the queue element. ``` -------------------------------- ### Clean build artifacts Source: https://github.com/nrf24/pyrf24/blob/main/README.rst Removes previous build files to ensure a clean state for subsequent build attempts. ```bash rm -r build/ dist/ ``` -------------------------------- ### RF24 Class - Basic Functionality Source: https://github.com/nrf24/pyrf24/blob/main/docs/rf24_api.rst Provides methods for basic radio operations such as initialization, listening, reading, and writing data. ```APIDOC ## RF24 Class - Basic Functionality ### Description This section covers the fundamental methods for interacting with the RF24 radio module, including initialization, starting and stopping listening modes, checking for available data, and reading/writing data payloads. ### Methods - `__init__()`: Constructor for the RF24 class. - `begin()`: Initializes the RF24 radio module. - `stop_listening()`: Stops the radio from listening for incoming data. - `start_listening()`: Starts the radio listening for incoming data. - `available()`: Checks if there is any data available to be read. - `read()`: Reads a data payload from the radio's buffer. - `write(data)`: Writes a data payload to the radio's buffer for transmission. - `open_tx_pipe(address)`: Opens a transmission pipe to a specified address. - `open_rx_pipe(pipe_number, address)`: Opens a reception pipe on a specified pipe number and address. ### Attributes - `listen` (bool): A boolean indicating whether the radio is currently in listening mode. ### Request Example ```python from pyrf24 import RF24 radio = RF24(22, 0) radio.begin() radio.open_rx_pipe(1, b'1Node') radio.start_listening() if radio.available(): data = radio.read() print(f"Received: {data}") radio.write(b'Hello World!') ``` ### Response Example ```json { "status": "success", "data_received": "Hello World!" } ``` ``` -------------------------------- ### FakeBLE Class Source: https://github.com/nrf24/pyrf24/blob/main/docs/ble_api.rst Information about the FakeBLE class for emulating BLE beacons. ```APIDOC ## pyrf24.fake_ble.FakeBLE ### Description Emulates a Bluetooth Low Energy (BLE) beacon using the nRF24 radio. ### Members - `__init__(self, spi, ce_pin, payload_size, freq, address, tx_power, data_rate, channel, fake_ble_instance=None)`: Initializes the FakeBLE object. - `power`: Sets the transmission power. - `data_rate`: Sets the data rate. - `channel`: Sets the communication channel. - `address`: Sets the radio address. - `payload_size`: Sets the payload size. - `freq`: Sets the frequency. - `ce_pin`: Sets the CE pin. - `spi`: Sets the SPI interface. - `fake_ble_instance`: An optional existing FakeBLE instance. - `start_beacon(self, service_data)`: Starts broadcasting a BLE beacon with the given service data. - `stop_beacon(self)`: Stops broadcasting the BLE beacon. - `send_packet(self, data, address)`: Sends a single packet of data to a specific address. - `receive_packet(self, timeout=None)`: Receives a packet of data. - `available(self)`: Checks if there are any received packets available. - `read_payload(self)`: Reads the payload of a received packet. - `what_happened(self)`: Returns a list of events that occurred. - `flush_rx(self)`: Clears the receive buffer. - `flush_tx(self)`: Clears the transmit buffer. - `power_down(self)`: Powers down the radio. - `power_up(self)`: Powers up the radio. - `set_address_width(self, address_width)`: Sets the address width (restricted when using FakeBLE). - `set_crc_length(self, crc_length)`: Sets the CRC length (restricted when using FakeBLE). - `open_rx_pipe(self, pipe, address)`: Opens an RX pipe (restricted when using FakeBLE). - `open_tx_pipe(self, address)`: Opens a TX pipe (restricted when using FakeBLE). - `start_listening(self)`: Starts listening for incoming data. - `stop_listening(self)`: Stops listening for incoming data. - `write_ack_payload(self, pipe, data)`: Writes an ACK payload (restricted when using FakeBLE). - `enable_dynamic_payloads(self, enable)`: Enables dynamic payloads (restricted when using FakeBLE). - `enable_auto_ack(self, enable)`: Enables auto ACK (restricted when using FakeBLE). ``` -------------------------------- ### RF24Network Constants Source: https://github.com/nrf24/pyrf24/blob/main/docs/rf24_network_api.rst Predefined constants for message types and network limits. ```APIDOC ## RF24Network Constants ### Description Module-level constants for message types, limits, and system messages. ### Constants - `MAX_USER_DEFINED_HEADER_TYPE` (int): Maximum value for user-defined message types. - `MAX_PAYLOAD_SIZE` (int): Maximum size for fragmented network frames. - `NETWORK_ADDR_RESPONSE` (int): System message type for address responses. - `NETWORK_PING` (int): System message type for ping requests. - `EXTERNAL_DATA_TYPE` (int): Type for messages intended for external systems. - `NETWORK_FIRST_FRAGMENT` (int): Indicates the first fragment of a fragmented message. - `NETWORK_MORE_FRAGMENTS` (int): Indicates a fragmented message with more fragments to follow. - `NETWORK_LAST_FRAGMENT` (int): Indicates the last fragment of a fragmented message. - `NETWORK_ACK` (int): System message type for acknowledging successful transmission. ``` -------------------------------- ### RF24 Class - Advanced Functionality Source: https://github.com/nrf24/pyrf24/blob/main/docs/rf24_api.rst Details advanced features including pipe management, status checking, and debugging utilities. ```APIDOC ## RF24 Class - Advanced Functionality ### Description This section covers advanced features of the RF24 class, such as managing all pipes, checking the validity and connection status of the chip, and utilizing various debugging tools. ### Methods - `toggle_all_pipes()`: Toggles the state of all configured pipes. - `is_valid()`: Checks if the RF24 chip is valid. - `is_chip_connected()`: Checks if the RF24 chip is connected. - `what_happened()`: Returns a status code indicating the last event. - `update()`: Updates the radio's internal state. - `set_status_flags(flags)`: Sets specific status flags for the radio. - `get_status_flags()`: Retrieves the current status flags of the radio. - `clear_status_flags()`: Clears all status flags. - `print_status()`: Prints the current status of the radio. - `print_details()`: Prints detailed information about the radio configuration. - `print_pretty_details()`: Prints detailed information in a human-readable format. - `sprintf_pretty_details()`: Returns a string with detailed radio information. - `get_arc()`: Gets the Auto Retransmission Count. - `write_ack_payload(pipe, data)`: Writes a payload to be sent in the acknowledgement of a received packet. - `write_fast(data)`: Writes data using a fast transmission method. - `reuse_tx()`: Reuses the last transmitted packet for transmission. - `write_blocking(data)`: Writes data and waits for transmission to complete. - `start_fast_write(data)`: Starts a fast transmission. - `start_write(data)`: Starts a standard transmission. - `tx_standby()`: Puts the transmitter into standby mode. - `flush_tx()`: Flushes the transmit FIFO buffer. - `flush_rx()`: Flushes the receive FIFO buffer. - `start_const_carrier()`: Starts transmitting a constant carrier signal. - `stop_const_carrier()`: Stops transmitting a constant carrier signal. - `available_pipe()`: Returns the pipe number of the received data. - `close_rx_pipe(pipe_number)`: Closes a specific receive pipe. - `set_retries(delay, count)`: Sets the auto retransmission delay and count. - `mask_irq(irq_flags)`: Masks specific interrupt flags. - `set_auto_ack(pipe, enable)`: Enables or disables auto-acknowledgement for a specific pipe. - `enable_dynamic_ack()`: Enables dynamic acknowledgement payloads. - `set_pa_level(level)`: Sets the power amplifier level. - `set_radiation(config)`: Configures radiation settings. ### Attributes - `is_plus_variant` (bool): True if the radio is a Plus variant. - `failure_detected` (bool): True if a failure has been detected. - `ce_pin` (int): The CE (Chip Enable) pin number. - `rx_fifo_full` (bool): True if the receive FIFO buffer is full. - `is_fifo(fifo_type)`: Checks if a specific FIFO buffer is enabled. - `rpd` (bool): Indicates if a signal is detected by the Radio Power Detector. - `address_width` (int): The width of the radio's address in bytes. - `channel` (int): The current radio channel (frequency). - `tx_delay` (int): The delay between transmissions in microseconds. - `payload_size` (int): The fixed payload size in bytes. - `dynamic_payloads` (bool): True if dynamic payload sizes are enabled. - `ack_payloads` (bool): True if acknowledgement payloads are enabled. - `pa_level` (int): The current power amplifier level. - `data_rate` (int): The current data rate of the radio. - `crc_length` (int): The current CRC length setting. ### Request Example ```python from pyrf24 import RF24 radio = RF24(22, 0) radio.begin() # Set power amplifier level radio.pa_level = 3 # RF24_PA_MAX # Set data rate radio.data_rate = 2 # RF24_2MBPS # Enable dynamic payloads radio.dynamic_payloads = True # Print detailed status radio.print_details() ``` ### Response Example ```json { "status": "configuration_updated", "pa_level": 3, "data_rate": 2, "dynamic_payloads": true } ``` ``` -------------------------------- ### RF24Mesh Class - Advanced API Source: https://github.com/nrf24/pyrf24/blob/main/docs/rf24_mesh_api.rst Advanced functionalities for managing connections and addresses within the mesh network. ```APIDOC ## RF24Mesh Class - Advanced API ### Description Offers advanced features for checking connections, managing addresses, and configuring network parameters. ### Methods - `check_connection()`: Checks the current network connection status. - `release_address()`: Releases the node's current address. - `get_node_id(address)`: Retrieves the node ID for a given address. - `get_address(node_id)`: Retrieves the logical address for a given node ID. - `set_address(address)`: Sets a specific logical address for the node. - `set_channel(channel)`: Sets the radio channel for the mesh network. - `set_child(node_id, address)`: Manually sets a child node's address. ### Attributes - `mesh_address`: The logical address assigned to the current node. - `addr_list`: A list of connected node addresses and their IDs. ``` -------------------------------- ### AddrListStruct Class Source: https://github.com/nrf24/pyrf24/blob/main/docs/rf24_mesh_api.rst Represents address list information for connected nodes. ```APIDOC ## AddrListStruct Class ### Description Represents a structure containing information about a connected node in the mesh network. Properties are read-only and managed by the master node. ### Attributes - `node_id` (int): The unique identifier of the node. - `address` (int): The logical address of the node within the mesh. ### Usage This class is typically instantiated by the master node. You can use `print(AddrListStruct_object)` to display its properties due to the support for the `repr()` magic method. ``` -------------------------------- ### Mesh Constants Source: https://github.com/nrf24/pyrf24/blob/main/docs/rf24_mesh_api.rst Pre-defined constants for use with the RF24Mesh library. ```APIDOC ## Mesh Constants ### Description Provides constants for convenience and readability when working with the RF24Mesh network. ### Constants - `MESH_DEFAULT_ADDRESS`: A reserved address for nodes requesting an assigned address. - `MESH_ADDR_LOOKUP`: Message type used by `get_address()` to fetch a logical address for a node ID. - `MESH_ID_LOOKUP`: Message type used by `get_node_id()` to fetch a node ID for a logical address. - `MESH_ADDR_RELEASE`: Message type used by `release_address()` when a node disconnects to unassign its address. ``` -------------------------------- ### Restricted RF24 Functionality with FakeBLE Source: https://github.com/nrf24/pyrf24/blob/main/docs/ble_api.rst Lists RF24 functionalities that should not be used when FakeBLE objects are instantiated with an RF24 object. ```APIDOC ## Restricted RF24 Functionality with FakeBLE ### Description When `FakeBLE` objects are instantiated with an `RF24` object, the following `RF24` functionalities are restricted and should not be used: - `dynamic_payloads` attribute - `data_rate` attribute - `address_width` attribute - `set_auto_ack()` method - `ack_payloads` attribute - `crc_length` attribute - `open_rx_pipe()` method - `open_tx_pipe()` method ``` -------------------------------- ### RF24Network Class - Advanced API Source: https://github.com/nrf24/pyrf24/blob/main/docs/rf24_network_api.rst Details advanced functionalities for network communication, including multicast and address validation. ```APIDOC ## RF24Network Class - Advanced API ### Description Advanced methods for complex network operations like multicast and routing. ### Methods - `multicast(message, header)`: Sends a message to multiple nodes. - `is_address_valid(address)`: Checks if a given network address is valid. ### Attributes - `node_address`: The address of the current node. - `multicast_relay`: Enables or disables multicast relay. - `tx_timeout`: Timeout for transmission. - `route_timeout`: Timeout for routing. - `multicast_level`: Level for multicast messages. ``` -------------------------------- ### RF24NetworkHeader Class Source: https://github.com/nrf24/pyrf24/blob/main/docs/rf24_network_api.rst Defines the structure and properties of network message headers. ```APIDOC ## RF24NetworkHeader Class ### Description Represents the header for messages sent over the RF24Network. Supports `repr()` for easy printing. ### Attributes - `to_node` (int): The destination node address. - `type` (int): The type of the message. - `from_node` (int): The source node address. - `id` (int): A unique identifier for the message. - `reserved` (int): Reserved field. ### Class Methods - `next_id` (int): The next sequential ID to be used for a new header. ``` -------------------------------- ### RF24 Enum Classes Source: https://github.com/nrf24/pyrf24/blob/main/docs/rf24_api.rst Enumerations for configuring CRC lengths, data rates, power amplifier levels, FIFO states, and IRQ flags. ```APIDOC ## RF24 Enum Classes ### Description This section describes the enumeration classes available in the PyRF24 library for configuring various radio parameters. ### Enumerations - `rf24_crclength_e`: - `RF24_CRC_DISABLED`: CRC disabled. - `RF24_CRC_8`: 8-bit CRC. - `RF24_CRC_16`: 16-bit CRC. - `rf24_datarate_e`: - `RF24_1MBPS`: 1 Mbps data rate. - `RF24_2MBPS`: 2 Mbps data rate. - `RF24_250KBPS`: 250 Kbps data rate. - `rf24_pa_dbm_e`: - `RF24_PA_MIN`: Minimum power amplifier level. - `RF24_PA_LOW`: Low power amplifier level. - `RF24_PA_HIGH`: High power amplifier level. - `RF24_PA_MAX`: Maximum power amplifier level. - `rf24_fifo_state_e`: - `RF24_FIFO_OCCUPIED`: FIFO buffer is occupied. - `RF24_FIFO_EMPTY`: FIFO buffer is empty. - `RF24_FIFO_FULL`: FIFO buffer is full. - `RF24_FIFO_INVALID`: FIFO buffer state is invalid. - `rf24_irq_flags_e`: - `RF24_RX_DR`: Data received interrupt. - `RF24_TX_DS`: Data sent interrupt. - `RF24_TX_DF`: Transmission failed interrupt. - `RF24_IRQ_ALL`: All interrupt flags. - `RF24_IRQ_NONE`: No interrupt flags. ### Usage Example ```python from pyrf24 import RF24, rf24_datarate_e, rf24_pa_dbm_e radio = RF24(22, 0) radio.begin() # Set data rate to 2 Mbps radio.data_rate = rf24_datarate_e.RF24_2MBPS # Set power amplifier level to maximum radio.pa_level = rf24_pa_dbm_e.RF24_PA_MAX ``` ``` -------------------------------- ### Network Flag Mnemonics Source: https://github.com/nrf24/pyrf24/blob/main/docs/rf24_network_api.rst Flags used to configure network behavior within the RF24Network stack. ```APIDOC ## FLAG_FAST_FRAG ### Description Prevents repetitive radio configuration during the transmission of fragmented messages when asserted in network_flags. ## FLAG_NO_POLL ### Description Prevents a node from responding to mesh nodes attempting to connect to the network. Used by RF24Mesh.set_child() to manage connection availability. ``` -------------------------------- ### Network Message Types Source: https://github.com/nrf24/pyrf24/blob/main/docs/rf24_network_api.rst Definitions for specialized network message types used for mesh networking and error reporting. ```APIDOC ## NETWORK_POLL ### Description Used by RF24Mesh to find active or available nodes via multi-casting. Nodes receiving this message respond directly to the sender with a blank message, providing their address in the header. ## NETWORK_REQ_ADDRESS ### Description Used by RF24Mesh to request information from the master node via unicast. Non-master nodes receiving this message will manually forward it to the master node. ## NETWORK_OVERRUN ### Description Indicates the network is being overrun with data and RF24Network.available() has returned from a loop. ## NETWORK_CORRUPTION ### Description Indicates the radio has encountered corrupted data and the RX FIFO has been flushed. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.