Skip to content

Commit

Permalink
filter basic messages
Browse files Browse the repository at this point in the history
  • Loading branch information
wuan committed Nov 28, 2024
1 parent 26d2084 commit d376052
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/data/openmqttgateway/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ impl OpenMqttGatewayParser {
let mut tags = HashMap::new();
tags.insert(String::from("device"), String::from(device_id));
tags.insert(String::from("gateway"), String::from(gateway_id));

let base_tag_count = tags.len();

for (key, value) in result {
match value {
Value::Number(value) => {
Expand All @@ -99,7 +102,10 @@ impl OpenMqttGatewayParser {
}
}
}
data = Some(Data { fields, tags });

if fields.contains_key("rssi") && fields.len() > 1 && tags.len() > base_tag_count {
data = Some(Data { fields, tags });
}
}
}
Ok(data)
Expand Down Expand Up @@ -130,6 +136,21 @@ mod tests {

Ok(())
}

#[test]
fn test_parse_ignored() -> Result<()> {
let mut parser = OpenMqttGatewayParser::new();
let message = Message::new(
"blegateway/D12331654712/BTtoMQTT/283146C17616",
"{\"id\":\"28:31:46:C1:76:16\",\"rssi\":-92}",
QOS_1,
);
let result = parser.parse(&message)?;

assert!(result.is_none());

Ok(())
}
}

pub fn create_logger(targets: Vec<Target>) -> (Arc<Mutex<dyn CheckMessage>>, Vec<JoinHandle<()>>) {
Expand Down

0 comments on commit d376052

Please sign in to comment.