Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve examples' use of mesh.begin() and renewAddress() #205

Merged
merged 6 commits into from
Mar 4, 2022

Conversation

2bndy5
Copy link
Member

@2bndy5 2bndy5 commented Feb 19, 2022

This solves #203

While reviewing all the examples, I added some comments to the Linux C++ examples and ported the work from the mesh examples in pyrf24. I can revert the changes to the python examples if people are still using python2.7 for some reason, but I'm pretty sure boost.python has phased out maintenance support for python2.

@2bndy5 2bndy5 linked an issue Feb 19, 2022 that may be closed by this pull request
@TMRh20
Copy link
Member

TMRh20 commented Feb 20, 2022

This commit just brought to light another issue with the examples.

        if(!mesh.renewAddress()){
          mesh.begin();
        }

I think should be?

        if(mesh.renewAddress() == MESH_DEFAULT_ADDRESS){
          mesh.begin();
        }

I guess when I wrote the examples, I was thinking it would return something else.

@2bndy5
Copy link
Member Author

2bndy5 commented Feb 20, 2022

I don't recall seeing that snippet anywhere. Why would you call begin() after renewAddress() fails?

But I would agree. Failure from renewAddress() is identified when it returns 04444.

@2bndy5
Copy link
Member Author

2bndy5 commented Feb 20, 2022

Wait, the docs don't mention what is returned when renewAddress() fails.

I suppose it is a good sign that users haven't noticed this oversight (or that no one reported it).

@2bndy5
Copy link
Member Author

2bndy5 commented Feb 20, 2022

Should I also add a while loop in the child node examples that demonstrate how to renewAddress() on write() failures?

        if (!mesh.write(&displayTimer, 'M', sizeof(displayTimer))) {
            // If a write fails, check connectivity to the mesh network
            if (!mesh.checkConnection()) {
                // The address could be refreshed per a specified timeframe or only when sequential writes fail, etc.
                printf("Renewing Address\n");
                mesh.renewAddress();
            }
            else {
                printf("Send fail, Test OK\n");
            }
        }
        else {
            printf("Send OK: %u\n", displayTimer);
        }

Or should we add a var isConnected that triggers a while (mesh.renewAddress() == MESH_DEFAULT_ADDRESS) in the loop()? This idea (to me) seems overly complex for a simple example.

@TMRh20
Copy link
Member

TMRh20 commented Feb 21, 2022

I don't recall seeing that snippet anywhere. Why would you call begin() after renewAddress() fails?

Its in all the client/child examples:

      // If a write fails, check connectivity to the mesh network
      if ( ! mesh.checkConnection() ) {
        //refresh the network address
        Serial.println("Renewing Address");
        if (!mesh.renewAddress()) {
          //If address renewal fails, reconfigure the radio and restart the mesh
          //This allows recovery from most if not all radio errors
          mesh.begin();
        }
      } else {
        Serial.println("Send fail, Test OK");
      }
    } else {
      Serial.print("Send OK: "); Serial.println(displayTimer);
    }
  }

It allows recovery from hardware failures etc. and makes the radios hot-swappable. I've swapped out faulty radios without having to reset the MCU...

Should I also add a while loop in the child node examples that demonstrate how to renewAddress() on write() failures?

Sure.

Comment on lines -77 to +85
if (!mesh.renewAddress()) {
if (mesh.renewAddress() == MESH_DEFAULT_ADDRESS) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the only instance I could find which improperly uses the return value of renewAddress().

@2bndy5
Copy link
Member Author

2bndy5 commented Feb 26, 2022

I found that the RF24::isChipConnected() wasn't exposed in the old py wrapper. I fixed this on RF24 master branch.

@2bndy5 2bndy5 changed the title improve examples' setup improve examples' use of mesh.begin() and renewAddress() Mar 1, 2022
@TMRh20 TMRh20 merged commit 30f9e17 into master Mar 4, 2022
@2bndy5 2bndy5 deleted the better-arduino-example-setup branch March 4, 2022 16:12
@2bndy5 2bndy5 mentioned this pull request Jun 6, 2022
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.

add option to reattempt connection in setup() for arduino examples
2 participants