IoT dashboard sends command to sensors

Hello,
I am new with grafana and i am sorry for the my common question.
Currently i am creating IoT platform with Mqtt, Telegraf, InfluxDb and Grafana. So i can push data from sensors --> mqtt broker --> telegraf --> influxdb --> grafana and the data is displayed in the appropriate dashboards. Bu i want to create an opposite flow. for example: When the given putton is pushed to send that command to influxdb --> telegraf–>mqtt broker then the my device will be subscribe for a topic and will get the message. So, what is an approach for that?

  1. Is it possible to push a message to influxdb from grafana?
  2. is it possible telegraf to undestand that there is a new message on influxdb ?
    Also i have to send this a new message from telegraf to mqtt broker with appropriate topic.

I would be grateful if anyone could help me with ideas or advice. :slight_smile:

1 Like

I think that is no possible that flow.
Maybe you could send data from grafana to the mqtt broker, influx save it and your sensor receive it.
But sadly I think that doesn’t exist a panel for grafana that can make this.

I guess that you are right but i want to make a record in to InfluxDB(the goal is to store a history of commands). It is possible JS
So i am going to create a my custom panel for grafana. But the next a question is: how i can get the new rows from InfluxDB to telegraf --> mqtt broker?

Sure, also I think that the history of commands is important. But as I understand there aren’t form that Telegraf know if a command/order is available from influx, but you can send your command through mqtt and save it with telegraf-influx

Hmmmm it is strange becuse mqtt—>telegraf—>influxdb is possible but In the reverse order is not possible

I have very similar situation:
IoT temperature controller periodically sending status -> mqtt -> nodered -> influxdb -> grafana

Same as you, I wanted to change target temperature on controller from Grafana. I tried to solve it in many ways but this worked for me:

In Grafana dashboard I created html panel with html form:

<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
   <title>Temperature Controller</title>
</head>

<body>

<iframe width="0" height="0" border="0" name="dummyframe" style="visibility: hidden;" id="dummyframe"></iframe>

<form class="form-field" action="https://xxxxx" method="post" target="dummyframe"> 
  <label class="btn navbar-label">°C</label>
	<input name="sp" class="gf-form-input gf-form-input width-6" placeholder="SP" type="text">
	<input type="hidden" name="device" value="$location">
	<input type="hidden" name="username" value="user">
	<input type="hidden" name="password" value="pass">
  <button class="btn navbar-button gf-timepicker-nav-btn" onclick="ref()">Save</button>
</form>

<script>

function ref() {
  return t.timeSrv.refreshDashboard(), Promise.resolve()
}

</script>

</body>
</html>

Using this I am able to send http reqest to nodered where it is transformed to mqtt message and published to IoT temperature controller (http request from grafana -> mqtt broker -> IoT temperature controller).

2 Likes

Exaclly, i am going to try this approach. I will create a my custom plugin within grafana

1 Like

Excited to see what you come up with!

I’m using nodered => influx => grafana and would also like to send commands to my devices.
I have never dabbled in grafana plugins. But if you get something simple setup that sends commands to a nodered http post api, I might be able to take it from there…

Good luck!

For smaller scale projects checkout https://www.home-assistant.io/

My setup is using NodeRed inbetween.
Node Red has perfect capabilities to connect with MQTT brokers, manage the data and store it into InfluxDB and/or send other MQTT messages. The capabilities are endless.
As Node Red can interface with InfluxDB, it can both write and read in the database, it is is perfectly able to generate alarms or, as your original question, send MQTT messages.

I am generating quite some IOT graphs, but beyond that I have created a special project: Control Roller shutters. Normally they go up and down automatically through a central clock. But I added an ESP with a relay to change the behaviour as I wish. There are push buttons on the ESP, but I can also control through an App on my mobile (an native MQTT app you can download and customize for your purpose). All interchanges go through MQTT while Node Red is the central intelligence that controls the state of each of the Roller Shutters.

1 Like

Hi there,

thanks for bringing this up. We are also looking into the same direction and did some research about it.

The most promising thing we found is the Field Display/Editor component conceived by @ryantxu for NatelEnergy the other day. However, it looks like it is part of a custom Grafana Application implementation and not available as a piece of open source software. If this doesn’t change in the future, it might at least serve as a source for inspiration.

With kind regards,
Andreas.

Thank you for sharing, can you please share your Node Red code to read the HTTP and send the MQTT back to the IOT sensor.
Thanks.

Here you go

[{"id":"1b64a27f.1afc0e","type":"http in","z":"6c960708.24432","name":"","url":"/http_endpoint","method":"post","upload":false,"swaggerDoc":"","x":150,"y":1220,"wires":[["7c5a1535.ec6c94"]]},{"id":"5195af23.64a61","type":"http response","z":"6c960708.24432","name":"","statusCode":"200","headers":{},"x":580,"y":1240,"wires":[]},{"id":"7c5a1535.ec6c94","type":"function","z":"6c960708.24432","name":"HTTP to MQTT","func":"\n///some logic\nvar sp = msg.payload.sp.replace(',','.');\n\nif (parseFloat(sp) > 0 && parseFloat(sp) < 50) {\n\n    msg.payload = parseFloat(sp)*10;\n    msg.topic = \"<mqtt topic>\"\n    \n    return msg;\n\n}","outputs":1,"noerr":0,"x":360,"y":1220,"wires":[["9c0aa8d8.e81ba","5195af23.64a61"]]},{"id":"9c0aa8d8.e81ba","type":"mqtt out","z":"6c960708.24432","name":"","topic":"","qos":"2","retain":"","broker":"","x":570,"y":1160,"wires":[]}]
2 Likes

Hi again,

there are some updates on this topic, so I want to humbly point to MQTT Button plugin here.

With kind regards,
Andreas.