mirror of
https://github.com/stakwork/sphinx-key.git
synced 2025-12-18 15:54:31 +01:00
sub vls, cotrol, and ota topics
This commit is contained in:
@@ -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"),
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user