diff --git a/src/config.rs b/src/config.rs index 62f368f..85dc37a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -4,8 +4,14 @@ pub struct GprsAp<'a> { pub password: &'a str, } -pub const A1_GPRS_AP: GprsAp = GprsAp { +pub const A1: GprsAp = GprsAp { apn: "internet", username: "internet", password: "internet", }; + +pub const MTS: GprsAp = GprsAp { + apn: "gprswap", + username: "mts", + password: "064", +}; diff --git a/src/modem.rs b/src/modem.rs index 6018de2..78d0cb9 100644 --- a/src/modem.rs +++ b/src/modem.rs @@ -197,15 +197,15 @@ impl Modem { self.send_command(Command::gprs_bearer_status()) } - pub fn gprs_attach_ap(&mut self, apn: &str, username: &str, password: &str)-> Result<()> { + pub fn gprs_attach_ap(&mut self, config: crate::config::GprsAp)-> Result<()> { println!("init gprs ..."); let _ = self.send_command(Command::gprs_init())?; - println!("setting up gprs credentials for apn {}, {}:{})", apn, username, password); + println!("setting up gprs credentials for apn {}, {}:{})", config.apn, config.username, config.password); - let _ = self.send_command(Command::gprs_set_apn(apn))?; - let _ = self.send_command(Command::gprs_set_user(username))?; - let _ = self.send_command(Command::gprs_set_pwd(password))?; + let _ = self.send_command(Command::gprs_set_apn(config.apn))?; + let _ = self.send_command(Command::gprs_set_user(config.username))?; + let _ = self.send_command(Command::gprs_set_pwd(config.password))?; Ok(()) } @@ -223,6 +223,7 @@ impl Modem { fn try_connect_gprs(&mut self) -> Result<()> { let mut retries = 0; + println!("TRYING TO CONNECT TO GPRS"); loop { if self.is_gprs_attached()? { let _ = self.gprs_connect()?; @@ -551,11 +552,7 @@ where loop { if !mdm.is_gprs_attached()? { - let _ = mdm.gprs_attach_ap( - crate::config::A1_GPRS_AP.apn, - crate::config::A1_GPRS_AP.username, - crate::config::A1_GPRS_AP.password, - )?; + let _ = mdm.gprs_attach_ap(crate::config::A1)?; } if let Ok(()) = mdm.try_connect_gprs() { // When command AT+CIPQSEND=0, it is in normal sending mode. In this mode, after user