# How to send mqtt to html response

**URL:** https://discourse.nodered.org/t/how-to-send-mqtt-to-html-response/22651
**Category:** Dashboard
**Created:** [5 March 2020 08:20 UTC](https://discourse.nodered.org/t/how-to-send-mqtt-to-html-response/22651 "2020-03-05T08:20:36Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Researcher](https://avatars.discourse-cdn.com/v4/letter/r/edb3f5/32.png) [@Researcher](https://discourse.nodered.org/u/Researcher)
#### Post date: [5 March 2020 08:20 UTC](https://discourse.nodered.org/t/how-to-send-mqtt-to-html-response/22651/1 "2020-03-05T08:20:37Z")

</div>

Hello  
Listening for mqtt on node-red dashboards.  
I want to send mqtt data directly to the specified http address.  
Is there a way to send without request?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/0/60701dde669888e11f089a47fa666c56271c8c07.png)

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [5 March 2020 08:24 UTC](https://discourse.nodered.org/t/how-to-send-mqtt-to-html-response/22651/2 "2020-03-05T08:24:33Z")

</div>

> [@Researcher](#):
>
> I want to send mqtt data directly to the specified http address.  
> Is there a way to send without request?

What do you mean "without request"? If you want to send data to an HTTP endpoint, you have to send a request to that endpoint using the HTTP Request node.

Alternatively, this recipe shows how you can include data data capture in one flow in the response to an incoming HTTP request - [Include data captured in another flow : Node-RED](https://cookbook.nodered.org/http/include-data-from-another-flow)

---

<div class="post-metadata">

### Author: ![Researcher](https://avatars.discourse-cdn.com/v4/letter/r/edb3f5/32.png) [@Researcher](https://discourse.nodered.org/u/Researcher)
#### Post date: [5 March 2020 08:30 UTC](https://discourse.nodered.org/t/how-to-send-mqtt-to-html-response/22651/3 "2020-03-05T08:30:24Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/1/f1a0085562534326aa6f888b8646203c86173a30.png)

So far, I have requested from the html page to the node-red server and received and processed the response.  
I want to send data directly from node-red to html address without any request from html.  
For example

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/0/40260096fb360381e68abbfc0910ae83a96fec95.png)

I would like to do this

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [5 March 2020 08:31 UTC](https://discourse.nodered.org/t/how-to-send-mqtt-to-html-response/22651/4 "2020-03-05T08:31:28Z")

</div>

> [@Researcher](#):
>
> I want to send data directly from node-red to html address without any request from html.  
> For example

Use the `HTTP Request` node

[https://cookbook.nodered.org/#http-requests](https://cookbook.nodered.org/#http-requests)

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [5 March 2020 09:12 UTC](https://discourse.nodered.org/t/how-to-send-mqtt-to-html-response/22651/5 "2020-03-05T09:12:13Z")

</div>

If you sending data that will probably need POST mode in the http request. That will depend on what the remote server requires of course.

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [5 March 2020 17:30 UTC](https://discourse.nodered.org/t/how-to-send-mqtt-to-html-response/22651/6 "2020-03-05T17:30:12Z")

</div>

There are several ways to do this.

As Nick has said, the http-in/out nodes come as a pair and you have to have a user connect to the url which sends typically a GET command to the http-in node. Web pages are user driven not server driven.

So to do what you want. You either have to have the latest MQTT data already in Node-RED so that you can send it as part of the response (http-out) (1). Or you have to create some kind of persistent connection between the users browser tab and the Node-RED server (2).

1. You could combine your two flow examples so that both the http-in and mqtt-in nodes both go into the same function node. In that function node, you would have a test on the msg.topic and if it matches the MQTT subscription, you simply grab the data and save it to a context variable. Otherwise, you grab the latest context variable data previously saved and feed that into the response.

2. In order to give the server a chance to send a _later_ response - for example, after the initial page load completes, you can use websockets. This is how the Dashboard works. uibuilder will also do it. You could also create your own websocket using the websocket nodes.

Here is an example using uibuilder:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/6/066f54ca3456d2d31eff6f4015a0a3a78829659c.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/c/7cdc35e731f55e8279107d66d6627676c52e0700.png)

The full code for that is in the Node-RED flows site.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [4 April 2020 17:30 UTC](https://discourse.nodered.org/t/how-to-send-mqtt-to-html-response/22651/7 "2020-04-04T17:30:13Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
