Skip to content

Conversation

@adria0
Copy link

@adria0 adria0 commented Nov 13, 2025

Summary
Add an example for sending messages over BLE

Related Issues
Closes #78

@CLAassistant
Copy link

CLAassistant commented Nov 13, 2025

CLA assistant check
All committers have signed the CLA.

}
}

async fn get_ble_device() -> String {
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 for showing discovery also, when device is not specified in the command line options.

Copy link
Contributor

Choose a reason for hiding this comment

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

If Luka wants to have a separate discovery example, that's fine for me. Just having some discovery example would be good.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I have a discovery example on a local branch, but I didn't like it. I'll try to polish it.

@andrewdavidmackenzie
Copy link
Contributor

Reviewed and commented, in case it helps.
Thanks for this, I needed it when learning how to use the crate.

Arguably, it could close #63 too?
Maybe a comment in docs on packet router trait to the example could help implementers find this?

@adria0
Copy link
Author

adria0 commented Nov 14, 2025

Arguably, it could close #63 too?

I expect this!

Maybe a comment in docs on packet router trait to the example could help implementers find this?

Mmmm... @andrewdavidmackenzie is not still not clear for me the design decisions behind the PacketRouter, so not really able to comment it.

Maybe if I implement some kind of router some day it would have more sense to me?

And thanks for the review 🙌

@andrewdavidmackenzie
Copy link
Contributor

You've implemented a router here, it's just quite simple, which makes sense as there is not much other app logic that needs it.

I think for some simple sending scenarios, not needing a router at all (but supplying from node id) would make sense.

@adria0
Copy link
Author

adria0 commented Nov 14, 2025

You've implemented a router here, it's just quite simple, which makes sense as there is not much other app logic that needs it.

I would say a "real router", forwarding packets and so on.

I think for some simple sending scenarios, not needing a router at all (but supplying from node id) would make sense.

Agree

@lukipuki
Copy link
Collaborator

Sorry, I haven't had the chance to have a proper deep look but will try over the weekend.

From the first glance, it's 200 lines of code (discounting comments in imports), that's a bit long for an example IMO. Do you think you can make it shorter?

Parts of it come from the PacketRouter which has probably not been a good design choice (predates me), but there might be parts that could be made shorter. E.g. contrary to Andrew's opinion I'd scratch the device discovery and put it in a separate example. Better have short examples showing partial functionality than having a long one doing it all.

I've started working on a BLE discovery example but got interrupted by other open source work. I can put it into another file.

@adria0
Copy link
Author

adria0 commented Nov 21, 2025

@lukipuki I think an example that is self-contained with the minimum needed to do something from beginning to end is very educational — that’s what examples are meant for, in my view — because it shows clearly how things are done.

As Andrew said, this is the kind of example I expected to find, so I wrote it.

I can strip the discovery part, which is about 2 LOC. Or strip PacketRouter, but what should I do instead?

@andrewdavidmackenzie
Copy link
Contributor

I think the PacketRouter is minimal and few lines of code.

As per my comment: impl From<FromRadio> for RecievedPacket on the other hand is quite a lot of lines of code for something relatively simple, unrelated to what you are trying to show in the example.

I think that could be removed and FromRadio handled directly, with if let or match or similar.

@adria0 adria0 marked this pull request as draft November 21, 2025 09:18
@adria0
Copy link
Author

adria0 commented Nov 23, 2025

@andrewdavidmackenzie, I changed a little the example to be more straighforward as also trying to be more precise about ACK handling.

Could you check if the ACK handling matches with you knowledge, plz.

Copy link
Contributor

@andrewdavidmackenzie andrewdavidmackenzie 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. Shorter!

My ack processing is slightly simpler (doesn't mean it's correct!)

  • RoutingApp
  • to == from
  • request_id matches the id of a message sent by me

I don't check the priority bit...

Cargo.toml Outdated
version = "0.1.7"
rust-version = "1.84"
edition = "2021"
rust-version = "1.91"
Copy link
Contributor

Choose a reason for hiding this comment

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

That's very recent. Do you need to force people onto such a recent version?
Does something in the code need it?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please don't change rust-version in a non-related PR. You can file an issue for that if needed.

Copy link
Author

Choose a reason for hiding this comment

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

Really only 1.88 is needed to support if let chains. It really makes the code more ergonomic to handle this protobuf de-encapsulations.

https://blog.rust-lang.org/2025/06/26/Rust-1.88.0/

But,why not to bump till last stable.

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, you're forcing anyone on 1.88 etc to upgrade before they can run the example, for no real reason?

Copy link
Author

Choose a reason for hiding this comment

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

it's a draft @andrewdavidmackenzie, I'm just experimenting different options here.
Not forcing anyone to anything.

stdout().flush().unwrap();
}};
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess you have seen problems due to io not appearing immediately?

Copy link
Author

Choose a reason for hiding this comment

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

No, it's just that if you print! output is not flushed, and you need it to report progress by printing dots.

}
}

async fn get_ble_device() -> String {
Copy link
Contributor

Choose a reason for hiding this comment

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

If Luka wants to have a separate discovery example, that's fine for me. Just having some discovery example would be good.

@adria0
Copy link
Author

adria0 commented Nov 24, 2025

About BLE discovery I can always add a comment about how to do it!

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.

Unable to send a message via BLE

4 participants