diff options
| author | Ulf Lilleengen <[email protected]> | 2024-09-05 10:02:45 +0200 |
|---|---|---|
| committer | Ulf Lilleengen <[email protected]> | 2024-09-05 10:02:45 +0200 |
| commit | 836e8add1bcb09c476a3aa3d7a416a15b8c21e6a (patch) | |
| tree | cc6be2c43ba0b6705ecfbebffe634501bf85ba6a /examples/nrf9160 | |
| parent | ccfa6264b0ad258625f2dd667ba8e6eaca1cfdc3 (diff) | |
Mintor fixes after testing re-attach
Diffstat (limited to 'examples/nrf9160')
| -rw-r--r-- | examples/nrf9160/src/bin/modem_tcp_client.rs | 54 |
1 files changed, 29 insertions, 25 deletions
diff --git a/examples/nrf9160/src/bin/modem_tcp_client.rs b/examples/nrf9160/src/bin/modem_tcp_client.rs index fb14b746f..b7d56802d 100644 --- a/examples/nrf9160/src/bin/modem_tcp_client.rs +++ b/examples/nrf9160/src/bin/modem_tcp_client.rs | |||
| @@ -10,6 +10,7 @@ use core::str::FromStr; | |||
| 10 | use defmt::{info, unwrap, warn}; | 10 | use defmt::{info, unwrap, warn}; |
| 11 | use embassy_executor::Spawner; | 11 | use embassy_executor::Spawner; |
| 12 | use embassy_net::{Ipv4Address, Ipv4Cidr, Stack, StackResources}; | 12 | use embassy_net::{Ipv4Address, Ipv4Cidr, Stack, StackResources}; |
| 13 | use embassy_net_nrf91::context::Status; | ||
| 13 | use embassy_net_nrf91::{context, Runner, State, TraceBuffer, TraceReader}; | 14 | use embassy_net_nrf91::{context, Runner, State, TraceBuffer, TraceReader}; |
| 14 | use embassy_nrf::buffered_uarte::{self, BufferedUarteTx}; | 15 | use embassy_nrf::buffered_uarte::{self, BufferedUarteTx}; |
| 15 | use embassy_nrf::gpio::{AnyPin, Level, Output, OutputDrive, Pin}; | 16 | use embassy_nrf::gpio::{AnyPin, Level, Output, OutputDrive, Pin}; |
| @@ -58,34 +59,38 @@ async fn control_task( | |||
| 58 | unwrap!( | 59 | unwrap!( |
| 59 | control | 60 | control |
| 60 | .run(&config, |status| { | 61 | .run(&config, |status| { |
| 61 | let Some(IpAddr::V4(addr)) = status.ip else { | 62 | stack.set_config_v4(status_to_config(status)); |
| 62 | panic!("Unexpected IP address"); | ||
| 63 | }; | ||
| 64 | let addr = Ipv4Address(addr.octets()); | ||
| 65 | |||
| 66 | let gateway = if let Some(IpAddr::V4(addr)) = status.gateway { | ||
| 67 | Some(Ipv4Address(addr.octets())) | ||
| 68 | } else { | ||
| 69 | None | ||
| 70 | }; | ||
| 71 | |||
| 72 | let mut dns_servers = Vec::new(); | ||
| 73 | for dns in status.dns.iter() { | ||
| 74 | if let IpAddr::V4(ip) = dns { | ||
| 75 | unwrap!(dns_servers.push(Ipv4Address(ip.octets()))); | ||
| 76 | } | ||
| 77 | } | ||
| 78 | |||
| 79 | stack.set_config_v4(embassy_net::ConfigV4::Static(embassy_net::StaticConfigV4 { | ||
| 80 | address: Ipv4Cidr::new(addr, 32), | ||
| 81 | gateway, | ||
| 82 | dns_servers, | ||
| 83 | })); | ||
| 84 | }) | 63 | }) |
| 85 | .await | 64 | .await |
| 86 | ); | 65 | ); |
| 87 | } | 66 | } |
| 88 | 67 | ||
| 68 | fn status_to_config(status: &Status) -> embassy_net::ConfigV4 { | ||
| 69 | let Some(IpAddr::V4(addr)) = status.ip else { | ||
| 70 | panic!("Unexpected IP address"); | ||
| 71 | }; | ||
| 72 | let addr = Ipv4Address(addr.octets()); | ||
| 73 | |||
| 74 | let gateway = if let Some(IpAddr::V4(addr)) = status.gateway { | ||
| 75 | Some(Ipv4Address(addr.octets())) | ||
| 76 | } else { | ||
| 77 | None | ||
| 78 | }; | ||
| 79 | |||
| 80 | let mut dns_servers = Vec::new(); | ||
| 81 | for dns in status.dns.iter() { | ||
| 82 | if let IpAddr::V4(ip) = dns { | ||
| 83 | unwrap!(dns_servers.push(Ipv4Address(ip.octets()))); | ||
| 84 | } | ||
| 85 | } | ||
| 86 | |||
| 87 | embassy_net::ConfigV4::Static(embassy_net::StaticConfigV4 { | ||
| 88 | address: Ipv4Cidr::new(addr, 32), | ||
| 89 | gateway, | ||
| 90 | dns_servers, | ||
| 91 | }) | ||
| 92 | } | ||
| 93 | |||
| 89 | #[embassy_executor::task] | 94 | #[embassy_executor::task] |
| 90 | async fn blink_task(pin: AnyPin) { | 95 | async fn blink_task(pin: AnyPin) { |
| 91 | let mut led = Output::new(pin, Level::Low, OutputDrive::Standard); | 96 | let mut led = Output::new(pin, Level::Low, OutputDrive::Standard); |
| @@ -193,7 +198,6 @@ async fn main(spawner: Spawner) { | |||
| 193 | info!("txd: {}", core::str::from_utf8(msg).unwrap()); | 198 | info!("txd: {}", core::str::from_utf8(msg).unwrap()); |
| 194 | Timer::after_secs(1).await; | 199 | Timer::after_secs(1).await; |
| 195 | } | 200 | } |
| 196 | // Test auto-attach | 201 | Timer::after_secs(4).await; |
| 197 | unwrap!(control.detach().await); | ||
| 198 | } | 202 | } |
| 199 | } | 203 | } |
