Add / before topic
This commit is contained in:
parent
b45d0d9a97
commit
940db5e20f
3 changed files with 7 additions and 7 deletions
|
@ -11,7 +11,7 @@ pub fn mqtt_connect(
|
||||||
updates: crossbeam_channel::Receiver<Status>,
|
updates: crossbeam_channel::Receiver<Status>,
|
||||||
) -> Result<(MqttCommands, MqttUpdates), String> {
|
) -> Result<(MqttCommands, MqttUpdates), String> {
|
||||||
let last_will = LastWill {
|
let last_will = LastWill {
|
||||||
topic: format!("{}/status", crate::MQTT_ID),
|
topic: format!("/{}/status", crate::MQTT_ID),
|
||||||
message: "disconnected".to_string(),
|
message: "disconnected".to_string(),
|
||||||
qos: QoS::AtLeastOnce,
|
qos: QoS::AtLeastOnce,
|
||||||
retain: true,
|
retain: true,
|
||||||
|
@ -26,7 +26,7 @@ pub fn mqtt_connect(
|
||||||
match MqttClient::start(options) {
|
match MqttClient::start(options) {
|
||||||
Ok((mut client, notifications)) => {
|
Ok((mut client, notifications)) => {
|
||||||
match client.publish(
|
match client.publish(
|
||||||
format!("{}/status", crate::MQTT_ID),
|
format!("/{}/status", crate::MQTT_ID),
|
||||||
QoS::AtLeastOnce,
|
QoS::AtLeastOnce,
|
||||||
true,
|
true,
|
||||||
"connected",
|
"connected",
|
||||||
|
|
|
@ -46,7 +46,7 @@ impl MqttCommands {
|
||||||
fn handle_publish(&self, data: Publish) {
|
fn handle_publish(&self, data: Publish) {
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref matchStr: String =
|
static ref matchStr: String =
|
||||||
format!(r"^{}/lights/([^/]+)/command/(\w+)$", crate::MQTT_ID);
|
format!(r"^/{}/lights/([^/]+)/command/(\w+)$", crate::MQTT_ID);
|
||||||
static ref RE: Regex = Regex::new(&matchStr).unwrap();
|
static ref RE: Regex = Regex::new(&matchStr).unwrap();
|
||||||
}
|
}
|
||||||
let matching = match RE.captures(&data.topic_name) {
|
let matching = match RE.captures(&data.topic_name) {
|
||||||
|
|
|
@ -15,12 +15,12 @@ impl MqttUpdates {
|
||||||
pub fn add_light(&mut self, id: &str, lightname: &str) -> Result<(), rumqtt::ClientError> {
|
pub fn add_light(&mut self, id: &str, lightname: &str) -> Result<(), rumqtt::ClientError> {
|
||||||
info!("Add light: {}", lightname);
|
info!("Add light: {}", lightname);
|
||||||
self.client.publish(
|
self.client.publish(
|
||||||
format!("{}/lights", crate::MQTT_ID),
|
format!("/{}/lights", crate::MQTT_ID),
|
||||||
QoS::AtLeastOnce,
|
QoS::AtLeastOnce,
|
||||||
false,
|
false,
|
||||||
format!("{}:{}", id, lightname),
|
format!("{}:{}", id, lightname),
|
||||||
)?;
|
)?;
|
||||||
let base_url = format!("{}/lights/{}/", crate::MQTT_ID, lightname);
|
let base_url = format!("/{}/lights/{}/", crate::MQTT_ID, lightname);
|
||||||
self.client.publish(
|
self.client.publish(
|
||||||
base_url.clone() + "status/connected",
|
base_url.clone() + "status/connected",
|
||||||
QoS::AtLeastOnce,
|
QoS::AtLeastOnce,
|
||||||
|
@ -65,7 +65,7 @@ impl MqttUpdates {
|
||||||
}
|
}
|
||||||
Status::Remove(_name) => {
|
Status::Remove(_name) => {
|
||||||
if let Err(err) = self.client.publish(
|
if let Err(err) = self.client.publish(
|
||||||
format!("{}/lights/{}/status/connected", crate::MQTT_ID, _name),
|
format!("/{}/lights/{}/status/connected", crate::MQTT_ID, _name),
|
||||||
QoS::AtLeastOnce,
|
QoS::AtLeastOnce,
|
||||||
true,
|
true,
|
||||||
"false",
|
"false",
|
||||||
|
@ -82,7 +82,7 @@ impl MqttUpdates {
|
||||||
let (detail, value) = update.status.unravel();
|
let (detail, value) = update.status.unravel();
|
||||||
if let Err(err) = self.client.publish(
|
if let Err(err) = self.client.publish(
|
||||||
format!(
|
format!(
|
||||||
"{}/lights/{}/status/{}",
|
"/{}/lights/{}/status/{}",
|
||||||
crate::MQTT_ID,
|
crate::MQTT_ID,
|
||||||
update.lightname,
|
update.lightname,
|
||||||
detail
|
detail
|
||||||
|
|
Loading…
Reference in a new issue