mqtt-datasource icon indicating copy to clipboard operation
mqtt-datasource copied to clipboard

Support complex MQTT Payloads

Open Appelg opened this issue 3 years ago • 16 comments

Hello!

Nice plugin. Can you please update the documentation with information on how to format the payload? No matter what I try, all I get is "Data does not have a time field"

Can I have complex objects with multiple values? Can I instruct it to parse the json? E.g

{
  foo: { 
   bar: 1337
  }
  baz: 555
}

Thanks!

Appelg avatar Jun 09 '21 16:06 Appelg

Currently the plugin supports simple values ie "555" or a simple map[string]number -- we should be able to support a more complex shape

ryantxu avatar Jun 15 '21 18:06 ryantxu

Thanks!

The no-data was solved by setting a low timerange, like 5 mins. I used it in an existing dashboard which defaulted to 30d.

Appelg avatar Jun 23 '21 13:06 Appelg

I'm new to grafana. Could you give more specific examples of the what the data should look like (i.e. what does map[string]number mean?) . I can generate data points with mosquitto_pub -t grafana -m 555 but want to attach a time to the data.

whbruce avatar Aug 05 '21 20:08 whbruce

currently we support very basic JSON structures like:

{
    'value1': 1.0,
    'value2': 2,
    'value3': 3.33,
    ...
}

notice how the key is string and the value is number in the JSON, that is what map[string]number (golang lingo) means in this context.

we do plan to bring support for more complex JSON structures soon (contributions are always welcome too 🙂)

as far as the timestamp is concerned currently we just naively use time.Now() for every message coming in, see: https://github.com/grafana/mqtt-datasource/blob/46b617808aab084804a89dd5b7ad31462e106d7f/pkg/mqtt/client.go#L98

however i do agree we should have a way to set that based on the incoming message in cases where the data is delayed and needs a timestamp on the publisher side to be propagated. any suggestions on this?

atifali avatar Aug 06 '21 03:08 atifali

Thanks for the detailed reply. I'm currently sending just raw data. Once I understand more about Grafana I'll try out your more complex json payload and recommend how time might be encoded.

Re: contributions your typescript and go code (and how they interact) is beyond me at this point (I'm a C++/Java/Python guy).

whbruce avatar Aug 06 '21 19:08 whbruce

support for more data types with the JSON payload would be super handy as part of this enhancement, see: https://github.com/grafana/mqtt-datasource/issues/19

atifali avatar Aug 16 '21 18:08 atifali

Hi @atifali,

How do you plan to support more complex json? will that be arbitrary json? Do you have plans to support timestamps that are part of the MQTT message?

This has caught my attention, I think it is awesome: https://grafana.com/blog/2021/08/12/streaming-real-time-sensor-data-to-grafana-using-mqtt-and-grafana-live/

But we can currently not use it, because our json is more complex and also subject to change.

rafaelschlatter avatar Sep 09 '21 17:09 rafaelschlatter

Hi @rafaelschlatter really appreciate your enthusiasm and patience with this. We are currently in the midst of incorporating a very versatile and flexible automatic JSON processor within Live "pipelines" in Grafana core (see: https://github.com/grafana/grafana/tree/main/pkg/services/live/pipeline), which will eventually be used here. This means that virtually any message that has a valid JSON format would work. Stay tuned!

atifali avatar Oct 05 '21 06:10 atifali

Sounds awesome, thanks for the update, @atifali !

rafaelschlatter avatar Oct 05 '21 06:10 rafaelschlatter

@rafaelschlatter that sounds awesome, nice work!

Appelg avatar Oct 05 '21 06:10 Appelg

Any news on this? There is an open pull request #22

andrerodi avatar Mar 16 '22 16:03 andrerodi

Hello, what is the status for the integration of the Live "pipelines" JSON processor in mqtt-datasource? Do you have any news? thanks and have a good day.

grabouillon06 avatar May 25 '22 11:05 grabouillon06

One idea about complex mqtt payloads would be to implement something like what Amazon did for the rules processing feature of IoT Core. Essentially, it allows you to use a language very close to SQL to "select" data out of a JSON object of arbitrary structure and depth, pull out the data you want, rename the fields, and do some basic math on them. Some of what they do probably wouldn't be necessary here (I don't think you really need WHERE clauses, for example).

wz2b avatar Jul 26 '22 13:07 wz2b

Sorry, which the state of this integration? I tried to understand it by clicking on the various links: closed, enhancement, open .... It's Like a stuck loop

DonatoD avatar Aug 07 '22 11:08 DonatoD

@atifali Hello, What is the status of this? Thanks

OlivierGre avatar Jan 30 '23 09:01 OlivierGre

Any progress on this?

pkkrusty avatar Jun 24 '23 16:06 pkkrusty