pass mqtt host/port in loop
This commit is contained in:
parent
d71a7bb2a9
commit
059263d7ea
2 changed files with 6 additions and 6 deletions
|
@ -36,7 +36,7 @@ fn main() -> anyhow::Result<()> {
|
||||||
//let accel_sender = gps_sender.clone();
|
//let accel_sender = gps_sender.clone();
|
||||||
|
|
||||||
//let _ = gps::main(gps_tx, gps_rx, gps_uart, gps_sender)?;
|
//let _ = gps::main(gps_tx, gps_rx, gps_uart, gps_sender)?;
|
||||||
threads.push(thread::spawn(move || gps::main(gps_tx, gps_rx, gps_uart, gps_sender)));
|
threads.push(thread::spawn(move || gps::main(gps_tx, gps_rx, gps_uart, gps_sender.clone())));
|
||||||
thread::sleep(Duration::from_millis(1000));
|
thread::sleep(Duration::from_millis(1000));
|
||||||
//threads.push(thread::spawn(move || accel::main(accel_sender)));
|
//threads.push(thread::spawn(move || accel::main(accel_sender)));
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ fn main() -> anyhow::Result<()> {
|
||||||
let _ = mdm.echo(false).unwrap_or(());
|
let _ = mdm.echo(false).unwrap_or(());
|
||||||
println!("resetting modem ... ");
|
println!("resetting modem ... ");
|
||||||
println!("======================= MODEM =======================");
|
println!("======================= MODEM =======================");
|
||||||
let _ = mdm.start_sending(mqtt_username, mqtt_password).unwrap_or(());
|
let _ = mdm.mqtt_send_position_loop("51.158.66.64", 7887, mqtt_username, mqtt_password).unwrap_or(());
|
||||||
let _ = mdm.tcp_close_connection().unwrap_or(());
|
let _ = mdm.tcp_close_connection().unwrap_or(());
|
||||||
thread::sleep(Duration::from_millis(1500));
|
thread::sleep(Duration::from_millis(1500));
|
||||||
}
|
}
|
||||||
|
|
|
@ -518,7 +518,7 @@ impl<UART: serial::Uart, PWK: OutputPin, RST: OutputPin, PW: OutputPin> Modem<UA
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn start_sending(&mut self, mqtt_username: &str, mqtt_password: &str) -> anyhow::Result<()> {
|
pub fn mqtt_send_position_loop(&mut self, host: &str, port: u16, username: &str, password: &str) -> anyhow::Result<()> {
|
||||||
if !self.is_gprs_attached()? {
|
if !self.is_gprs_attached()? {
|
||||||
let _ = self.gprs_attach_ap(crate::config::MTS)?;
|
let _ = self.gprs_attach_ap(crate::config::MTS)?;
|
||||||
let _ = self.try_connect_gprs()?;
|
let _ = self.try_connect_gprs()?;
|
||||||
|
@ -531,14 +531,14 @@ impl<UART: serial::Uart, PWK: OutputPin, RST: OutputPin, PW: OutputPin> Modem<UA
|
||||||
let _ = self.send("AT+CIPRXGET=1", "OK");
|
let _ = self.send("AT+CIPRXGET=1", "OK");
|
||||||
|
|
||||||
for _ in 0..5 {
|
for _ in 0..5 {
|
||||||
if let Ok(_) = self.tcp_connect("51.158.66.64", 7887) {
|
if let Ok(_) = self.tcp_connect(host, port) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let device_id = "c36a72df-5bd6-4f9b-995d-059433bc3267";
|
let device_id = "c36a72df-5bd6-4f9b-995d-059433bc3267";
|
||||||
println!("connecting to MQTT with ({}:{})", mqtt_username, mqtt_password);
|
println!("connecting to MQTT with ({}:{})", username, password);
|
||||||
let _ = self.mqtt_connect(device_id, mqtt_username, mqtt_password)?;
|
let _ = self.mqtt_connect(device_id, username, password)?;
|
||||||
|
|
||||||
println!("entering queue receive loop ...");
|
println!("entering queue receive loop ...");
|
||||||
let mut err_count = 0;
|
let mut err_count = 0;
|
||||||
|
|
Loading…
Reference in a new issue