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

[Q]: How to use .write asynchronously #217

Open
lbirkert opened this issue Feb 6, 2024 · 1 comment
Open

[Q]: How to use .write asynchronously #217

lbirkert opened this issue Feb 6, 2024 · 1 comment
Labels

Comments

@lbirkert
Copy link

lbirkert commented Feb 6, 2024

I've got some operations that are quite fragile to timing [multi-threading is not possible] and using network.write in between causes these operations to fail. I only want to write for sending agnostic data back to my master node, so it receiving this data is non-critical. Can I somehow write asynchronously? - I've noticed that the RF24 has a startWrite method, could I somehow use this without having to sacrifice the additional benefits [reliable data transfers] that RF24Network gives me?

@lbirkert lbirkert changed the title How to use .write without blocking [Q]: How to use .write without blocking Feb 6, 2024
@lbirkert lbirkert changed the title [Q]: How to use .write without blocking [Q]: How to use .write asynchronously Feb 6, 2024
@2bndy5
Copy link
Member

2bndy5 commented Feb 6, 2024

RF24Network uses RF24::writeFast() and RF24::txStandby() under the hood.

RF24Network/RF24Network.cpp

Lines 995 to 1000 in 4e804ee

ok = radio.writeFast(frame_buffer, frame_size, 0);
if (!(networkFlags & FLAG_FAST_FRAG)) {
ok = radio.txStandBy(txTimeout);
radio.setAutoAck(0, 0);
}

There is no way to write asynchronously from RF24Network/Mesh. Normally, I'd suggest inheriting from RF24Network and overwriting some behavior, but it wouldn't be that easy because

  1. messages over 24 bytes long are fragmented into a series of 24 byte payloads with changing RF24NetworkHeader info.
  2. Receiving payloads (during network.update()) isn't designed for using interrupts.

I think your best approach is to separate out some of the logic in your app to different processors. The RP2040 seems well suited for this because it is a dual-core processor.

@2bndy5 2bndy5 added the question label Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants