From d3760522dca644e4a9e58dbee46d239607c99a4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20W=C3=BCrl?= Date: Thu, 28 Nov 2024 10:02:45 +0100 Subject: [PATCH] filter basic messages --- src/data/openmqttgateway/mod.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/data/openmqttgateway/mod.rs b/src/data/openmqttgateway/mod.rs index 8f5d1bd..0beb38b 100644 --- a/src/data/openmqttgateway/mod.rs +++ b/src/data/openmqttgateway/mod.rs @@ -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) => { @@ -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) @@ -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) -> (Arc>, Vec>) {