# Something very weird is happening to my messages enroute

**URL:** https://discourse.nodered.org/t/something-very-weird-is-happening-to-my-messages-enroute/83940
**Category:** General
**Created:** [21 December 2023 22:41 UTC](https://discourse.nodered.org/t/something-very-weird-is-happening-to-my-messages-enroute/83940 "2023-12-21T22:41:07Z")
**Posts on this page:** 12
**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: [21 December 2023 22:41 UTC](https://discourse.nodered.org/t/something-very-weird-is-happening-to-my-messages-enroute/83940/1 "2023-12-21T22:41:07Z")

</div>

# Folks, this is as convoluted as it gets.

NR 3.0.2  
RasPi  
Buster

```auto
pi@TelePi:~ $ node -v
v14.18.1
pi@TelePi:~ $ 

```

Yes, I am a bit of a `subflow` adict. I also have a node `resend last message` installed for the exact reason it says in it's documentation.  
_It is handy to debug_

The story - as briefly as I can:  
Something isn't working and I am trying to find out where it is _failing_.

I got this node (`node-red-contrib-resend-last-msg`) to help me.  
It was kind of working but also not.

I've been chasing my tail and I can not understand why what I am seeing is happening.

I send a message over `MQTT`:

```auto
{"payload":{"payload":"TimePi temperature","device":"TimePi","what":"health","event":"TimePi TEST MESSAGE - over temperature.","colour":"red","state":"1","led":"rgb,7,10,10,0","priority":1},"topic":"EVENT/HEALTH/TimePi","_msgid":"27a9de74ce449fbd"}

```

So all the extra stuff is also received.  
Good/Bad? Dunno, but it works - well, AFAIK, it does.

It is received at the remote end and stuck through a `JSON` node.

This is what I receive and you can also see the problem happening here too, but _weirdly_ further down this branch it is all ok.

 ![Screenshot from 2023-12-22 09-42-10](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/d/5d47eddbd0b8b824a7b0cd3b5907b928ea8da010.png)

I get this:

```auto
{"payload":"TimePi temperature","device":"TimePi","what":"health","event":"TimePi TEST MESSAGE - over temperature.","colour":"red","state":"1","led":"rgb,7,10,10,0","priority":1}

```

Great! All is good in the world.

It goes through other nodes and I get what I want for that branch of the flow.  
I go back a bit and from the _RAW_ message, I send it else where on the same machine and things go awry.

Sorry for the messy tab.  
I was running in ever decreasing circles trying to find out what is/was going on.

(Screen shot)  
See the incoming message.  
ALL is good.  
Ignore my `subflow` as for a while I thought it was causing the problem.  
Also ignore the `resend last message` node. Same.

I put/send the message through a `switch` node and it has _reformatted_ the message.  
See the red lines.

 ![Screenshot from 2023-12-22 09-31-58](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/d/ed5b97d73c685100ad7fdb907c882cea91f5d566.png)

The `msg.payload` has become `msg.payload.payload{}`

WHY? HOW?

If I put back my `subflow` it happens after it rather than after the `switch` node.

(See second screen shot)

 ![Screenshot from 2023-12-22 09-37-51](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/0/7010410e9d891e01681e7274d9076f7d216bbbc2.png)

If I open `B` it is the same as `A` message format.

But you can see in the GREEN `debug` node, it is as I received it in the first screen shot.

I've been putting `debug` nodes every where, can't see why it is happening.

Anyone?

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [21 December 2023 22:51 UTC](https://discourse.nodered.org/t/something-very-weird-is-happening-to-my-messages-enroute/83940/2 "2023-12-21T22:51:04Z")

</div>

One of those debug nodes shows the whole message, the other shows just msg.payload.  
So we can't be certain that they are displaying the same message (by comparing msgid).

Could you be getting two messages arriving at the Machine Health LED link in, when you expect just one?

---

<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: [21 December 2023 22:54 UTC](https://discourse.nodered.org/t/something-very-weird-is-happening-to-my-messages-enroute/83940/3 "2023-12-21T22:54:31Z")

</div>

I appreciate your reply but I've been sitting here for .... a few hours.

Of which `debug` node do you speak?  
At least on which screen shot?

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [21 December 2023 22:55 UTC](https://discourse.nodered.org/t/something-very-weird-is-happening-to-my-messages-enroute/83940/4 "2023-12-21T22:55:48Z")

</div>

I was looking at the one with the green tick and red cross superimposed, the second picture.

Actually, the one with the green tick is only showing msg.payload.  
And it has msg.payload.payload, msg.payload.device etc. So I think that means your problem is not arising at that part of the flow.

---

<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: [21 December 2023 23:03 UTC](https://discourse.nodered.org/t/something-very-weird-is-happening-to-my-messages-enroute/83940/5 "2023-12-21T23:03:51Z")

</div>

![Screenshot from 2023-12-22 09-31-58](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/d/ed5b97d73c685100ad7fdb907c882cea91f5d566.png)

This one?

In green:  
`fan led message` (green) is the complete message received.  
You can see the _flat_ message structure.  
`payload`  
`device`  
`what`  
`event`  
`colour`  
`state`  
and so on.

In the RED message  
the message structure has changed and their paths are then  
`msg.payload` + the original paths.

Sorry, this all started 4 hours ago. I forced myself to get breakfast and then I started looking at this problem.

I found _bugs_ with what I had done - as that part of the code had never really been tested.  
OVERHEAT SHUTDOWN.  
And I didn't get any logs. (Even worse)

But moving on, I was testing the messages sent - and I did have the foresight to include a TEST parameter.  
So I send it and see what happens and where the messages go.

I'll leave out all the other things and though they may be part of this bigger problem, I can't see how/why so I am not including them as I fear it will only further confuse you as they are other things.

So I am seeing the _flat_ (_normal_?) message (green). It goes through a node (basic `switch`) and it comes out with a `payload` prefix on the paths of the message that went into that node.

---

<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: [21 December 2023 23:06 UTC](https://discourse.nodered.org/t/something-very-weird-is-happening-to-my-messages-enroute/83940/6 "2023-12-21T23:06:51Z")

</div>

Yes, sorry.

Ok, so that maybe has helped.

I'll do more digging.

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [21 December 2023 23:07 UTC](https://discourse.nodered.org/t/something-very-weird-is-happening-to-my-messages-enroute/83940/7 "2023-12-21T23:07:44Z")

</div>

> [@Trying\_to\_learn](#):
>
> In green:  
> `fan led message` (green) is the complete message received.

Are you sure? See my blue arrows:

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

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

---

<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: [21 December 2023 23:09 UTC](https://discourse.nodered.org/t/something-very-weird-is-happening-to-my-messages-enroute/83940/8 "2023-12-21T23:09:47Z")

</div>

Sorry, as I posted I only just saw/noticed that.

It may be that I need to know how to convert the message _back_ to what it was when I sent 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: [21 December 2023 23:17 UTC](https://discourse.nodered.org/t/something-very-weird-is-happening-to-my-messages-enroute/83940/9 "2023-12-21T23:17:33Z")

</div>

I **THINK** I've worked it out.

After realising that problem things have taken a whole new (better?) view and I have to sit down and check what I've just seen.

# THANKS!

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [21 December 2023 23:21 UTC](https://discourse.nodered.org/t/something-very-weird-is-happening-to-my-messages-enroute/83940/10 "2023-12-21T23:21:43Z")

</div>

Always good to step away from the screen, focus your eyes on the distance and kick the cat/brew coffee for a while 🙂

(no cats were hurt in the making of that sentence)

---

<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: [21 December 2023 23:24 UTC](https://discourse.nodered.org/t/something-very-weird-is-happening-to-my-messages-enroute/83940/11 "2023-12-21T23:24:13Z")

</div>

Thanks though.

I was a bit _blinded_ by the state of the `debug` nodes and after I opened them all up to show the full message things started to fall into place.

I know I am not helping myself with some of the things I am doing with MQTT messages, but it kinda helps the learning curve.

## SOLUTION:

I was sending a _complex message_ over MQTT. Which is a bad idea with how I was doing it.  
At the other end I wasn't decoding the message correctly which lead to a lot of heart ache.

After being shown the mistake, I fixed it with a `function` node to restore the original _structure_ of the message and all things now seem to 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: [4 January 2024 23:24 UTC](https://discourse.nodered.org/t/something-very-weird-is-happening-to-my-messages-enroute/83940/12 "2024-01-04T23:24:25Z")

</div>

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