mirror of
https://github.com/stakwork/sphinx-key.git
synced 2025-12-20 16:54:32 +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::sync::mpsc;
|
||||||
use std::thread;
|
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 RETURN_TOPIC: &str = "sphinx-return";
|
||||||
pub const USERNAME: &str = "sphinx-key";
|
pub const USERNAME: &str = "sphinx-key";
|
||||||
pub const PASSWORD: &str = "sphinx-key-pass";
|
pub const PASSWORD: &str = "sphinx-key-pass";
|
||||||
@@ -82,11 +84,19 @@ pub fn start_listening(
|
|||||||
let topic_opt = msg.topic();
|
let topic_opt = msg.topic();
|
||||||
if let Some(topic) = topic_opt {
|
if let Some(topic) = topic_opt {
|
||||||
match topic {
|
match topic {
|
||||||
TOPIC => tx
|
VLS_TOPIC => tx
|
||||||
.send(CoreEvent::VlsMessage(msg.data().to_vec()))
|
.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),
|
_ => log::warn!("unrecognized topic {}", topic),
|
||||||
};
|
};
|
||||||
|
} else {
|
||||||
|
log::warn!("empty topic in msg!!!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::Deleted(_mes_id) => info!("RECEIVED Deleted MESSAGE"),
|
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::config::Config;
|
||||||
use crate::core::init::make_init_msg;
|
use crate::core::init::make_init_msg;
|
||||||
|
|
||||||
@@ -51,8 +51,12 @@ pub fn make_event_loop(
|
|||||||
// wait for a Connection first.
|
// wait for a Connection first.
|
||||||
match event {
|
match event {
|
||||||
Event::Connected => {
|
Event::Connected => {
|
||||||
log::info!("SUBSCRIBE to {}", TOPIC);
|
log::info!("SUBSCRIBE to {}", VLS_TOPIC);
|
||||||
mqtt.subscribe(TOPIC, QOS)
|
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");
|
.expect("could not MQTT subscribe");
|
||||||
led_tx.send(Status::Connected).unwrap();
|
led_tx.send(Status::Connected).unwrap();
|
||||||
break;
|
break;
|
||||||
@@ -72,8 +76,12 @@ pub fn make_event_loop(
|
|||||||
while let Ok(event) = rx.recv() {
|
while let Ok(event) = rx.recv() {
|
||||||
match event {
|
match event {
|
||||||
Event::Connected => {
|
Event::Connected => {
|
||||||
log::info!("SUBSCRIBE TO {}", TOPIC);
|
log::info!("SUBSCRIBE TO {}", VLS_TOPIC);
|
||||||
mqtt.subscribe(TOPIC, QOS)
|
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");
|
.expect("could not MQTT subscribe");
|
||||||
led_tx.send(Status::Connected).unwrap();
|
led_tx.send(Status::Connected).unwrap();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user