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>,
|
||||
) -> Result<(MqttCommands, MqttUpdates), String> {
|
||||
let last_will = LastWill {
|
||||
topic: format!("{}/status", crate::MQTT_ID),
|
||||
topic: format!("/{}/status", crate::MQTT_ID),
|
||||
message: "disconnected".to_string(),
|
||||
qos: QoS::AtLeastOnce,
|
||||
retain: true,
|
||||
|
@ -26,7 +26,7 @@ pub fn mqtt_connect(
|
|||
match MqttClient::start(options) {
|
||||
Ok((mut client, notifications)) => {
|
||||
match client.publish(
|
||||
format!("{}/status", crate::MQTT_ID),
|
||||
format!("/{}/status", crate::MQTT_ID),
|
||||
QoS::AtLeastOnce,
|
||||
true,
|
||||
"connected",
|
||||
|
|
|
@ -46,7 +46,7 @@ impl MqttCommands {
|
|||
fn handle_publish(&self, data: Publish) {
|
||||
lazy_static! {
|
||||
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();
|
||||
}
|
||||
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> {
|
||||
info!("Add light: {}", lightname);
|
||||
self.client.publish(
|
||||
format!("{}/lights", crate::MQTT_ID),
|
||||
format!("/{}/lights", crate::MQTT_ID),
|
||||
QoS::AtLeastOnce,
|
||||
false,
|
||||
format!("{}:{}", id, lightname),
|
||||
)?;
|
||||
let base_url = format!("{}/lights/{}/", crate::MQTT_ID, lightname);
|
||||
let base_url = format!("/{}/lights/{}/", crate::MQTT_ID, lightname);
|
||||
self.client.publish(
|
||||
base_url.clone() + "status/connected",
|
||||
QoS::AtLeastOnce,
|
||||
|
@ -65,7 +65,7 @@ impl MqttUpdates {
|
|||
}
|
||||
Status::Remove(_name) => {
|
||||
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,
|
||||
true,
|
||||
"false",
|
||||
|
@ -82,7 +82,7 @@ impl MqttUpdates {
|
|||
let (detail, value) = update.status.unravel();
|
||||
if let Err(err) = self.client.publish(
|
||||
format!(
|
||||
"{}/lights/{}/status/{}",
|
||||
"/{}/lights/{}/status/{}",
|
||||
crate::MQTT_ID,
|
||||
update.lightname,
|
||||
detail
|
||||
|
|
Loading…
Reference in a new issue