@@ -15,29 +15,24 @@ async fn main() -> anyhow::Result<()> {
1515 "ls -ls" . to_string ( )
1616 } ;
1717
18- let username: Option < String > = None ;
19- let password: Option < String > = None ;
20-
21- let config_path: PathBuf = "./config.yml" . parse ( ) . unwrap ( ) ;
22- let publish_client_id = "root" ;
23- //let username:Option<String> = Some("".to_string());
24- //let password:Option<String> = Some("".to_string());
18+ let config_path: PathBuf = "./ctrl_config.yml" . parse ( ) . unwrap ( ) ;
19+ //let config_path:PathBuf = "./config.prod.yml".parse().unwrap();
2520
2621 let is_terminal = std:: io:: stdout ( ) . is_terminal ( ) ;
2722
2823 tracing_subscriber:: fmt ( ) . with_env_filter ( EnvFilter :: try_from_default_env ( ) . unwrap_or_else ( |_| EnvFilter :: from ( "debug" ) ) , )
2924 . with_ansi ( is_terminal) . init ( ) ;
3025
31- let config = mproxy:: config:: Config :: new ( Some ( config_path) ) . unwrap ( ) ;
26+ let config = mproxy:: config:: CtrlConfig :: new ( config_path) . unwrap ( ) ;
3227
33- let mqtt_url = format ! ( "{}?client_id={}" , & config. server, publish_client_id ) ;
28+ let mqtt_url = format ! ( "{}?client_id={}" , & config. server, & config . client_id ) ;
3429 let mut options = MqttOptions :: parse_url ( & mqtt_url) . unwrap ( ) ;
35- if matches ! ( password , Some ( _) ) && matches ! ( username , Some ( _) ) {
36- options. set_credentials ( username. unwrap ( ) , password. unwrap ( ) ) ;
30+ if matches ! ( config . username , Some ( _) ) && matches ! ( config . password , Some ( _) ) {
31+ options. set_credentials ( config . username . clone ( ) . unwrap ( ) , config . password . clone ( ) . unwrap ( ) ) ;
3732 }
3833 let ( client, mut eventloop) = AsyncClient :: new ( options, 20 ) ;
3934
40- let topic = config. get_response_command_topic ( ) ;
35+ let topic = config. get_subscribe_command_topic ( ) ;
4136 client. subscribe ( topic, QoS :: ExactlyOnce ) . await ?;
4237
4338 tokio:: spawn ( async move {
@@ -63,7 +58,7 @@ async fn main() -> anyhow::Result<()> {
6358 } ) ;
6459 let command = RequestMessage :: Cmd { command : command. to_string ( ) , request_id : "test_request_id" . to_string ( ) } ;
6560 let command = serde_json:: to_vec ( & command) . unwrap ( ) ;
66- client. publish ( config. get_command_topic ( ) , QoS :: ExactlyOnce , false , command) . await ?;
61+ client. publish ( config. get_publish_command_topic ( ) , QoS :: ExactlyOnce , false , command) . await ?;
6762 tokio:: signal:: ctrl_c ( ) . await ?;
6863
6964 Ok ( ( ) )
0 commit comments