@@ -48,8 +48,8 @@ fn load_config(config_file: &str) -> Option<Config> {
48
48
config
49
49
}
50
50
51
- impl From < config:: AuthMethod > for AuthMethod {
52
- fn from ( value : config:: AuthMethod ) -> Self {
51
+ impl From < & config:: AuthMethod > for AuthMethod {
52
+ fn from ( value : & config:: AuthMethod ) -> Self {
53
53
format ! ( "{value:?}" ) . parse ( ) . unwrap ( )
54
54
}
55
55
}
@@ -73,20 +73,20 @@ async fn run_async(spawner: LocalSpawner) -> Result<(), anyhow::Error> {
73
73
let mut button = PinDriver :: input ( peripherals. pins . gpio14 ) ?;
74
74
button. set_pull ( Pull :: Up ) ?;
75
75
76
- let mut _wifi: Option < WifiSession > = None ;
76
+ let mut _wifi: Option < Rc < WifiSession > > = None ;
77
77
let mut _sntp: Option < EspSntp > = None ;
78
78
if let Some ( config) = & config {
79
79
let mut wifi = WifiSession :: new (
80
80
& WifiConfig {
81
81
ssid : config. wifi . ssid . clone ( ) ,
82
82
password : config. wifi . password . clone ( ) ,
83
- auth_method : Some ( ( & config. wifi . auth_method ) . into ( ) ) ,
83
+ auth_method : Some ( AuthMethod :: from ( & config. wifi . auth_method ) ) ,
84
84
} ,
85
85
peripherals. modem ,
86
86
) ?;
87
87
wifi. connect ( ) . await ?;
88
88
log:: info!( "Connected wifi: {:#?}" , wifi. get_ip_info( ) ) ;
89
- _wifi = Some ( wifi) ;
89
+ _wifi = Some ( Rc :: new ( wifi) ) ;
90
90
91
91
// Keep it around or else the SNTP service will stop
92
92
_sntp = Some ( EspSntp :: new_default ( ) ?) ;
@@ -96,6 +96,7 @@ async fn run_async(spawner: LocalSpawner) -> Result<(), anyhow::Error> {
96
96
97
97
let captured_mount_path = mount_path. clone ( ) ;
98
98
let mount_path_c_str = CString :: new ( mount_path. as_bytes ( ) ) ?;
99
+ let wifi_ref = _wifi. unwrap ( ) . clone ( ) ;
99
100
let device_info_producer: DeviceInfoProducer = Box :: new ( move || {
100
101
let mut total_volume_size: u64 = 0 ;
101
102
let mut free_volume_size: u64 = 0 ;
@@ -109,7 +110,7 @@ async fn run_async(spawner: LocalSpawner) -> Result<(), anyhow::Error> {
109
110
Ok ( DeviceInfo {
110
111
version : VERSION . to_string ( ) ,
111
112
// TODO: maybe pass in Rc of wifi instead?
112
- wifi_ip : wifi . get_ip_info ( ) . unwrap ( ) . ip . to_string ( ) ,
113
+ wifi_ip : wifi_ref . get_ip_info ( ) . unwrap ( ) . ip . to_string ( ) ,
113
114
local_time : OffsetDateTime :: now_utc ( ) ,
114
115
mount_path : captured_mount_path. to_string ( ) ,
115
116
total_volume_size,
0 commit comments