How to publish mqtt data(on and off) from the grafana panel to a public broker?

Currently I am working on how to publish mqtt data from grafana panel. I was able to subscribe data on dashboard. But not able to publishing the data from panel.
Does anyone has any idea on how to publish data to a public broker from a panel using mqtt protocol or any way to do this.

@ashishagarwalzy Grafana is more for monitoring than to proxy-route data from a place to another so you won’t find a way to do this.

The closest thing you can do is create alerts that dispatch based on specific queries and have a service waiting for those alerts to do something with them.

@academo this blog is showing how to control device using panel in grafana.

So how they are doing this. Sending string using api and then publishing data using mqtt to device?

1 Like

@ashishagarwalzy a panel plugin is a react component rendered inside Grafana that receives as props the data a datasource query returns.

In that sense, you can basically do anything you can do with javascript. For example, send a POST requests to an API using the native fetch API with the data you want.

This is what the form panel plugin allows you to do, it has an UI to construct forms and configuration options to send that data somewhere on submission.

The important bit here and the reason of my negative answer is because you need a dedicated panel like this one to do so, you can’t do that from other panels as a native option.

@academo one more thing. Can we submit data from the panel form which will reach directly to api without going to database query?

@ashishagarwalzy What API do you mean?

As I mentioned, in a panel you can freely use the Fetch API from the browser and reach any endpoint that won’t block you due to CORS limitations.

If you are talking about the Grafana API, you can also call the Grafana API from a panel but the Grafana API doesn’t offer ways to push data into data sources because data sources are meant to provide data only.

@academo means sending the data directly to a URL. Also how can we check which line in the code or which part of the code is giving the error?

@ashishagarwalzy I am not sure I understand. what error do you mean?

@academo trying to send on/off from data manipulation panel to a URL but getting error : Request TypeError: Failed to fetch.
Also URL(only IP is present not domain name) is receiving the hit but no data is received at the URL end.
Referring this article:

Also, followed other article and Added header for cors but the result is till same.

Hi @ashishagarwalzy consider opening an issue in their plugin repository Issues · VolkovLabs/business-forms · GitHub perhaps they can give you a hand at putting together the correct setup for your use case.

@academo okay. Thanks for the support.