# Information missing i switch

**URL:** <https://discourse.nodered.org/t/information-missing-i-switch/49201>\
**Category:** General\
**Created:** [2 August 2021 09:22 UTC](https://discourse.nodered.org/t/information-missing-i-switch/49201 "2021-08-02T09:22:41Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![funhall](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/funhall/32/36062_2.png) [@funhall](https://discourse.nodered.org/u/funhall)\
**Post date:** [2 August 2021 09:22 UTC](https://discourse.nodered.org/t/information-missing-i-switch/49201/1 "2021-08-02T09:22:42Z")

</div>

I have this flow that works fine without the Switch

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/c/9cf227d7cdb0b3f6d0908ec0e3c058286bd140e9.png)  
If i set in the switch that sort on msg.topic == Cart01, msg.topic == Cart2, etc. like picture below it wont work. All the message have the topic to Cart01.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/2/1212a51912116f648e5192028da2f34cf3d597f8.png)

If you wanna help the code is here. Thanks  
I am not a programmer so i like answer to use in nodes please... If possible affcourse.

```auto
[{"id":"98714863.006c68","type":"ui_text","z":"89f03bbf.93f678","group":"242d1b9c.039d64","order":15,"width":7,"height":1,"name":"1 lap time","label":"<font size=15>Lap time","format":"<font size=15>{{msg.laptime}} ","layout":"row-spread","x":4120,"y":1460,"wires":[]},{"id":"65f8eb04.e95e44","type":"ui_text","z":"89f03bbf.93f678","group":"242d1b9c.039d64","order":4,"width":5,"height":1,"name":"1 Best lap","label":"<font size =6>Best lap","format":"<font size =6>{{msg.bestlap}} ","layout":"row-spread","x":4120,"y":1380,"wires":[]},{"id":"59d60ac6.37c224","type":"change","z":"89f03bbf.93f678","name":"","rules":[{"t":"set","p":"laptime","pt":"msg","to":"laptime","tot":"flow"},{"t":"set","p":"lastlaptime","pt":"flow","to":"laptime","tot":"flow"},{"t":"delete","p":"payload","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":3260,"y":1440,"wires":[["604ca9d2.047f78"]]},{"id":"fb08ea92.63d058","type":"switch","z":"89f03bbf.93f678","name":"","property":"bestlap","propertyType":"flow","rules":[{"t":"gt","v":"laptime","vt":"flow"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":3050,"y":1520,"wires":[["1f874d7b.9471a3"],[]]},{"id":"1f874d7b.9471a3","type":"change","z":"89f03bbf.93f678","name":"","rules":[{"t":"set","p":"bestlap","pt":"msg","to":"laptime","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":3260,"y":1520,"wires":[["9779c6e8.54acc8"]]},{"id":"9779c6e8.54acc8","type":"moment","z":"89f03bbf.93f678","name":"Format bestlap","topic":"","input":"bestlap","inputType":"msg","inTz":"Africa/Abidjan","adjAmount":0,"adjType":"milliseconds","adjDir":"add","format":"mm:ss","locale":"en-US","output":"bestlap","outputType":"msg","outTz":"Europe/Copenhagen","x":3500,"y":1500,"wires":[["65f8eb04.e95e44"]]},{"id":"604ca9d2.047f78","type":"moment","z":"89f03bbf.93f678","name":"Format laptime","topic":"","input":"laptime","inputType":"msg","inTz":"Africa/Abidjan","adjAmount":0,"adjType":"milliseconds","adjDir":"add","format":"mm:ss","locale":"en-US","output":"laptime","outputType":"msg","outTz":"Europe/Copenhagen","x":3500,"y":1440,"wires":[["98714863.006c68"]]},{"id":"1edc99d4.b43e26","type":"moment","z":"89f03bbf.93f678","name":"Format bestlap","topic":"","input":"bestlap","inputType":"msg","inTz":"Africa/Abidjan","adjAmount":0,"adjType":"milliseconds","adjDir":"add","format":"mm:ss","locale":"en-US","output":"bestlap","outputType":"msg","outTz":"Europe/Copenhagen","x":3500,"y":1380,"wires":[["ff49e179.e3306","65f8eb04.e95e44"]]},{"id":"5d646448.8b71ac","type":"change","z":"89f03bbf.93f678","name":"","rules":[{"t":"set","p":"bestlap","pt":"msg","to":"laptime","tot":"flow"},{"t":"set","p":"bestlap","pt":"flow","to":"laptime","tot":"flow"},{"t":"set","p":"lastlap","pt":"flow","to":"laptime","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":3260,"y":1380,"wires":[["1edc99d4.b43e26"]]},{"id":"ff49e179.e3306","type":"change","z":"89f03bbf.93f678","name":"","rules":[{"t":"set","p":"laptime","pt":"msg","to":"bestlap","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":3740,"y":1320,"wires":[["98714863.006c68"]]},{"id":"242d1b9c.039d64","type":"ui_group","name":"GOKART 1","tab":"9ebba496.680ec8","order":2,"disp":true,"width":"30","collapse":true},{"id":"9ebba496.680ec8","type":"ui_tab","name":"Race board","icon":"dashboard","disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

**Author:** ![MyRandomThoughts](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/myrandomthoughts/32/41085_2.png) [@MyRandomThoughts](https://discourse.nodered.org/u/MyRandomThoughts)\
**Post date:** [2 August 2021 09:42 UTC](https://discourse.nodered.org/t/information-missing-i-switch/49201/2 "2021-08-02T09:42:30Z")

</div>

Have you added a debug node to the output of the "Format" nodes to ensure that the topic is actually being returned.

---

<div class="post-metadata">

**Author:** ![funhall](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/funhall/32/36062_2.png) [@funhall](https://discourse.nodered.org/u/funhall)\
**Post date:** [2 August 2021 09:45 UTC](https://discourse.nodered.org/t/information-missing-i-switch/49201/3 "2021-08-02T09:45:19Z")

</div>

Thanks for your quick reply. Yes as you see on the picture it should be okay

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/8/380a4f980f1f73961d27662726686f7a81d6bb27.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:** [2 August 2021 09:46 UTC](https://discourse.nodered.org/t/information-missing-i-switch/49201/4 "2021-08-02T09:46:19Z")

</div>

@funhall

1. There is no `switch` node in the provided flow
2. you don't explain where the data is coming from or show the incoming data

---

<div class="post-metadata">

**Author:** ![funhall](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/funhall/32/36062_2.png) [@funhall](https://discourse.nodered.org/u/funhall)\
**Post date:** [2 August 2021 09:57 UTC](https://discourse.nodered.org/t/information-missing-i-switch/49201/5 "2021-08-02T09:57:47Z")

</div>

Sorry.  
Here is the incomming data from the MQTT

```auto
{"topic":"Cart01","payload":"{\"RGB\":[70.59917,51.63223,48.47107],\"speeder\":353,\"output\":0,\"color\":\"GREEN\",\"maxspeed\":{\"default\":358,\"red\":358,\"blue\":614,\"yellow\":1024,\"current\":614}}","qos":0,"retain":false,"_msgid":"88f5fc0c.89dd2"}

```

Here you have the whole flow. Hope that gives more sende. Looking forward to see your answer...  
Thanks a lot

was to big to use the preformated text input here in the chat so had to use pastebin

> **[Untitled - Pastebin.com](https://pastebin.com/g3kRW8em)**
>
> Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

---

<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:** [2 August 2021 10:00 UTC](https://discourse.nodered.org/t/information-missing-i-switch/49201/6 "2021-08-02T10:00:44Z")

</div>

Add debug nodes showing what is going into and what is coming out of the node that you think is not doing what you want. Give the debug nodes names so they can be identified easily. If it is a switch node then include an 'Otherwise' output and put debug nodes on all outputs. Then send in just the message that you thing is failing. That way you can identify exactly what is going on.

---

<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:** [2 August 2021 10:22 UTC](https://discourse.nodered.org/t/information-missing-i-switch/49201/7 "2021-08-02T10:22:47Z")

</div>

Put 'debug' nodes (set to display the complete msg object) -with names on them - on the output of the 'GREEN count \>1' `switch` node and show us what they provide.

Also, If you change the `mqtt-in` nodes to output ' **a parsed JSON object**' you won't have to do it later in your code.

Question: Why are you using the client ID in the mqtt nodes? Since the topic is identifying the cart, why not have one mqtt-in node and a swirrch after it to look at the topic and route te msg with that.

Observation: Your flow is huge and - to me - unmanageable. If I was you, I would create a tab for each cart and move all of its processing to the seperate tabs. BUT before that, I would see what code is duplicated and merge that code to simplify your flow(s)

---

<div class="post-metadata">

**Author:** ![funhall](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/funhall/32/36062_2.png) [@funhall](https://discourse.nodered.org/u/funhall)\
**Post date:** [2 August 2021 10:41 UTC](https://discourse.nodered.org/t/information-missing-i-switch/49201/8 "2021-08-02T10:41:58Z")

</div>

What do you mean with Client ID i was not aware that I was doing that. ;.(

Yes it is the cleaning of the flows I am about to do now. But I am quiet new to NR and not a programmer. So not familar to all good programing behavior if you know what i mean?

---

<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:** [2 August 2021 11:14 UTC](https://discourse.nodered.org/t/information-missing-i-switch/49201/9 "2021-08-02T11:14:37Z")

</div>

> [@funhall](#):
>
> What do you mean with Client ID i was not aware that I was doing that. ;.(

Unless someone else set up your `mqtt` nodes, you must have entered the client id' in the node....

`Another thing to note`: flow varables are shared with all nodes on the `tab`. So if a mqtt msg comes in and `msg.current Mode` equals 614

 ![Screen Shot 2021-08-02 at 7.01.42 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/1/71d0b16f0b67f2fce90fa60bf0ff0c42f07502b9.png)  
you go and set `flow.currentmode` to **blue**. BUT if the next mqtt msg has a `msg.current Mode` equals 1024, you change `flow.currentmode` to **yellow**

So you have the possibility of thinking you are processing data for blue when it has been changed to yellow.

Since I have no idea of what your project is for and what you are trying to do (i.e. why do you set flow.currentmode to a color?) it's hard - for anyone - to give you suggestions on what to do to improve/simplify your flow.

---

<div class="post-metadata">

**Author:** ![funhall](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/funhall/32/36062_2.png) [@funhall](https://discourse.nodered.org/u/funhall)\
**Post date:** [2 August 2021 11:27 UTC](https://discourse.nodered.org/t/information-missing-i-switch/49201/10 "2021-08-02T11:27:07Z")

</div>

Really good answer i appreciate it. It is for some special gocart where they are detecting colors on the floor. almost like mario cart. So when it is red it drives on 30%, blue 70% and yellow with 100% boos in 5 second.

Okay now i think i know what you mean by the ID. You think it is better to have each car on a separate TAP?  
I will try that...

---

<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:** [2 August 2021 12:04 UTC](https://discourse.nodered.org/t/information-missing-i-switch/49201/11 "2021-08-02T12:04:46Z")

</div>

> [@funhall](#):
>
> You think it is better to have each car on a separate TAP?

I assume you mean TAB and it you can not consolidate much of the code to simplify it, then yes I think it will be easier for you to keep a handle on things.

`NOTE` when you move th ngs to seperate TABs, you need to be aware that `flow` variables will not be working across the TABs.

I would - in a statup flow - create one global object for each cart and store the info each needs. You could do this in a change node:

 ![Screen Shot 2021-08-02 at 8.03.17 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/4/0483451c95d958e6414914138ab3fd5b3baf2924.png)

---

<div class="post-metadata">

**Author:** ![funhall](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/funhall/32/36062_2.png) [@funhall](https://discourse.nodered.org/u/funhall)\
**Post date:** [2 August 2021 12:38 UTC](https://discourse.nodered.org/t/information-missing-i-switch/49201/12 "2021-08-02T12:38:59Z")

</div>

Hi.  
I made a little video to show what I am doing. I hope you can help. I really appreciate it...  
Or give some good advice for a startup...  
Br. Martin

> **[Recording Node-red#1](https://screencast-o-matic.com/watch/crjnlAViS03)**

---

<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:** [1 October 2021 12:39 UTC](https://discourse.nodered.org/t/information-missing-i-switch/49201/13 "2021-10-01T12:39:17Z")

</div>

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