diff options
Diffstat (limited to 'examples/std')
| -rw-r--r-- | examples/std/Cargo.toml | 18 | ||||
| -rw-r--r-- | examples/std/README.md | 119 | ||||
| -rw-r--r-- | examples/std/src/bin/net.rs | 8 | ||||
| -rw-r--r-- | examples/std/src/bin/net_dns.rs | 8 | ||||
| -rw-r--r-- | examples/std/src/bin/net_ppp.rs | 10 | ||||
| -rw-r--r-- | examples/std/src/bin/net_udp.rs | 8 | ||||
| -rw-r--r-- | examples/std/src/bin/serial.rs | 2 | ||||
| -rw-r--r-- | examples/std/src/bin/tcp_accept.rs | 8 | ||||
| -rw-r--r-- | examples/std/src/bin/tick.rs | 2 | ||||
| -rw-r--r-- | examples/std/tap.sh | 2 |
10 files changed, 150 insertions, 35 deletions
diff --git a/examples/std/Cargo.toml b/examples/std/Cargo.toml index f00953167..449c5ddca 100644 --- a/examples/std/Cargo.toml +++ b/examples/std/Cargo.toml | |||
| @@ -3,14 +3,15 @@ edition = "2021" | |||
| 3 | name = "embassy-std-examples" | 3 | name = "embassy-std-examples" |
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
| 6 | publish = false | ||
| 6 | 7 | ||
| 7 | [dependencies] | 8 | [dependencies] |
| 8 | embassy-sync = { version = "0.6.2", path = "../../embassy-sync", features = ["log"] } | 9 | embassy-sync = { version = "0.7.2", path = "../../embassy-sync", features = ["log"] } |
| 9 | embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = ["arch-std", "executor-thread", "log"] } | 10 | embassy-executor = { version = "0.9.0", path = "../../embassy-executor", features = ["arch-std", "executor-thread", "log"] } |
| 10 | embassy-time = { version = "0.4.0", path = "../../embassy-time", features = ["log", "std", ] } | 11 | embassy-time = { version = "0.5.0", path = "../../embassy-time", features = ["log", "std", ] } |
| 11 | embassy-net = { version = "0.7.0", path = "../../embassy-net", features=[ "log", "medium-ethernet", "medium-ip", "tcp", "udp", "dns", "dhcpv4", "proto-ipv6"] } | 12 | embassy-net = { version = "0.7.1", path = "../../embassy-net", features=[ "log", "medium-ethernet", "medium-ip", "tcp", "udp", "dns", "dhcpv4", "proto-ipv6"] } |
| 12 | embassy-net-tuntap = { version = "0.1.0", path = "../../embassy-net-tuntap" } | 13 | embassy-net-tuntap = { version = "0.1.0", path = "../../embassy-net-tuntap" } |
| 13 | embassy-net-ppp = { version = "0.2.0", path = "../../embassy-net-ppp", features = ["log"]} | 14 | embassy-net-ppp = { version = "0.2.1", path = "../../embassy-net-ppp", features = ["log"]} |
| 14 | embedded-io-async = { version = "0.6.1" } | 15 | embedded-io-async = { version = "0.6.1" } |
| 15 | embedded-io-adapters = { version = "0.6.1", features = ["futures-03"] } | 16 | embedded-io-adapters = { version = "0.6.1", features = ["futures-03"] } |
| 16 | critical-section = { version = "1.1", features = ["std"] } | 17 | critical-section = { version = "1.1", features = ["std"] } |
| @@ -21,9 +22,14 @@ futures = { version = "0.3.17" } | |||
| 21 | log = "0.4.14" | 22 | log = "0.4.14" |
| 22 | nix = "0.26.2" | 23 | nix = "0.26.2" |
| 23 | clap = { version = "3.0.0-beta.5", features = ["derive"] } | 24 | clap = { version = "3.0.0-beta.5", features = ["derive"] } |
| 24 | rand_core = { version = "0.6.3", features = ["std"] } | 25 | rand_core = { version = "0.9.1", features = ["std", "os_rng"] } |
| 25 | heapless = { version = "0.8", default-features = false } | 26 | heapless = { version = "0.8", default-features = false } |
| 26 | static_cell = "2" | 27 | static_cell = "2" |
| 27 | 28 | ||
| 28 | [profile.release] | 29 | [profile.release] |
| 29 | debug = 2 | 30 | debug = 2 |
| 31 | |||
| 32 | [package.metadata.embassy] | ||
| 33 | build = [ | ||
| 34 | { artifact-dir = "out/examples/std" } | ||
| 35 | ] | ||
diff --git a/examples/std/README.md b/examples/std/README.md index dcc152fc2..ac2c2a1a6 100644 --- a/examples/std/README.md +++ b/examples/std/README.md | |||
| @@ -1,19 +1,128 @@ | |||
| 1 | 1 | ||
| 2 | ## Running the `embassy-net` examples | 2 | ## Running the `embassy-net` examples |
| 3 | 3 | ||
| 4 | First, create the tap99 interface. (The number was chosen to | 4 | To run `net`, `tcp_accept`, `net_udp` and `net_dns` examples you will need a tap interface. Before running these examples, create the tap99 interface. (The number was chosen to |
| 5 | hopefully not collide with anything.) You only need to do | 5 | hopefully not collide with anything.) You only need to do this once every time you reboot your computer. |
| 6 | this once. | ||
| 7 | 6 | ||
| 8 | ```sh | 7 | ```sh |
| 8 | cd $EMBASSY_ROOT/examples/std/ | ||
| 9 | sudo sh tap.sh | 9 | sudo sh tap.sh |
| 10 | ``` | 10 | ``` |
| 11 | 11 | ||
| 12 | Second, have something listening there. For example `nc -lp 8000` | 12 | The example `net_ppp` requires different steps that are detailed in its section. |
| 13 | |||
| 14 | ### `net` example | ||
| 15 | |||
| 16 | For this example, you need to have something listening in the correct port. For example `nc -lp 8000`. | ||
| 13 | 17 | ||
| 14 | Then run the example located in the `examples` folder: | 18 | Then run the example located in the `examples` folder: |
| 15 | 19 | ||
| 16 | ```sh | 20 | ```sh |
| 17 | cd $EMBASSY_ROOT/examples/std/ | 21 | cd $EMBASSY_ROOT/examples/std/ |
| 18 | sudo cargo run --bin net -- --tap tap99 --static-ip | 22 | cargo run --bin net -- --tap tap99 --static-ip |
| 23 | ``` | ||
| 24 | ### `tcp_accept` example | ||
| 25 | |||
| 26 | This example listen for a tcp connection. | ||
| 27 | |||
| 28 | First run the example located in the `examples` folder: | ||
| 29 | |||
| 30 | ```sh | ||
| 31 | cd $EMBASSY_ROOT/examples/std/ | ||
| 32 | cargo run --bin tcp_accept -- --tap tap99 --static-ip | ||
| 33 | ``` | ||
| 34 | |||
| 35 | Then open a connection to the port. For example `nc 192.168.69.2 9999`. | ||
| 36 | |||
| 37 | ### `net_udp` example | ||
| 38 | |||
| 39 | This example listen for a udp connection. | ||
| 40 | |||
| 41 | First run the example located in the `examples` folder: | ||
| 42 | |||
| 43 | ```sh | ||
| 44 | cd $EMBASSY_ROOT/examples/std/ | ||
| 45 | cargo run --bin net_udp -- --tap tap99 --static-ip | ||
| 46 | ``` | ||
| 47 | |||
| 48 | Then open a connection to the port. For example `nc -u 192.168.69.2 9400`. | ||
| 49 | |||
| 50 | ### `net_dns` example | ||
| 51 | |||
| 52 | This example queries a `DNS` for the IP address of `www.example.com`. | ||
| 53 | |||
| 54 | In order to achieve this, the `tap99` interface requires configuring tap99 as a gateway device temporarily. | ||
| 55 | |||
| 56 | For example, in Ubuntu you can do this by: | ||
| 57 | |||
| 58 | 1. Identifying your default route device. In the next example `eth0` | ||
| 59 | |||
| 60 | ```sh | ||
| 61 | ip r | grep "default" | ||
| 62 | default via 192.168.2.1 dev eth0 proto kernel metric 35 | ||
| 63 | ``` | ||
| 64 | |||
| 65 | 2. Enabling temporarily IP Forwarding: | ||
| 66 | |||
| 67 | ```sh | ||
| 68 | sudo sysctl -w net.ipv4.ip_forward=1 | ||
| 69 | ``` | ||
| 70 | |||
| 71 | 3. Configuring NAT to mascarade traffic from `tap99` to `eth0` | ||
| 72 | |||
| 73 | ```sh | ||
| 74 | sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE | ||
| 75 | sudo iptables -A FORWARD -i tap99 -j ACCEPT | ||
| 76 | sudo iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT | ||
| 77 | ``` | ||
| 78 | |||
| 79 | 4. Then you can run the example located in the `examples` folder: | ||
| 80 | |||
| 81 | ```sh | ||
| 82 | cd $EMBASSY_ROOT/examples/std/ | ||
| 83 | cargo run --bin net_dns -- --tap tap99 --static-ip | ||
| 84 | ``` | ||
| 85 | |||
| 86 | ### `net_ppp` example | ||
| 87 | |||
| 88 | This example establish a Point-to-Point Protocol (PPP) connection that can be used, for example, for connecting to internet through a 4G modem via a serial channel. | ||
| 89 | |||
| 90 | The example creates a PPP bridge over a virtual serial channel between `pty1` and `pty2` for the example code and a PPP server running on the same computer. | ||
| 91 | |||
| 92 | To run this example you will need: | ||
| 93 | - ppp (pppd server) | ||
| 94 | - socat (socket CAT) | ||
| 95 | |||
| 96 | To run the examples you may follow the next steps: | ||
| 97 | |||
| 98 | 1. Save the PPP server configuration: | ||
| 99 | ```sh | ||
| 100 | sudo sh -c 'echo "myuser $(hostname) mypass 192.168.7.10" >> /etc/ppp/pap-secrets' | ||
| 101 | ``` | ||
| 102 | |||
| 103 | 2. Create a files `pty1` and `pty2` and link them | ||
| 104 | ```sh | ||
| 105 | cd $EMBASSY_ROOT/examples/std/ | ||
| 106 | socat -v -x PTY,link=pty1,rawer PTY,link=pty2,rawer | ||
| 107 | ``` | ||
| 108 | |||
| 109 | 3. open a second terminal and start the PPP server: | ||
| 110 | ```sh | ||
| 111 | cd $EMBASSY_ROOT/examples/std/ | ||
| 112 | sudo pppd $PWD/pty1 115200 192.168.7.1: ms-dns 8.8.4.4 ms-dns 8.8.8.8 nodetach debug local persist silent | ||
| 113 | ``` | ||
| 114 | |||
| 115 | 4. Open a third terminal and run the example | ||
| 116 | ```sh | ||
| 117 | cd $EMBASSY_ROOT/examples/std/ | ||
| 118 | RUST_LOG=trace cargo run --bin net_ppp -- --device pty2 | ||
| 119 | ``` | ||
| 120 | 5. Observe the output in the second and third terminal | ||
| 121 | 6. Open one last terminal to interact with `net_ppp` example through the PPP connection | ||
| 122 | ```sh | ||
| 123 | # ping the net_ppp client | ||
| 124 | ping 192.168.7.10 | ||
| 125 | # open an tcp connection | ||
| 126 | nc 192.168.7.10 1234 | ||
| 127 | # Type anything and observe the output in the different terminals | ||
| 19 | ``` | 128 | ``` |
diff --git a/examples/std/src/bin/net.rs b/examples/std/src/bin/net.rs index 6e50b1a01..fd7b6c930 100644 --- a/examples/std/src/bin/net.rs +++ b/examples/std/src/bin/net.rs | |||
| @@ -9,7 +9,7 @@ use embassy_time::Duration; | |||
| 9 | use embedded_io_async::Write; | 9 | use embedded_io_async::Write; |
| 10 | use heapless::Vec; | 10 | use heapless::Vec; |
| 11 | use log::*; | 11 | use log::*; |
| 12 | use rand_core::{OsRng, RngCore}; | 12 | use rand_core::{OsRng, TryRngCore}; |
| 13 | use static_cell::StaticCell; | 13 | use static_cell::StaticCell; |
| 14 | 14 | ||
| 15 | #[derive(Parser)] | 15 | #[derive(Parser)] |
| @@ -48,7 +48,7 @@ async fn main_task(spawner: Spawner) { | |||
| 48 | 48 | ||
| 49 | // Generate random seed | 49 | // Generate random seed |
| 50 | let mut seed = [0; 8]; | 50 | let mut seed = [0; 8]; |
| 51 | OsRng.fill_bytes(&mut seed); | 51 | OsRng.try_fill_bytes(&mut seed).unwrap(); |
| 52 | let seed = u64::from_le_bytes(seed); | 52 | let seed = u64::from_le_bytes(seed); |
| 53 | 53 | ||
| 54 | // Init network stack | 54 | // Init network stack |
| @@ -56,7 +56,7 @@ async fn main_task(spawner: Spawner) { | |||
| 56 | let (stack, runner) = embassy_net::new(device, config, RESOURCES.init(StackResources::new()), seed); | 56 | let (stack, runner) = embassy_net::new(device, config, RESOURCES.init(StackResources::new()), seed); |
| 57 | 57 | ||
| 58 | // Launch network task | 58 | // Launch network task |
| 59 | spawner.spawn(net_task(runner)).unwrap(); | 59 | spawner.spawn(net_task(runner).unwrap()); |
| 60 | 60 | ||
| 61 | // Then we can use it! | 61 | // Then we can use it! |
| 62 | let mut rx_buffer = [0; 4096]; | 62 | let mut rx_buffer = [0; 4096]; |
| @@ -95,6 +95,6 @@ fn main() { | |||
| 95 | 95 | ||
| 96 | let executor = EXECUTOR.init(Executor::new()); | 96 | let executor = EXECUTOR.init(Executor::new()); |
| 97 | executor.run(|spawner| { | 97 | executor.run(|spawner| { |
| 98 | spawner.spawn(main_task(spawner)).unwrap(); | 98 | spawner.spawn(main_task(spawner).unwrap()); |
| 99 | }); | 99 | }); |
| 100 | } | 100 | } |
diff --git a/examples/std/src/bin/net_dns.rs b/examples/std/src/bin/net_dns.rs index a42c5dbb7..dff704b86 100644 --- a/examples/std/src/bin/net_dns.rs +++ b/examples/std/src/bin/net_dns.rs | |||
| @@ -5,7 +5,7 @@ use embassy_net::{Config, Ipv4Address, Ipv4Cidr, StackResources}; | |||
| 5 | use embassy_net_tuntap::TunTapDevice; | 5 | use embassy_net_tuntap::TunTapDevice; |
| 6 | use heapless::Vec; | 6 | use heapless::Vec; |
| 7 | use log::*; | 7 | use log::*; |
| 8 | use rand_core::{OsRng, RngCore}; | 8 | use rand_core::{OsRng, TryRngCore}; |
| 9 | use static_cell::StaticCell; | 9 | use static_cell::StaticCell; |
| 10 | 10 | ||
| 11 | #[derive(Parser)] | 11 | #[derive(Parser)] |
| @@ -45,7 +45,7 @@ async fn main_task(spawner: Spawner) { | |||
| 45 | 45 | ||
| 46 | // Generate random seed | 46 | // Generate random seed |
| 47 | let mut seed = [0; 8]; | 47 | let mut seed = [0; 8]; |
| 48 | OsRng.fill_bytes(&mut seed); | 48 | OsRng.try_fill_bytes(&mut seed).unwrap(); |
| 49 | let seed = u64::from_le_bytes(seed); | 49 | let seed = u64::from_le_bytes(seed); |
| 50 | 50 | ||
| 51 | // Init network stack | 51 | // Init network stack |
| @@ -53,7 +53,7 @@ async fn main_task(spawner: Spawner) { | |||
| 53 | let (stack, runner) = embassy_net::new(device, config, RESOURCES.init(StackResources::new()), seed); | 53 | let (stack, runner) = embassy_net::new(device, config, RESOURCES.init(StackResources::new()), seed); |
| 54 | 54 | ||
| 55 | // Launch network task | 55 | // Launch network task |
| 56 | spawner.spawn(net_task(runner)).unwrap(); | 56 | spawner.spawn(net_task(runner).unwrap()); |
| 57 | 57 | ||
| 58 | let host = "example.com"; | 58 | let host = "example.com"; |
| 59 | info!("querying host {:?}...", host); | 59 | info!("querying host {:?}...", host); |
| @@ -78,6 +78,6 @@ fn main() { | |||
| 78 | 78 | ||
| 79 | let executor = EXECUTOR.init(Executor::new()); | 79 | let executor = EXECUTOR.init(Executor::new()); |
| 80 | executor.run(|spawner| { | 80 | executor.run(|spawner| { |
| 81 | spawner.spawn(main_task(spawner)).unwrap(); | 81 | spawner.spawn(main_task(spawner).unwrap()); |
| 82 | }); | 82 | }); |
| 83 | } | 83 | } |
diff --git a/examples/std/src/bin/net_ppp.rs b/examples/std/src/bin/net_ppp.rs index f667e8d4c..82272c798 100644 --- a/examples/std/src/bin/net_ppp.rs +++ b/examples/std/src/bin/net_ppp.rs | |||
| @@ -23,7 +23,7 @@ use futures::io::BufReader; | |||
| 23 | use heapless::Vec; | 23 | use heapless::Vec; |
| 24 | use log::*; | 24 | use log::*; |
| 25 | use nix::sys::termios; | 25 | use nix::sys::termios; |
| 26 | use rand_core::{OsRng, RngCore}; | 26 | use rand_core::{OsRng, TryRngCore}; |
| 27 | use static_cell::StaticCell; | 27 | use static_cell::StaticCell; |
| 28 | 28 | ||
| 29 | use crate::serial_port::SerialPort; | 29 | use crate::serial_port::SerialPort; |
| @@ -89,7 +89,7 @@ async fn main_task(spawner: Spawner) { | |||
| 89 | 89 | ||
| 90 | // Generate random seed | 90 | // Generate random seed |
| 91 | let mut seed = [0; 8]; | 91 | let mut seed = [0; 8]; |
| 92 | OsRng.fill_bytes(&mut seed); | 92 | OsRng.try_fill_bytes(&mut seed).unwrap(); |
| 93 | let seed = u64::from_le_bytes(seed); | 93 | let seed = u64::from_le_bytes(seed); |
| 94 | 94 | ||
| 95 | // Init network stack | 95 | // Init network stack |
| @@ -102,8 +102,8 @@ async fn main_task(spawner: Spawner) { | |||
| 102 | ); | 102 | ); |
| 103 | 103 | ||
| 104 | // Launch network task | 104 | // Launch network task |
| 105 | spawner.spawn(net_task(net_runner)).unwrap(); | 105 | spawner.spawn(net_task(net_runner).unwrap()); |
| 106 | spawner.spawn(ppp_task(stack, runner, port)).unwrap(); | 106 | spawner.spawn(ppp_task(stack, runner, port).unwrap()); |
| 107 | 107 | ||
| 108 | // Then we can use it! | 108 | // Then we can use it! |
| 109 | let mut rx_buffer = [0; 4096]; | 109 | let mut rx_buffer = [0; 4096]; |
| @@ -160,6 +160,6 @@ fn main() { | |||
| 160 | 160 | ||
| 161 | let executor = EXECUTOR.init(Executor::new()); | 161 | let executor = EXECUTOR.init(Executor::new()); |
| 162 | executor.run(|spawner| { | 162 | executor.run(|spawner| { |
| 163 | spawner.spawn(main_task(spawner)).unwrap(); | 163 | spawner.spawn(main_task(spawner).unwrap()); |
| 164 | }); | 164 | }); |
| 165 | } | 165 | } |
diff --git a/examples/std/src/bin/net_udp.rs b/examples/std/src/bin/net_udp.rs index 02d4d3efb..c5c4da65f 100644 --- a/examples/std/src/bin/net_udp.rs +++ b/examples/std/src/bin/net_udp.rs | |||
| @@ -5,7 +5,7 @@ use embassy_net::{Config, Ipv4Address, Ipv4Cidr, StackResources}; | |||
| 5 | use embassy_net_tuntap::TunTapDevice; | 5 | use embassy_net_tuntap::TunTapDevice; |
| 6 | use heapless::Vec; | 6 | use heapless::Vec; |
| 7 | use log::*; | 7 | use log::*; |
| 8 | use rand_core::{OsRng, RngCore}; | 8 | use rand_core::{OsRng, TryRngCore}; |
| 9 | use static_cell::StaticCell; | 9 | use static_cell::StaticCell; |
| 10 | 10 | ||
| 11 | #[derive(Parser)] | 11 | #[derive(Parser)] |
| @@ -44,7 +44,7 @@ async fn main_task(spawner: Spawner) { | |||
| 44 | 44 | ||
| 45 | // Generate random seed | 45 | // Generate random seed |
| 46 | let mut seed = [0; 8]; | 46 | let mut seed = [0; 8]; |
| 47 | OsRng.fill_bytes(&mut seed); | 47 | OsRng.try_fill_bytes(&mut seed).unwrap(); |
| 48 | let seed = u64::from_le_bytes(seed); | 48 | let seed = u64::from_le_bytes(seed); |
| 49 | 49 | ||
| 50 | // Init network stack | 50 | // Init network stack |
| @@ -52,7 +52,7 @@ async fn main_task(spawner: Spawner) { | |||
| 52 | let (stack, runner) = embassy_net::new(device, config, RESOURCES.init(StackResources::new()), seed); | 52 | let (stack, runner) = embassy_net::new(device, config, RESOURCES.init(StackResources::new()), seed); |
| 53 | 53 | ||
| 54 | // Launch network task | 54 | // Launch network task |
| 55 | spawner.spawn(net_task(runner)).unwrap(); | 55 | spawner.spawn(net_task(runner).unwrap()); |
| 56 | 56 | ||
| 57 | // Then we can use it! | 57 | // Then we can use it! |
| 58 | let mut rx_meta = [PacketMetadata::EMPTY; 16]; | 58 | let mut rx_meta = [PacketMetadata::EMPTY; 16]; |
| @@ -86,6 +86,6 @@ fn main() { | |||
| 86 | 86 | ||
| 87 | let executor = EXECUTOR.init(Executor::new()); | 87 | let executor = EXECUTOR.init(Executor::new()); |
| 88 | executor.run(|spawner| { | 88 | executor.run(|spawner| { |
| 89 | spawner.spawn(main_task(spawner)).unwrap(); | 89 | spawner.spawn(main_task(spawner).unwrap()); |
| 90 | }); | 90 | }); |
| 91 | } | 91 | } |
diff --git a/examples/std/src/bin/serial.rs b/examples/std/src/bin/serial.rs index 10c85511d..1ed9997c4 100644 --- a/examples/std/src/bin/serial.rs +++ b/examples/std/src/bin/serial.rs | |||
| @@ -50,6 +50,6 @@ fn main() { | |||
| 50 | 50 | ||
| 51 | let executor = EXECUTOR.init(Executor::new()); | 51 | let executor = EXECUTOR.init(Executor::new()); |
| 52 | executor.run(|spawner| { | 52 | executor.run(|spawner| { |
| 53 | spawner.spawn(run()).unwrap(); | 53 | spawner.spawn(run().unwrap()); |
| 54 | }); | 54 | }); |
| 55 | } | 55 | } |
diff --git a/examples/std/src/bin/tcp_accept.rs b/examples/std/src/bin/tcp_accept.rs index 18646a083..77886f471 100644 --- a/examples/std/src/bin/tcp_accept.rs +++ b/examples/std/src/bin/tcp_accept.rs | |||
| @@ -7,7 +7,7 @@ use embassy_time::{Duration, Timer}; | |||
| 7 | use embedded_io_async::Write as _; | 7 | use embedded_io_async::Write as _; |
| 8 | use heapless::Vec; | 8 | use heapless::Vec; |
| 9 | use log::*; | 9 | use log::*; |
| 10 | use rand_core::{OsRng, RngCore}; | 10 | use rand_core::{OsRng, TryRngCore}; |
| 11 | use static_cell::StaticCell; | 11 | use static_cell::StaticCell; |
| 12 | 12 | ||
| 13 | #[derive(Parser)] | 13 | #[derive(Parser)] |
| @@ -46,7 +46,7 @@ async fn main_task(spawner: Spawner) { | |||
| 46 | 46 | ||
| 47 | // Generate random seed | 47 | // Generate random seed |
| 48 | let mut seed = [0; 8]; | 48 | let mut seed = [0; 8]; |
| 49 | OsRng.fill_bytes(&mut seed); | 49 | OsRng.try_fill_bytes(&mut seed).unwrap(); |
| 50 | let seed = u64::from_le_bytes(seed); | 50 | let seed = u64::from_le_bytes(seed); |
| 51 | 51 | ||
| 52 | // Init network stack | 52 | // Init network stack |
| @@ -54,7 +54,7 @@ async fn main_task(spawner: Spawner) { | |||
| 54 | let (stack, runner) = embassy_net::new(device, config, RESOURCES.init(StackResources::new()), seed); | 54 | let (stack, runner) = embassy_net::new(device, config, RESOURCES.init(StackResources::new()), seed); |
| 55 | 55 | ||
| 56 | // Launch network task | 56 | // Launch network task |
| 57 | spawner.spawn(net_task(runner)).unwrap(); | 57 | spawner.spawn(net_task(runner).unwrap()); |
| 58 | 58 | ||
| 59 | // Then we can use it! | 59 | // Then we can use it! |
| 60 | let mut rx_buffer = [0; 4096]; | 60 | let mut rx_buffer = [0; 4096]; |
| @@ -101,6 +101,6 @@ fn main() { | |||
| 101 | 101 | ||
| 102 | let executor = EXECUTOR.init(Executor::new()); | 102 | let executor = EXECUTOR.init(Executor::new()); |
| 103 | executor.run(|spawner| { | 103 | executor.run(|spawner| { |
| 104 | spawner.spawn(main_task(spawner)).unwrap(); | 104 | spawner.spawn(main_task(spawner).unwrap()); |
| 105 | }); | 105 | }); |
| 106 | } | 106 | } |
diff --git a/examples/std/src/bin/tick.rs b/examples/std/src/bin/tick.rs index f23cf3549..16b82c82b 100644 --- a/examples/std/src/bin/tick.rs +++ b/examples/std/src/bin/tick.rs | |||
| @@ -17,5 +17,5 @@ async fn main(spawner: Spawner) { | |||
| 17 | .format_timestamp_nanos() | 17 | .format_timestamp_nanos() |
| 18 | .init(); | 18 | .init(); |
| 19 | 19 | ||
| 20 | spawner.spawn(run()).unwrap(); | 20 | spawner.spawn(run().unwrap()); |
| 21 | } | 21 | } |
diff --git a/examples/std/tap.sh b/examples/std/tap.sh index 39d92a099..fb89d2381 100644 --- a/examples/std/tap.sh +++ b/examples/std/tap.sh | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | ip tuntap add name tap99 mode tap user $USER | 1 | ip tuntap add name tap99 mode tap user $SUDO_USER |
| 2 | ip link set tap99 up | 2 | ip link set tap99 up |
| 3 | ip addr add 192.168.69.100/24 dev tap99 | 3 | ip addr add 192.168.69.100/24 dev tap99 |
| 4 | ip -6 addr add fe80::100/64 dev tap99 | 4 | ip -6 addr add fe80::100/64 dev tap99 |
