aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2025-01-02 10:30:17 +0000
committerGitHub <[email protected]>2025-01-02 10:30:17 +0000
commit87b4d949bdfd67105729d90250d35debf22ad1d8 (patch)
treebfb21e6fdc6c7d0606e48bb6a9a5d5a430017026 /examples
parentadf1e424f4e6ec8602b429b2727a7c5ce153558e (diff)
parentb5ef53ac1349d2c96f37c5186c2f4945604767be (diff)
Merge pull request #3702 from BartMassey-upstream/std-example-cosmetics
std example cosmetics
Diffstat (limited to 'examples')
-rw-r--r--examples/std/README.md14
-rw-r--r--examples/std/src/bin/net.rs8
-rw-r--r--examples/std/tap.sh7
3 files changed, 18 insertions, 11 deletions
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 @@
1 1
2## Running the `embassy-net` examples 2## Running the `embassy-net` examples
3 3
4First, create the tap0 interface. You only need to do this once. 4First, create the tap99 interface. (The number was chosen to
5hopefully not collide with anything.) You only need to do
6this once.
5 7
6```sh 8```sh
7sudo ip tuntap add name tap0 mode tap user $USER 9sudo sh tap.sh
8sudo ip link set tap0 up
9sudo ip addr add 192.168.69.100/24 dev tap0
10sudo ip -6 addr add fe80::100/64 dev tap0
11sudo ip -6 addr add fdaa::100/64 dev tap0
12sudo ip -6 route add fe80::/64 dev tap0
13sudo ip -6 route add fdaa::/64 dev tap0
14``` 10```
15 11
16Second, have something listening there. For example `nc -lp 8000` 12Second, have something listening there. For example `nc -lp 8000`
@@ -19,5 +15,5 @@ Then run the example located in the `examples` folder:
19 15
20```sh 16```sh
21cd $EMBASSY_ROOT/examples/std/ 17cd $EMBASSY_ROOT/examples/std/
22cargo run --bin net -- --static-ip 18sudo cargo run --bin net -- --tap tap99 --static-ip
23``` 19```
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 @@
1use core::fmt::Write as _;
2
1use clap::Parser; 3use clap::Parser;
2use embassy_executor::{Executor, Spawner}; 4use embassy_executor::{Executor, Spawner};
3use embassy_net::tcp::TcpSocket; 5use embassy_net::tcp::TcpSocket;
@@ -71,8 +73,10 @@ async fn main_task(spawner: Spawner) {
71 return; 73 return;
72 } 74 }
73 info!("connected!"); 75 info!("connected!");
74 loop { 76 for i in 0.. {
75 let r = socket.write_all(b"Hello!\n").await; 77 let mut buf = heapless::String::<100>::new();
78 write!(buf, "Hello! ({})\r\n", i).unwrap();
79 let r = socket.write_all(buf.as_bytes()).await;
76 if let Err(e) = r { 80 if let Err(e) = r {
77 warn!("write error: {:?}", e); 81 warn!("write error: {:?}", e);
78 return; 82 return;
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 @@
1ip tuntap add name tap99 mode tap user $USER
2ip link set tap99 up
3ip addr add 192.168.69.100/24 dev tap99
4ip -6 addr add fe80::100/64 dev tap99
5ip -6 addr add fdaa::100/64 dev tap99
6ip -6 route add fe80::/64 dev tap99
7ip -6 route add fdaa::/64 dev tap99