From 6b3ca677631a360bc1e485f0edd158f5b7afa1f1 Mon Sep 17 00:00:00 2001 From: Bart Massey Date: Tue, 31 Dec 2024 14:27:41 -0800 Subject: [PATCH 1/2] modified examples/std README to avoid possible problems --- examples/std/README.md | 14 +++++--------- examples/std/tap.sh | 7 +++++++ 2 files changed, 12 insertions(+), 9 deletions(-) create mode 100644 examples/std/tap.sh diff --git a/examples/std/README.md b/examples/std/README.md index e3a59d6ea..dcc152fc2 100644 --- a/examples/std/README.md +++ b/examples/std/README.md @@ -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` @@ -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 ``` diff --git a/examples/std/tap.sh b/examples/std/tap.sh new file mode 100644 index 000000000..39d92a099 --- /dev/null +++ b/examples/std/tap.sh @@ -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 From b5ef53ac1349d2c96f37c5186c2f4945604767be Mon Sep 17 00:00:00 2001 From: Bart Massey Date: Tue, 31 Dec 2024 15:15:11 -0800 Subject: [PATCH 2/2] gave examples/std a cleaner and more informational Hello --- examples/std/src/bin/net.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/std/src/bin/net.rs b/examples/std/src/bin/net.rs index cefa5448c..6e50b1a01 100644 --- a/examples/std/src/bin/net.rs +++ b/examples/std/src/bin/net.rs @@ -1,3 +1,5 @@ +use core::fmt::Write as _; + use clap::Parser; use embassy_executor::{Executor, Spawner}; use embassy_net::tcp::TcpSocket; @@ -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;