Information missing i switch

I have this flow that works fine without the Switch


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.

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.

[{"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}]

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

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

@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

Sorry.
Here is the incomming data from the MQTT

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

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.

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)

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?

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


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.

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

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:

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

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