sub vls, cotrol, and ota topics

This commit is contained in:
Evan Feenstra
2022-08-31 13:39:09 -07:00
parent bfa13efd70
commit 30ef762605
2 changed files with 26 additions and 8 deletions

View File

@@ -12,7 +12,9 @@ use log::*;
use std::sync::mpsc;
use std::thread;
pub const TOPIC: &str = "sphinx";
pub const VLS_TOPIC: &str = "sphinx";
pub const CONTROL_TOPIC: &str = "sphinx-control";
pub const OTA_TOPIC: &str = "sphinx-ota";
pub const RETURN_TOPIC: &str = "sphinx-return";
pub const USERNAME: &str = "sphinx-key";
pub const PASSWORD: &str = "sphinx-key-pass";
@@ -82,11 +84,19 @@ pub fn start_listening(
let topic_opt = msg.topic();
if let Some(topic) = topic_opt {
match topic {
TOPIC => tx
VLS_TOPIC => tx
.send(CoreEvent::VlsMessage(msg.data().to_vec()))
.expect("couldnt send Event::Message"),
.expect("couldnt send Event::VlsMessage"),
CONTROL_TOPIC => tx
.send(CoreEvent::Control(msg.data().to_vec()))
.expect("couldnt send Event::Control"),
OTA_TOPIC => tx
.send(CoreEvent::Ota(msg.data().to_vec()))
.expect("couldnt send Event::Ota"),
_ => log::warn!("unrecognized topic {}", topic),
};
} else {
log::warn!("empty topic in msg!!!");
}
}
Event::Deleted(_mes_id) => info!("RECEIVED Deleted MESSAGE"),

View File

@@ -1,4 +1,4 @@
use crate::conn::mqtt::{QOS, RETURN_TOPIC, TOPIC};
use crate::conn::mqtt::{CONTROL_TOPIC, OTA_TOPIC, QOS, RETURN_TOPIC, VLS_TOPIC};
use crate::core::config::Config;
use crate::core::init::make_init_msg;
@@ -51,8 +51,12 @@ pub fn make_event_loop(
// wait for a Connection first.
match event {
Event::Connected => {
log::info!("SUBSCRIBE to {}", TOPIC);
mqtt.subscribe(TOPIC, QOS)
log::info!("SUBSCRIBE to {}", VLS_TOPIC);
mqtt.subscribe(VLS_TOPIC, QOS)
.expect("could not MQTT subscribe");
mqtt.subscribe(CONTROL_TOPIC, QOS)
.expect("could not MQTT subscribe");
mqtt.subscribe(OTA_TOPIC, QOS)
.expect("could not MQTT subscribe");
led_tx.send(Status::Connected).unwrap();
break;
@@ -72,8 +76,12 @@ pub fn make_event_loop(
while let Ok(event) = rx.recv() {
match event {
Event::Connected => {
log::info!("SUBSCRIBE TO {}", TOPIC);
mqtt.subscribe(TOPIC, QOS)
log::info!("SUBSCRIBE TO {}", VLS_TOPIC);
mqtt.subscribe(VLS_TOPIC, QOS)
.expect("could not MQTT subscribe");
mqtt.subscribe(CONTROL_TOPIC, QOS)
.expect("could not MQTT subscribe");
mqtt.subscribe(OTA_TOPIC, QOS)
.expect("could not MQTT subscribe");
led_tx.send(Status::Connected).unwrap();
}