Skip to content

Commit

Permalink
Swap order of ID and event name in MQTT topic
Browse files Browse the repository at this point in the history
  • Loading branch information
user890104 committed Oct 26, 2024
1 parent b0b4001 commit e86c2e8
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,30 +122,30 @@ async fn process_central_event(config: &Config, adapter: &Adapter, event: Centra
let event = match event {
CentralEvent::DeviceDiscovered(id) => {
let (name, mac_address, rssi) = get_properties(adapter, &id).await?;
topic = format!("{}/{}/{}", config.mqtt_topic, "DeviceDiscovered", id.to_string());
topic = format!("{}/{}/{}", config.mqtt_topic, id.to_string(), "DeviceDiscovered");
Event::new(id.to_string(), "DeviceDiscovered".into(), mac_address, name, rssi, None, None, None)
}
CentralEvent::DeviceUpdated(id) => {
let (name, mac_address, rssi) = get_properties(adapter, &id).await?;
topic = format!("{}/{}/{}", config.mqtt_topic, "DeviceUpdated", id.to_string());
topic = format!("{}/{}/{}", config.mqtt_topic, id.to_string(), "DeviceUpdated");
Event::new(id.to_string(), "DeviceUpdated".into(), mac_address, name, rssi, None, None, None)
}
CentralEvent::DeviceConnected(id) => {
let (name, mac_address, rssi) = get_properties(adapter, &id).await?;
topic = format!("{}/{}/{}", config.mqtt_topic, "DeviceConnected", id.to_string());
topic = format!("{}/{}/{}", config.mqtt_topic, id.to_string(), "DeviceConnected");
Event::new(id.to_string(), "DeviceConnected".into(), mac_address, name, rssi, None, None, None)
}
CentralEvent::DeviceDisconnected(id) => {
let (name, mac_address, rssi) = get_properties(adapter, &id).await?;
topic = format!("{}/{}/{}", config.mqtt_topic, "DeviceDisconnected", id.to_string());
topic = format!("{}/{}/{}", config.mqtt_topic, id.to_string(), "DeviceDisconnected");
Event::new(id.to_string(), "DeviceDisconnected".into(), mac_address, name, rssi, None, None, None)
}
CentralEvent::ManufacturerDataAdvertisement { id, manufacturer_data } => {
let data = manufacturer_data.iter().
map(|(k, v)| (k.clone(), hex::encode(v))).
collect();
let (name, mac_address, rssi) = get_properties(adapter, &id).await?;
topic = format!("{}/{}/{}", config.mqtt_topic, "ManufacturerDataAdvertisement", id.to_string());
topic = format!("{}/{}/{}", config.mqtt_topic, id.to_string(), "ManufacturerDataAdvertisement");

if verbose {
let peripheral = adapter.peripheral(&id).await?;
Expand All @@ -157,7 +157,7 @@ async fn process_central_event(config: &Config, adapter: &Adapter, event: Centra
}
CentralEvent::ServiceDataAdvertisement { id, service_data } => {
let (name, mac_address, rssi) = get_properties(adapter, &id).await?;
topic = format!("{}/{}/{}", config.mqtt_topic, "ServiceDataAdvertisement", id.to_string());
topic = format!("{}/{}/{}", config.mqtt_topic, id.to_string(), "ServiceDataAdvertisement");
let data = service_data.iter().
map(|(k, v)| (k.clone(), hex::encode(v))).
collect();
Expand All @@ -172,7 +172,7 @@ async fn process_central_event(config: &Config, adapter: &Adapter, event: Centra
}
CentralEvent::ServicesAdvertisement { id, services } => {
let (name, mac_address, rssi) = get_properties(adapter, &id).await?;
topic = format!("{}/{}/{}", config.mqtt_topic, "ServicesAdvertisement", id.to_string());
topic = format!("{}/{}/{}", config.mqtt_topic, id.to_string(), "ServicesAdvertisement");

if verbose {
let peripheral = adapter.peripheral(&id).await?;
Expand Down

0 comments on commit e86c2e8

Please sign in to comment.