use whole AP config as input arg
This commit is contained in:
parent
ff779d0dc3
commit
47b333d354
2 changed files with 14 additions and 11 deletions
|
@ -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",
|
||||
};
|
||||
|
|
17
src/modem.rs
17
src/modem.rs
|
@ -197,15 +197,15 @@ impl<UART: serial::Uart> Modem<UART> {
|
|||
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<UART: serial::Uart> Modem<UART> {
|
|||
|
||||
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
|
||||
|
|
Loading…
Add table
Reference in a new issue