Skip to content

Add authorized-nodes filtering example to all master examples#265

Merged
TMRh20 merged 3 commits intomasterfrom
copilot/update-authorized-nodes-example
Apr 23, 2026
Merged

Add authorized-nodes filtering example to all master examples#265
TMRh20 merged 3 commits intomasterfrom
copilot/update-authorized-nodes-example

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 23, 2026

All master node examples lacked a reference pattern for restricting which node IDs are authorized to remain allocated in the mesh — a common production hardening step.

Adds a commented-out authorized-nodes filtering snippet immediately after every mesh.DHCP() call across all six master example files, with indentation matching each file's style.

Files updated:

  • examples/RF24Mesh_Example_Master/RF24Mesh_Example_Master.ino
  • examples/RF24Mesh_Example_Master_Statics/RF24Mesh_Example_Master_Statics.ino
  • examples/RF24Mesh_Example_Master_To_Nodes/RF24Mesh_Example_Master_To_Nodes.ino
  • examples_RPi/RF24Mesh_Example_Master.cpp
  • examples_RPi/RF24Mesh_Example_Master.py
  • examples_pico/RF24Mesh_Example_Master.cpp

C/C++ snippet (inserted after mesh.DHCP();):

// The following code can be un-commented in a production environment to limit the authorized nodes
// to a specified list of nodes. Any nodes not in this list will be de-allocated. Can be run on a timer.
// AUTHORIZED NODES LIST:
/*for(int i=0; i< mesh.addrListTop; i++){
    if(mesh.addrList[i].nodeID != 2 && mesh.addrList[i].nodeID != 3 && mesh.addrList[i].nodeID != 4){
        mesh.addrList[i].address = 0;
    }
}*/

Python equivalent (inserted after mesh.DHCP()):

# The following code can be un-commented in a production environment to limit
# the authorized nodes to a specified list of nodes. Any nodes not in this list
# will be de-allocated. Can be run on a timer.
# AUTHORIZED NODES LIST:
# for i in range(mesh.addrListTop):
#     if mesh.addrList[i].nodeID not in (2, 3, 4):
#         mesh.addrList[i].address = 0

No runtime behavior is changed; all new code is comment-only.

Original prompt

Update all master examples in repository nRF24/RF24Mesh to include an authorized-nodes filtering example immediately after the call to mesh.DHCP() (or the Python equivalent location directly after mesh.DHCP()).

Goal:

  • Add the provided commented example snippet to all master examples so users can optionally restrict authorized nodes by node ID.
  • Preserve existing behavior by keeping the new logic commented out.
  • Match each file’s language/style.

Files to update:

  • examples/RF24Mesh_Example_Master/RF24Mesh_Example_Master.ino
  • examples/RF24Mesh_Example_Master_Statics/RF24Mesh_Example_Master_Statics.ino
  • examples/RF24Mesh_Example_Master_To_Nodes/RF24Mesh_Example_Master_To_Nodes.ino
  • examples_RPi/RF24Mesh_Example_Master.cpp
  • examples_RPi/RF24Mesh_Example_Master.py
  • examples_pico/RF24Mesh_Example_Master.cpp

Required C/C++ snippet to add after mesh.DHCP();:

// The following code can be commented out in a production environment to limit the authorized nodes
// to a specified list of nodes. Any nodes not in this list will be de-allocated. Can be run on a timer.
// AUTHORIZED NODES LIST:
/*for(int i=0; i< mesh.addrListTop; i++){
    if(mesh.addrList[i].nodeID != 2 && mesh.addrList[i].nodeID != 3 && mesh.addrList[i].nodeID != 4){
        mesh.addrList[i].address = 0;
    }
}*/

For the Python file, add the equivalent commented Python example directly after mesh.DHCP() using Python comment syntax and idiomatic range(mesh.addrListTop) / membership check against (2, 3, 4).

Constraints:

  • Do not change runtime behavior besides adding comments/examples.
  • Keep formatting consistent with surrounding code.
  • Create a pull request with these changes.

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: i want to add the following code to all the master examples in the RF24Mesh library located at @nRF24/RF24Mesh. This is the code: // The following code can be commented out in a production environment to limit the authorized nodes
// to a specified list of nodes. Any nodes not in this list will be de-allocated. Can be run on a timer.
// AUTHORIZED NODES LIST:
/for(int i=0; i< mesh.addrListTop; i++){
if(mesh.addrList[i].nodeID != 2 && mesh.addrList[i].nodeID != 3 && mesh.addrList[i].nodeID != 4){
mesh.addrList[i].address = 0;
}
}
/

Assistant: I’m ready to proceed, but I need you to accept the pending authorization prompt so I can apply that commented “AUTHORIZED NODES LIST” snippet across the RF24Mesh master examples and open the update for review.

User: can you show me the code first?

Assistant: Yes — here’s the code I’d add to the master examples first, before making any PR.

The repo appears to have these master examples:

  • examples/RF24Mesh_Example_Master/RF24Mesh_Example_Master.ino
  • examples/RF24Mesh_Example_Master_Statics/RF24Mesh_Example_Master_Statics.ino
  • examples/RF24Mesh_Example_Master_To_Nodes/RF24Mesh_Example_Master_To_Nodes.ino
  • examples_RPi/RF24Mesh_Example_Master.cpp
  • examples_RPi/RF24Mesh_Example_Master.py
  • examples_pico/RF24Mesh_Example_Master.cpp

The code search results I used may be incomplete because that tool only returns up to 10 matches. You can view more in GitHub code search here:
https://github.com/search?q=repo%3AnRF24%2FRF24Mesh+RF24Mesh_Example_Master&type=code

Proposed insertion

I’d place this immediately after mesh.DHCP(); in each master example.

// The following code can be commented out in a production environment to limit the authorized nodes
// to a specified list of nodes. Any nodes not in this list will be de-allocated. Can be run on a timer.
// AUTHORIZED NODES LIST:
/*for(int i=0; i< mesh.addrListTop; i++){
    if(mesh.addrList[i].nodeID != 2 && mesh.addrList[i].nodeID != 3 && mesh.addrList[i].nodeID != 4){
        mesh.addrList[i].address = 0;
    }
}*/

Example of how it would look in the main Arduino master sketch

void loop() {

  // Call mesh.update to keep the network updated
  mesh.update();

  // In addition, keep the 'DHCP service' running on the master node so addresses will
  // be assigned to the sensor nodes
  mesh.DHCP();

  // The following code can be commented out in a production environment to limit the authorized nodes
  // to a specified list of nodes. Any nodes not in this list will be de-allocated. Can be run on a timer.
  // AUTHORIZED NODES LIST:
  /*for(int i=0; i< mesh.addrListTop; i++){
      if(mesh.addrList[i].nodeID != 2 && mesh.addrList[i].nodeID != 3 && mesh.addrList[i].nodeID != 4){
          mesh.addrList[i].address = 0;
      }
  }*/

  // Check for incoming data from the sensors
  if (network.available()) {
    RF24NetworkHea...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

*This pull request was created from Copilot chat.*
>

Copilot AI changed the title [WIP] Update master examples to include authorized-nodes filtering example Add authorized-nodes filtering example to all master examples Apr 23, 2026
Copilot AI requested a review from TMRh20 April 23, 2026 11:22
@TMRh20
Copy link
Copy Markdown
Member

TMRh20 commented Apr 23, 2026

closes #264

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 23, 2026

Memory usage change @ 76c4d06

Board Flash % RAM for global variables %
arduino:avr:nano 0 - 0 0 - 0 0 - 0 0 - 0
arduino:samd:mkrzero 0 - 0 0 - 0 0 - 0 0 - 0
Click for full report per board

arduino:avr:nano

Sketch Flash % RAM for global variables %
examples/RF24Mesh_Example 0 0 0 0
examples/RF24Mesh_Example_Master_Statics 0 0 0 0
examples/RF24Mesh_Example_Master_To_Nodes 0 0 0 0
examples/RF24Mesh_Example_Node2Node 0 0 0 0
examples/RF24Mesh_Example_Node2NodeExtra 0 0 0 0
examples/RF24Mesh_SerialConfig 0 0 0 0
examples/RF24Mesh_Example_Master 0 0 0 0

arduino:samd:mkrzero

Sketch Flash % RAM for global variables %
examples/RF24Mesh_Example 0 0 0 0
examples/RF24Mesh_Example_Master_Statics 0 0 0 0
examples/RF24Mesh_Example_Master_To_Nodes 0 0 0 0
examples/RF24Mesh_Example_Node2Node 0 0 0 0
examples/RF24Mesh_Example_Node2NodeExtra 0 0 0 0
examples/RF24Mesh_SerialConfig 0 0 0 0
examples/RF24Mesh_Example_Master 0 0 0 0

@TMRh20
Copy link
Copy Markdown
Member

TMRh20 commented Apr 23, 2026

@copilot Change the words "The following code can be commented out in a production environment" to "The following code can be un-commented in a production environment" in this PR for all the changes

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 23, 2026

@copilot Change the words "The following code can be commented out in a production environment" to "The following code can be un-commented in a production environment" in this PR for all the changes

Done in 76c4d06 — updated "can be commented out" to "can be un-commented" in all 6 files.

@TMRh20 TMRh20 marked this pull request as ready for review April 23, 2026 11:36
@TMRh20 TMRh20 requested a review from 2bndy5 April 23, 2026 11:37
Copy link
Copy Markdown
Member

@TMRh20 TMRh20 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

Copy link
Copy Markdown
Member

@2bndy5 2bndy5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style mistake in the C++ comment: ; i< mesh., but the examples serve their purpose.

@TMRh20 TMRh20 merged commit 561fc5d into master Apr 23, 2026
104 checks passed
@TMRh20 TMRh20 deleted the copilot/update-authorized-nodes-example branch April 23, 2026 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants