# Receive msg from mqtt to html

**URL:** https://discourse.nodered.org/t/receive-msg-from-mqtt-to-html/30797
**Category:** General
**Created:** [27 July 2020 21:23 UTC](https://discourse.nodered.org/t/receive-msg-from-mqtt-to-html/30797 "2020-07-27T21:23:41Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![nati070](https://avatars.discourse-cdn.com/v4/letter/n/48db29/32.png) [@nati070](https://discourse.nodered.org/u/nati070)
#### Post date: [27 July 2020 21:23 UTC](https://discourse.nodered.org/t/receive-msg-from-mqtt-to-html/30797/1 "2020-07-27T21:23:41Z")

</div>

hi , i really glad for help  
i started learn nodered and i have a problem when i try to send a message from the mqtt to the html. the html web not stop loading , the problem is in idPerson node , but i dont know what i do wrong.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/6/c671e1a95225b2f671809ed1f9fc713a36130b67.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/1/418fda2932f88f5b496edbf6b0b5a245ef03383a.png)

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [27 July 2020 22:53 UTC](https://discourse.nodered.org/t/receive-msg-from-mqtt-to-html/30797/2 "2020-07-27T22:53:15Z")

</div>

Put a seperate debug nodes (all set to display the 'Complete msg object') on the outputs of the 'MyPage', 'Openvm/test' and idPersion' nodes so you can see what is coming out of each node.

You can also add some `node.warn('dgb1'+msg.topic)` in your function node (you can use any variable in the function node) so you can see what is happening.

---

<div class="post-metadata">

### Author: ![nati070](https://avatars.discourse-cdn.com/v4/letter/n/48db29/32.png) [@nati070](https://discourse.nodered.org/u/nati070)
#### Post date: [28 July 2020 01:29 UTC](https://discourse.nodered.org/t/receive-msg-from-mqtt-to-html/30797/3 "2020-07-28T01:29:52Z")

</div>

hi , thank you for your answer , i try it but still i cant figure why the page not load,  
i try to add the case of "undefined" but still not working  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/c/9cdb76610d368532321c0a9b2863a8198326e920.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/b/7b605b47ab2cfaeacb3c6459a4229541b17c1417.png)

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [28 July 2020 08:59 UTC](https://discourse.nodered.org/t/receive-msg-from-mqtt-to-html/30797/4 "2020-07-28T08:59:09Z")

</div>

Nati, so the debug is showing that msg.topic 'undefined'.  
1 - Why do you think that is?  
2 - If you look at the debug, do you 'topic' a part of the msg object?  
3 - which node is this debug attached to? (if you put your cursor over the debug data in the sidebar, the `debug` node it is from will be outlined in a red dashed line)

---

<div class="post-metadata">

### Author: ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)
#### Post date: [28 July 2020 09:22 UTC](https://discourse.nodered.org/t/receive-msg-from-mqtt-to-html/30797/5 "2020-07-28T09:22:03Z")

</div>

I’m afraid the flow you’ve imagined won’t work in practice. This debug message is coming from the http-in node feeding into your function, as can be seen by the `req` and `res` properties on the object. The `msg.topic` you’re looking for would come from the mqtt-in node wired to the same function node. While I think I understand what your goal is, can you try to explain what your flow is supposed to do, in general terms rather than flow specific.

As for your function node shown here, rather than `msg.topic` holding the string `"undefined"`, it _is_ undefined. I explained the difference [in another topic](https://discourse.nodered.org/t/how-to-delete-a-flow-variable-from-a-function-node/19731/10). In there, your string`"undefined"` would be _non-zero value_ while the undefined seen here is the last one.

---

<div class="post-metadata">

### Author: ![nati070](https://avatars.discourse-cdn.com/v4/letter/n/48db29/32.png) [@nati070](https://discourse.nodered.org/u/nati070)
#### Post date: [28 July 2020 11:11 UTC](https://discourse.nodered.org/t/receive-msg-from-mqtt-to-html/30797/6 "2020-07-28T11:11:17Z")

</div>

hi thank you for your response ,

1. its happen because the http-in node , this node give undefined and go to the function idPerson .
2. no  
3.the node is mypage(http-in)

---

<div class="post-metadata">

### Author: ![nati070](https://avatars.discourse-cdn.com/v4/letter/n/48db29/32.png) [@nati070](https://discourse.nodered.org/u/nati070)
#### Post date: [28 July 2020 11:26 UTC](https://discourse.nodered.org/t/receive-msg-from-mqtt-to-html/30797/7 "2020-07-28T11:26:33Z")

</div>

hi thank you for your response ,

the flow supposed to do:  
the mqtt give a string (some number) this number go to the sql and return the name that attached to the number that i got from the mqtt , and then the name go to the page ,  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/e/7e19fdf29ee29db5bc787fe3d8196a06c2574d60.jpeg)

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [28 July 2020 11:45 UTC](https://discourse.nodered.org/t/receive-msg-from-mqtt-to-html/30797/8 "2020-07-28T11:45:45Z")

</div>

So now you know why you get the undefined. Becase you have two nodes that can start the flow **independently** of each other and since the http-in node doesn't have a msg.topic, the switch condition in the `function` node will not trigger - in that case. (You should remove the 'undefined' case)

why not use the node-red-dashboard to display the name and get rid of the http-in and http-out nodes?

---

<div class="post-metadata">

### Author: ![nati070](https://avatars.discourse-cdn.com/v4/letter/n/48db29/32.png) [@nati070](https://discourse.nodered.org/u/nati070)
#### Post date: [29 July 2020 10:59 UTC](https://discourse.nodered.org/t/receive-msg-from-mqtt-to-html/30797/9 "2020-07-29T10:59:38Z")

</div>

hi , ok so how can i send a string that dependent on what mqtt output to the web page

and about the dashboard i prefer to do my own web

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [29 July 2020 11:49 UTC](https://discourse.nodered.org/t/receive-msg-from-mqtt-to-html/30797/10 "2020-07-29T11:49:38Z")

</div>

How is the mqtt-in being triggered - i.e. what action causes a mqtt-in msg to arrive?

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [29 July 2020 15:44 UTC](https://discourse.nodered.org/t/receive-msg-from-mqtt-to-html/30797/11 "2020-07-29T15:44:06Z")

</div>

If you want to start from the bare bones then maybe this example - [https://flows.nodered.org/flow/8666510f94ad422e4765](https://flows.nodered.org/flow/8666510f94ad422e4765)

For something more sophisticated but also lets you build from scratch then look at the node-red-contrib-ui-builder project.

---

<div class="post-metadata">

### Author: ![nati070](https://avatars.discourse-cdn.com/v4/letter/n/48db29/32.png) [@nati070](https://discourse.nodered.org/u/nati070)
#### Post date: [29 July 2020 16:25 UTC](https://discourse.nodered.org/t/receive-msg-from-mqtt-to-html/30797/12 "2020-07-29T16:25:31Z")

</div>

thank you!! ,this is what i need , and its work 😄 😄 😄

---

<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: [12 August 2020 16:25 UTC](https://discourse.nodered.org/t/receive-msg-from-mqtt-to-html/30797/13 "2020-08-12T16:25:36Z")

</div>

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