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

std example cosmetics #3702

Merged
merged 2 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions examples/std/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@

## Running the `embassy-net` examples

First, create the tap0 interface. You only need to do this once.
First, create the tap99 interface. (The number was chosen to
hopefully not collide with anything.) You only need to do
this once.

```sh
sudo ip tuntap add name tap0 mode tap user $USER
sudo ip link set tap0 up
sudo ip addr add 192.168.69.100/24 dev tap0
sudo ip -6 addr add fe80::100/64 dev tap0
sudo ip -6 addr add fdaa::100/64 dev tap0
sudo ip -6 route add fe80::/64 dev tap0
sudo ip -6 route add fdaa::/64 dev tap0
sudo sh tap.sh
```

Second, have something listening there. For example `nc -lp 8000`
Expand All @@ -19,5 +15,5 @@ Then run the example located in the `examples` folder:

```sh
cd $EMBASSY_ROOT/examples/std/
cargo run --bin net -- --static-ip
sudo cargo run --bin net -- --tap tap99 --static-ip
```
8 changes: 6 additions & 2 deletions examples/std/src/bin/net.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use core::fmt::Write as _;

use clap::Parser;
use embassy_executor::{Executor, Spawner};
use embassy_net::tcp::TcpSocket;
Expand Down Expand Up @@ -71,8 +73,10 @@ async fn main_task(spawner: Spawner) {
return;
}
info!("connected!");
loop {
let r = socket.write_all(b"Hello!\n").await;
for i in 0.. {
let mut buf = heapless::String::<100>::new();
write!(buf, "Hello! ({})\r\n", i).unwrap();
let r = socket.write_all(buf.as_bytes()).await;
if let Err(e) = r {
warn!("write error: {:?}", e);
return;
Expand Down
7 changes: 7 additions & 0 deletions examples/std/tap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ip tuntap add name tap99 mode tap user $USER
ip link set tap99 up
ip addr add 192.168.69.100/24 dev tap99
ip -6 addr add fe80::100/64 dev tap99
ip -6 addr add fdaa::100/64 dev tap99
ip -6 route add fe80::/64 dev tap99
ip -6 route add fdaa::/64 dev tap99
Loading