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

fix (library): ESP32-NOW peer removal #10076

Closed
wants to merge 2 commits into from

Conversation

craiglink
Copy link
Contributor

in the case were _esp_now_del_peer, the peer could never be added again because added would always be true and never reset. This forces it to be reset

By completing this PR sufficiently, you help us to review this Pull Request quicker and also help improve the quality of Release Notes


Description of Change

in the case where _esp_now_del_peer API calls,, the peer could never be added again by the C++ class because added would always be true and never reset. This forces 'added' to be reset, regardless of the api call.

Tests scenarios

Fixes a issue in WLED code where a broadcast peer couldn't be added a second time during restart. Run on an ESP32 dig2go board.

in the case were _esp_now_del_peer, the peer could never be added again because `added` would always be true and never reset.  This forces it to be reset
Copy link
Contributor

github-actions bot commented Jul 26, 2024

Warnings
⚠️

Some issues found for the commit messages in this PR:

  • the commit message "fix peer removal":
    • body's lines must not be longer than 100 characters
    • summary looks empty
    • type/action looks empty

Please fix these commit messages - here are some basic tips:

  • follow Conventional Commits style
  • correct format of commit message should be: <type/action>(<scope/component>): <summary>, for example fix(esp32): Fixed startup timeout issue
  • allowed types are: change,ci,docs,feat,fix,refactor,remove,revert,test
  • sufficiently descriptive message summary should be between 20 to 72 characters and start with upper case letter
  • avoid Jira references in commit messages (unavailable/irrelevant for our customers)

TIP: Install pre-commit hooks and run this check when committing (uses the Conventional Precommit Linter).

👋 Hello craiglink, we appreciate your contribution to this project!


Click to see more instructions ...


This automated output is generated by the PR linter DangerJS, which checks if your Pull Request meets the project's requirements and helps you fix potential issues.

DangerJS is triggered with each push event to a Pull Request and modify the contents of this comment.

Please consider the following:
- Danger mainly focuses on the PR structure and formatting and can't understand the meaning behind your code or changes.
- Danger is not a substitute for human code reviews; it's still important to request a code review from your colleagues.
- Resolve all warnings (⚠️ ) before requesting a review from human reviewers - they will appreciate it.
- To manually retry these Danger checks, please navigate to the Actions tab and re-run last Danger workflow.

Review and merge process you can expect ...


We do welcome contributions in the form of bug reports, feature requests and pull requests.

1. An internal issue has been created for the PR, we assign it to the relevant engineer.
2. They review the PR and either approve it or ask you for changes or clarifications.
3. Once the GitHub PR is approved we do the final review, collect approvals from core owners and make sure all the automated tests are passing.
- At this point we may do some adjustments to the proposed change, or extend it by adding tests or documentation.
4. If the change is approved and passes the tests it is merged into the default branch.

Generated by 🚫 dangerJS against 7fa3afd

Copy link
Contributor

Memory usage test (comparing PR against master branch)

The table below shows the summary of memory usage change (decrease - increase) in bytes and percentage for each target.

MemoryFLASH [bytes]FLASH [%]RAM [bytes]RAM [%]
TargetDECINCDECINCDECINCDECINC
ESP32S3💚 -400.000.00000.000.00
ESP32S2💚 -400.000.00000.000.00
ESP32C3💚 -1400.000.00000.000.00
ESP32C6💚 -1400.000.00000.000.00
ESP32💚 -400.000.00000.000.00
Click to expand the detailed deltas report [usage change in BYTES]
TargetESP32S3ESP32S2ESP32C3ESP32C6ESP32
ExampleFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAM
ESP_NOW/examples/ESP_NOW_Broadcast_Master💚 -40💚 -40💚 -140💚 -14000
ESP_NOW/examples/ESP_NOW_Broadcast_Slave00000000💚 -40
ESP_NOW/examples/ESP_NOW_Network00000000💚 -40
ESP_NOW/examples/ESP_NOW_Serial💚 -40💚 -40💚 -140💚 -14000

Copy link
Contributor

github-actions bot commented Jul 26, 2024

Test Results

 56 files   -  83   56 suites   - 83   4m 56s ⏱️ - 1h 37m 56s
 21 tests  -   9   21 ✅  -   9  0 💤 ±0  0 ❌ ±0 
135 runs   - 168  135 ✅  - 168  0 💤 ±0  0 ❌ ±0 

Results for commit 7fa3afd. ± Comparison against base commit f5be003.

This pull request removes 9 tests.
performance.coremark.test_coremark ‑ test_coremark
performance.fibonacci.test_fibonacci ‑ test_fibonacci
performance.psramspeed.test_psramspeed ‑ test_psramspeed
performance.ramspeed.test_ramspeed ‑ test_ramspeed
performance.superpi.test_superpi ‑ test_superpi
test_touch_errors
test_touch_interrtupt
test_touch_read
validation.periman.test_periman ‑ test_periman

♻️ This comment has been updated with latest results.

@VojtechBartoska VojtechBartoska changed the title fix ESP32_NOW peer removal fix (library): ESP32-NOW peer removal Jul 26, 2024
@VojtechBartoska VojtechBartoska added Area: Libraries Issue is related to Library support. Status: Review needed Issue or PR is awaiting review labels Jul 26, 2024
@VojtechBartoska
Copy link
Contributor

Thank you for the PR @craiglink, we will review it soon 👍

@P-R-O-C-H-Y
Copy link
Member

Hello @craiglink, Is there any way on how to reproduce the issue and see if this is needed at all?
From my point of view the added = false; is on right place, after successful return from _esp_now_del_peer();
If this function fails, it means the peer was not deleted, so it makes sense to keep added = true.
Thank you for more details.

@P-R-O-C-H-Y P-R-O-C-H-Y added the Resolution: Awaiting response Waiting for response of author label Jul 26, 2024
@craiglink
Copy link
Contributor Author

The problem with only setting added = false after a successful peer deletion is that the peer list also gets cleared if esp_now_deinit() is called. However this calls exist in a different calls, thus it leaves the peer class in a bad state which can never be reset as its currently written. A mechanism or codepath is need to reset "added" if deinit() was called. Or just always set added to false when unregistering a peer

@me-no-dev
Copy link
Member

me-no-dev commented Jul 29, 2024

@craiglink in that case proper solution would be to seta all peers to false if esp_now_deinit() is called (maybe with helper function)

@awong1900
Copy link

It is break change from 2.0 to 3.0 on esp now. I will watch this.

@craiglink
Copy link
Contributor Author

That code path is actually broken too. I actually gave up on using this class after seeing all the issues because it seem to brittle.

for example

bool ESP_NOW_Class::end() {
if (!_esp_now_has_begun) {
return true;
}
//remove all peers?
esp_err_t err = esp_now_deinit();
if (err != ESP_OK) {
log_e("esp_now_deinit failed! 0x%x", err);
return false;
}
_esp_now_has_begun = false;
memset(_esp_now_peers, 0, sizeof(ESP_NOW_Peer *) * ESP_NOW_MAX_TOTAL_PEER_NUM);
return true;
}

Similarly if deinit() fails, the peers list won't be reset even though they no longer exist
And you'd want to create a friend function in Peer that ESP_NOW_Class could call to detach the peer.

@lucasssvaz lucasssvaz removed the Resolution: Awaiting response Waiting for response of author label Jul 30, 2024
@VojtechBartoska VojtechBartoska added this to the 3.0.4 milestone Jul 31, 2024
@VojtechBartoska VojtechBartoska added Status: In Progress Issue is in progress and removed Status: Review needed Issue or PR is awaiting review labels Jul 31, 2024
@P-R-O-C-H-Y
Copy link
Member

@craiglink @awong1900 I am closing this in favour of #10102.
Feel free to review or comment the new PR. Thanks

@P-R-O-C-H-Y P-R-O-C-H-Y closed this Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Libraries Issue is related to Library support. Status: In Progress Issue is in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants