More updates to my previous MQTT question

In follow up to: this

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

This is some of the code (screen shot)

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.

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

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

There you see it is looking at/for the LWT

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

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

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

Now you see that msg.enabled is set to false

Screenshot from 2020-05-13 10-26-41

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.

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.

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

Not really showing me much of use.

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.

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.

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.

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)

        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:

[{"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.

{"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.

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?

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?

Sorry Colin.

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

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

{"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.

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)

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