Support JSON in MQTT payloads
The imeptus for this is to allow embedding an event timestamp with the data, since MQTT doesn't tag messages with the time they were sent. So Instead of having a payload value like "some value", you could have: { "timestamp": 1630360029124, "value": "some value" } ... and then configure the mapping in mqtt2db to be a JSON mapping, with timestamp field name "timestamp" and value field name "value", and we just figure things out. If no mapping payload type is specified, we just assume it's a raw value as before.
This commit is contained in:
@ -53,10 +53,22 @@ pub struct InfluxDBConfig {
|
||||
pub measurement: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
#[serde(rename_all = "camelCase", tag = "type")]
|
||||
#[allow(non_camel_case_types)]
|
||||
pub enum Payload {
|
||||
#[serde(rename_all = "camelCase")]
|
||||
json {
|
||||
value_field_name: String,
|
||||
timestamp_field_name: Option<String>,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Mapping {
|
||||
pub topic: String,
|
||||
pub payload: Option<Payload>,
|
||||
pub field_name: String,
|
||||
pub value_type: ValueType,
|
||||
pub tags: HashMap<String, TagValue>,
|
||||
|
Reference in New Issue
Block a user