# More updates to my previous MQTT question

**URL:** <https://discourse.nodered.org/t/more-updates-to-my-previous-mqtt-question/26562>\
**Category:** General\
**Created:** [13 May 2020 00:48 UTC](https://discourse.nodered.org/t/more-updates-to-my-previous-mqtt-question/26562 "2020-05-13T00:48:21Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [13 May 2020 00:48 UTC](https://discourse.nodered.org/t/more-updates-to-my-previous-mqtt-question/26562/1 "2020-05-13T00:48:22Z")

</div>

In follow up to: [this](https://discourse.nodered.org/t/mqtt-message-not-seeming-to-work/25705)

It is still not consistent in what is happening. Or that's what I am seeing it as.

This is a lot of screen shots. That may better. It may be worse.

## The scenario:

I turn on **this** machine. The `MQTT broker` (host) is on another machine.

This is what I see on my dashboard from a powered off condition. So: machine is off. I turn it on. Load browser and this is what I see.

![Screenshot from 2020-05-13 10-23-46](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/a/5ad2d4f2ae03f67c7ed920f65188fd61fae0eea7.png)

This is some of the code (screen shot)

 ![Screenshot from 2020-05-13 10-24-32](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/c/8cb0283528a128a2f0e44491bdb0052f638be198.png)

Note `red` marks.  
I get that it is saying the bulb is `on` and the message is **not** `retained`.  
Yeah, I'll cop that. But it isn't that easy/simple.

That is that part of the code. A bit more looking at what is happening.

 ![Screenshot from 2020-05-13 10-24-40](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/a/6aac0915b32a1a3b480b5d5578b9cd6842134bc7.png)

That is the `MQTT` node. Note: I specify the _topic_/path.

 ![Screenshot from 2020-05-13 10-25-13](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/4/b486b39b3c51e7c39bcd15eac3f9b8c78bc83ea6.png)

This is the other `MQTT` node which looks at/for the LWT message.  
Note here it is `Offline` and the message **is** `retained`.

 ![Screenshot from 2020-05-13 10-25-24](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/b/ab34f9777983a828cf465464b6ba183eb5f271f7.png)

There you see it is looking at/for the `LWT`

 ![Screenshot from 2020-05-13 10-25-49](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/d/7df2bbe9e8b52f7d8aff123dad618d129762e184.png)

Here it is `switched` if the payload is `Offline` to output 2.

 ![Screenshot from 2020-05-13 10-26-05](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/e/fe3a4fbc2e43286b68486652c0b0fde981199c65.png)

You can see the `LWT` (switch) node going to the `function` node (BAN)

 ![Screenshot from 2020-05-13 10-26-25](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/5/b5ca89222acc939c0f4c9cb89baf9de66a259101.png)

Here you see the `msg.icon` is set to the font-awesome `ban` icon.

 ![Screenshot from 2020-05-13 10-26-36](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/8/b8a80684f1e2c4022aa2b5ec6dda91d2a20baecb.png)

Now you see that `msg.enabled` is set to `false`

![Screenshot from 2020-05-13 10-26-41](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/8/f87caaf439d7112bb52bbec84b496044162b0323.png)

And (finally) you see that message is sent into the `button` node.

So: Ok, the other message is/was sent in error. Ok. But the message was also sent that the button is `disabled` and the `msg.icon` is set to the `ban` icon.

Even if the timing is wrong, the button should be disabled. It isn't

I can post the flow (or part there of) but there are a couple of foreign nodes.

But I need to set the _topic_ (path) in the second `MQTT in` node or the message just doesn't seem to be received/actioned.

---

<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:** [13 May 2020 06:03 UTC](https://discourse.nodered.org/t/more-updates-to-my-previous-mqtt-question/26562/2 "2020-05-13T06:03:07Z")

</div>

As always there is no need need to post a full dissertation as to what your flow consists of. Just concentrate on what is going wrong. You say that the button should be disabled, but isn't, so put debug nodes showing the messages that affect the button and look at those. Once you understand what is causing the button to be in the wrong state then work back up the flow to find why.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [13 May 2020 07:41 UTC](https://discourse.nodered.org/t/more-updates-to-my-previous-mqtt-question/26562/3 "2020-05-13T07:41:46Z")

</div>

Well, I am trying that - which is why there is the `queue` node and `debug` node.

Not really showing me much of use.

---

<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:** [13 May 2020 08:08 UTC](https://discourse.nodered.org/t/more-updates-to-my-previous-mqtt-question/26562/4 "2020-05-13T08:08:38Z")

</div>

Can't you put a debug node showing what is going into the bulb and see what is being sent? Since you have two inputs then it might be confusing if messages are coming close together, but apart from that situation you just have to look at the last message and see what is going into the bulb. If it is too confusing then feed both inputs through a function node that just passes them on, then you can send that output to both the bulb and a debug node so you can always see the last message sent to the bulb.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [13 May 2020 08:34 UTC](https://discourse.nodered.org/t/more-updates-to-my-previous-mqtt-question/26562/5 "2020-05-13T08:34:28Z")

</div>

> [@Colin](#):
>
> Can't you put a debug node showing what is going into the bulb and see what is being sent?

I'm taking it you mean the button for the bulb - yes?

Did that on this time boot up. So next time I boot, I shall get a look at what is being sent into it.

---

<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:** [13 May 2020 09:04 UTC](https://discourse.nodered.org/t/more-updates-to-my-previous-mqtt-question/26562/6 "2020-05-13T09:04:09Z")

</div>

> [@Trying\_to\_learn](#):
>
> I'm taking it you mean the button for the bulb - yes?

Assuming that is the one that is misbehaving then yes.  
That should always be your first line of attack. A node isn't doing what you expect so look at what is going into it.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [13 May 2020 09:12 UTC](https://discourse.nodered.org/t/more-updates-to-my-previous-mqtt-question/26562/7 "2020-05-13T09:12:40Z")

</div>

Thanks Colin....

Alas my stupidity is only making things worse.

As is with the flow as is, I can press the `enable` (inject) node and it is enabled.  
Press the `disable` (inject) node and it is correctly disabled.

Ok...... So just to save the mess that is happening around the node, I copied it and am working on a copy.

To get it working, I need to get it enabled and showing the `bulb` icon.  
That is killing me.

To get it showing the `bulb` a `function` node gives it this message:  
(part)

```auto
        msg= {icon: '<font color = "red"><i class="fa fa-lightbulb-o fa-3x"></i></font>'};

```

So, I want to stick that in a `change` node. Ok, I could use a `function` node. But in the spirit of wanting to learn better ways, I am using an `inject` node and setting it as the `{ }` option.

So, I make this bit of code:

```auto
[{"id":"5b4418e5.5562c8","type":"inject","z":"26262ba1.62dcbc","name":"Disable","topic":"","payload":"{\"icon\":\"<font color = \\\"red\\\"><i class=\\\"fa fa-ban fa-3x\\\"></i></font>\",\"enabled\":false}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":3040,"y":2400,"wires":[["60aa0814.a605e","6bea8ffe.219b5"]]},{"id":"60aa0814.a605e","type":"ui_button","z":"26262ba1.62dcbc","name":"BULB#1","group":"7893c6c4.30ede","order":2,"width":"1","height":"2","passthru":false,"label":"{{msg.icon}}","tooltip":"","color":"","bgcolor":"{{msg.background}}","icon":"","payload":"X","payloadType":"str","topic":"","x":3230,"y":2400,"wires":[[]]},{"id":"6bea8ffe.219b5","type":"debug","z":"26262ba1.62dcbc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":3220,"y":2350,"wires":[]},{"id":"8e34543.523caa8","type":"inject","z":"26262ba1.62dcbc","name":"Enable","topic":"","payload":"{icon: <font color = \"red\"><i class=\"fa fa-lightbulb-o fa-3x\"></i></font>}","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":3040,"y":2350,"wires":[["60aa0814.a605e","6bea8ffe.219b5"]]},{"id":"7893c6c4.30ede","type":"ui_group","z":"","name":"BULB-1","tab":"aa487daa.33c1c","order":4,"disp":true,"width":"3","collapse":false},{"id":"aa487daa.33c1c","type":"ui_tab","z":"","name":"Real_World_Control","icon":"dashboard","order":3,"disabled":false,"hidden":false}]

```

### Note:

The `enable` inject node is not set correctly. I know. Because if I change it to be `{ }` rather than `string` it gives an error.

I am somehow not helping myself and just can't seem to get it working at this level.

### Back to the main flow:

This message is seen going into the `button` node which is incorrectly showing the bulb as `online`.

```auto
{"icon":"<font color = \"red\"><i class=\"fa fa-ban fa-3x\"></i></font>","_msgid":"75765122.a4db3","enabled":false,"ttl":0,"_queuetimestamp":1589359955009,"_queueCount":0}

```

I've tried putting the `"` around the `icon` part. No change. The `inject` node just refuses to accept being set to inject a message to set it as _enabled_ and _online_.

# Silly me

I can't use a simple `inject` node as I thought.

Work in progress.

But this is a _test_ bit, and I can see the message going into the `button` on/in the main flow.  
So I am not really sure this is helping.

---

<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:** [13 May 2020 09:22 UTC](https://discourse.nodered.org/t/more-updates-to-my-previous-mqtt-question/26562/8 "2020-05-13T09:22:57Z")

</div>

> [@Trying\_to\_learn](#):
>
> This message is seen going into the `button` node

In what way is that 'seen'. That doesn't look like the output from a debug node. What does it look like in a debug node?

---

<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:** [13 May 2020 09:25 UTC](https://discourse.nodered.org/t/more-updates-to-my-previous-mqtt-question/26562/9 "2020-05-13T09:25:41Z")

</div>

> [@Trying\_to\_learn](#):
>
> I can see the message going into the `button` on/in the main flow.  
> So I am not really sure this is helping

You have lost me again. What message? If you are sending a message to the button and it is not doing what it should then why is that not helping?

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [13 May 2020 09:35 UTC](https://discourse.nodered.org/t/more-updates-to-my-previous-mqtt-question/26562/10 "2020-05-13T09:35:07Z")

</div>

Sorry Colin.

Believe me I am not wanting to be confusing. Really.

Ok, this is what is being sent into the `button` node.

```auto
{"icon":"<font color = \"red\"><i class=\"fa fa-ban fa-3x\"></i></font>","_msgid":"efcee59d.66dfa8","enabled":false,"ttl":0,"_queuetimestamp":1589362005145,"_queueCount":0}

```

This is seen after a `node-red-restart` command. (Worked out that is as good as a restart of the PC for what I need)

So I restart NR and that is being sent into the `button` node.

YET, this is what I am seeing on the dashboard.

I have deleted a _wire_ but I don't think there is a message as the _queue_ is empty.

The light blue is messages from the _enabled_ node. Follow blue line to other end.  
Queue is empty.  
Orange line is the output from the _disabled_ node. See how it is connected to the `button`.  
Also the queue. (Ok, it is empty because I displayed the message.)  
See red circle. **enabled: false**

When you look at the second picture the `button` is showing the button is online and on.

 ![Screenshot from 2020-05-13 19-27-42](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/2/e237bfcee73082dd3e0c983359519a7d8acce064.png)

 ![Screenshot from 2020-05-13 19-29-21](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/4/a461937e438b8490661b60da30c7144945cbdfed.png)

Oh, the second picture.

The _double green_ is showing what the icon should be when _disabled_

I think I found the problem.

A _hidden_ delay node I had forgotten about.

ARGH!

Nearly had it. Slipped through my fingers.  
Sorry folks. (Colin, I don't think I know what is happening)

---

<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:** [27 May 2020 09:49 UTC](https://discourse.nodered.org/t/more-updates-to-my-previous-mqtt-question/26562/12 "2020-05-27T09:49:37Z")

</div>

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