@@ -18,7 +18,7 @@ use bleps::{
18
18
Ble , HciConnector ,
19
19
} ;
20
20
21
- use esp_wifi:: { ble:: controller:: BleConnector , current_millis, wifi_interface:: Network } ;
21
+ use esp_wifi:: { ble:: controller:: BleConnector , current_millis, wifi_interface:: WifiStack } ;
22
22
23
23
use embedded_io:: blocking:: * ;
24
24
use embedded_svc:: ipv4:: Interface ;
@@ -27,14 +27,13 @@ use embedded_svc::wifi::{AccessPointInfo, ClientConfiguration, Configuration, Wi
27
27
use esp_backtrace as _;
28
28
use esp_println:: { logger:: init_logger, print, println} ;
29
29
use esp_wifi:: initialize;
30
- use esp_wifi:: wifi:: { WifiError , utils:: create_network_interface} ;
31
- use esp_wifi:: { create_network_stack_storage, network_stack_storage} ;
30
+ use esp_wifi:: wifi:: { utils:: create_network_interface, WifiError } ;
32
31
use hal:: {
33
32
clock:: { ClockControl , CpuClock } ,
34
33
Rng ,
35
34
} ;
36
35
use hal:: { peripherals:: Peripherals , prelude:: * , Rtc } ;
37
- use smoltcp:: wire:: Ipv4Address ;
36
+ use smoltcp:: { iface :: SocketStorage , wire:: Ipv4Address } ;
38
37
39
38
#[ cfg( feature = "esp32c3" ) ]
40
39
use hal:: system:: SystemExt ;
@@ -72,9 +71,9 @@ fn main() -> ! {
72
71
73
72
rtc. rwdt . disable ( ) ;
74
73
75
- let mut storage = create_network_stack_storage ! ( 3 , 8 , 1 , 1 ) ;
76
- let ethernet = create_network_interface ( network_stack_storage ! ( storage ) ) ;
77
- let mut wifi_interface = esp_wifi :: wifi_interface :: Wifi :: new ( ethernet ) ;
74
+ let mut socket_set_entries : [ SocketStorage ; 3 ] = Default :: default ( ) ;
75
+ let ( iface , device , sockets ) = create_network_interface ( & mut socket_set_entries ) ;
76
+ let mut wifi_stack = WifiStack :: new ( iface , device , sockets , current_millis ) ;
78
77
79
78
#[ cfg( feature = "esp32c3" ) ]
80
79
{
@@ -89,11 +88,10 @@ fn main() -> ! {
89
88
initialize ( timg1. timer0 , Rng :: new ( peripherals. RNG ) , & clocks) . unwrap ( ) ;
90
89
}
91
90
92
- println ! ( "is wifi started: {:?}" , wifi_interface . is_started( ) ) ;
91
+ println ! ( "is wifi started: {:?}" , wifi_stack . is_started( ) ) ;
93
92
94
93
println ! ( "Start Wifi Scan" ) ;
95
- let res: Result < ( heapless:: Vec < AccessPointInfo , 10 > , usize ) , WifiError > =
96
- wifi_interface. scan_n ( ) ;
94
+ let res: Result < ( heapless:: Vec < AccessPointInfo , 10 > , usize ) , WifiError > = wifi_stack. scan_n ( ) ;
97
95
if let Ok ( ( res, _count) ) = res {
98
96
for ap in res {
99
97
println ! ( "{:?}" , ap) ;
@@ -106,16 +104,16 @@ fn main() -> ! {
106
104
password : PASSWORD . into ( ) ,
107
105
..Default :: default ( )
108
106
} ) ;
109
- let res = wifi_interface . set_configuration ( & client_config) ;
107
+ let res = wifi_stack . set_configuration ( & client_config) ;
110
108
println ! ( "wifi_connect returned {:?}" , res) ;
111
109
112
- println ! ( "{:?}" , wifi_interface . get_capabilities( ) ) ;
113
- println ! ( "wifi_connect {:?}" , wifi_interface . connect( ) ) ;
110
+ println ! ( "{:?}" , wifi_stack . get_capabilities( ) ) ;
111
+ println ! ( "wifi_connect {:?}" , wifi_stack . connect( ) ) ;
114
112
115
113
// wait to get connected
116
114
println ! ( "Wait to get connected" ) ;
117
115
loop {
118
- let res = wifi_interface . is_connected ( ) ;
116
+ let res = wifi_stack . is_connected ( ) ;
119
117
match res {
120
118
Ok ( connected) => {
121
119
if connected {
@@ -128,18 +126,15 @@ fn main() -> ! {
128
126
}
129
127
}
130
128
}
131
- println ! ( "{:?}" , wifi_interface . is_connected( ) ) ;
129
+ println ! ( "{:?}" , wifi_stack . is_connected( ) ) ;
132
130
133
131
// wait for getting an ip address
134
132
println ! ( "Wait to get an ip address" ) ;
135
- let network = Network :: new ( wifi_interface, current_millis) ;
136
133
loop {
137
- network . poll_dhcp ( ) . unwrap ( ) ;
134
+ wifi_stack . work ( ) ;
138
135
139
- network. work ( ) ;
140
-
141
- if network. is_iface_up ( ) {
142
- println ! ( "got ip {:?}" , network. get_ip_info( ) ) ;
136
+ if wifi_stack. is_iface_up ( ) {
137
+ println ! ( "got ip {:?}" , wifi_stack. get_ip_info( ) ) ;
143
138
break ;
144
139
}
145
140
}
@@ -171,7 +166,7 @@ fn main() -> ! {
171
166
172
167
let mut rx_buffer = [ 0u8 ; 1536 ] ;
173
168
let mut tx_buffer = [ 0u8 ; 1536 ] ;
174
- let mut socket = network . get_socket ( & mut rx_buffer, & mut tx_buffer) ;
169
+ let mut socket = wifi_stack . get_socket ( & mut rx_buffer, & mut tx_buffer) ;
175
170
176
171
loop {
177
172
println ! ( "Making HTTP request" ) ;
0 commit comments