Hello Again Help with array to dashboard

I wonder if someone would be good enough to help me please
I have a function that receives an array of 8 pieces of numeric data
My function is as follows

for (var i = 0; i < msg.payload.length; i++) {
    var newMsg = {};
    newMsg.payload = msg.payload[i];
    node.send(newMsg);
}

return null;

there are 8 items in the array and on receiving the data i would like to assign each item of the array to 1 of 8 textboxes on a dashboard programmatically.

Thank you in anticipation

Andrew

Well, quickly looking at it:

Could you post the actual payload that is received?

Because if it is not correctly structured it won't work.

(p.s.)

Is it you are receiving ONE message with the whole array, or EIGHT?

I am not sure because of how you worded the question.

You have 2 options

  • add the payload element to each text node, e.g {{msg.payload[0]}} in the value format field, 0 to 7 .
  • split the array with a split node and use the msg.parts.index in a switch node property field to send to each text node, using rule == 0. 0 to 7

p.s node.send(newMsg) or return newMsg should be outside the loop, you are sending the payload 8 time with varying elements, rather than once with 8 elements. Also var neMsg = {} should be before the loop.

[edit] Looking again the function is not even required. just use one of the options i suggested.

Example of option 1 with node-red-dashboard text nodes

[{"id":"d0da769320e30ab5","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[1,2,3,4,5,6,7]","payloadType":"json","x":230,"y":40,"wires":[["77e8dca2af5bfa85","c769043b62334f2e"]]},{"id":"77e8dca2af5bfa85","type":"ui_text","z":"d1395164b4eec73e","group":"8b5cde76.edd58","order":4,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload[0]}}","layout":"row-spread","className":"","style":false,"font":"","fontSize":16,"color":"#000000","x":410,"y":40,"wires":[]},{"id":"c769043b62334f2e","type":"ui_text","z":"d1395164b4eec73e","group":"8b5cde76.edd58","order":5,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload[1]}}","layout":"row-spread","className":"","style":false,"font":"","fontSize":16,"color":"#000000","x":410,"y":80,"wires":[]},{"id":"8b5cde76.edd58","type":"ui_group","name":"default","tab":"8f03e639.85956","order":1,"disp":false,"width":"12","collapse":false},{"id":"8f03e639.85956","type":"ui_tab","name":"Home","icon":"dashboard","order":3,"disabled":false,"hidden":false}]

Example of option 2 with DB2 text nodes

[{"id":"d22816a2341152ef","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[\"one\",\"two\"]","payloadType":"json","x":454,"y":26.00000023841858,"wires":[["9c4556bbc7e2acac"]]},{"id":"9c4556bbc7e2acac","type":"split","z":"d1395164b4eec73e","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":594,"y":26.00000023841858,"wires":[["7d5fb1326bcbdc61"]]},{"id":"7d5fb1326bcbdc61","type":"switch","z":"d1395164b4eec73e","name":"","property":"parts.index","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":714,"y":26.00000023841858,"wires":[["0e42041dcff44bb4","984e85a78eca56dc"],["9802e41f18e33d4e"]]},{"id":"0e42041dcff44bb4","type":"ui-text","z":"d1395164b4eec73e","group":"9d83cd8b3d5ee33c","order":1,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload}}","layout":"row-spread","style":false,"font":"","fontSize":16,"color":"#717171","className":"","x":874,"y":26.00000023841858,"wires":[]},{"id":"9802e41f18e33d4e","type":"ui-text","z":"d1395164b4eec73e","group":"9d83cd8b3d5ee33c","order":2,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload}}","layout":"row-spread","style":false,"font":"","fontSize":16,"color":"#717171","className":"","x":874,"y":66.00000023841858,"wires":[]},{"id":"984e85a78eca56dc","type":"debug","z":"d1395164b4eec73e","name":"debug 2562","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":714,"y":86.00000023841858,"wires":[]},{"id":"9d83cd8b3d5ee33c","type":"ui-group","name":"Group1","page":"c694d0ebe0d2b702","width":"6","height":"1","order":1,"showTitle":true,"className":"","visible":"true","disabled":"false"},{"id":"c694d0ebe0d2b702","type":"ui-page","name":"Page1","ui":"1805777f90e92057","path":"/page1","icon":"home","layout":"grid","theme":"a965ccfef139317a","order":2,"className":"","visible":"true","disabled":"false"},{"id":"1805777f90e92057","type":"ui-base","name":"dashboard","path":"/dashboard","includeClientData":true,"acceptsClientConfig":["ui-notification","ui-control"],"showPathInSidebar":false},{"id":"a965ccfef139317a","type":"ui-theme","name":"HN Theme","colors":{"surface":"#5c5c5c","primary":"#00fdff","bgPage":"#383838","groupBg":"#4f4f4f","groupOutline":"#858585"},"sizes":{"pagePadding":"12px","groupGap":"12px","groupBorderRadius":"4px","widgetGap":"12px"}}]

Option 2 would be more efficient as the array would not be cloned 7 times for each new wire.

Good Morning
Please excuse my weak description, what i am trying to achieve is when my loop function iterates through the msg.payload[i];will get the first number array(0) and I want to assign that to txtbox0 on the dashboard, the second iteration would be array(1) and that value would be written to txtbox1.
It would continue to array(7) and assign that to txtbox7.
I guess the simple question is how do you programmatically assign a numeric value to a specific dashboard text box.

Thank you in advance
andrew

There is no need for the function, you can feed your existing full message directly into all the text boxes. Then tell the text boxes what they should display by using the Value Format field. So in the first text box use {{msg.payload[0]}}
image
In the second use {{msg.payload[1]}} and so on.

Hi Colin
thank you so much for helping me move forward, your suggestion makes perfect sense and I was over complicating it. I am using dashboard 2 and my text box does not have a setting for value.format.
I have attached the properties i have along with how my array look.
Thank you again.

Andrew

I gave the exact same advise as @colin and provided examples. As stated it would use less resources if you split the payload and directed them via a switch node (example 2) as the payload array would not need to be cloned 7 time for each wire.

E1cid yes you did thank you, As i was trying to explain i don't seem to have a format value box in the properties of my dashboard text box.
I am an SQL programmer and nodered is new to me so you will have to excuse my ignorance.
I am grateful for everyone's input and and would thank everyone when i resolve the issue

Kind regards
Andrew

In closing I imported your examples thank you but it threw an error unknown or missing ui-text?

You have not state which dashboard you are using.
From the look of it it is DB2

delete the node that is throwing an error and delete any unused configs in the sidebar config tab.
The add your text node to example 2, it should work for you.

[edit] Just tested this flow and works with DB2

[{"id":"d22816a2341152ef","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[\"one\",\"two\"]","payloadType":"json","x":454,"y":26.00000023841858,"wires":[["9c4556bbc7e2acac"]]},{"id":"9c4556bbc7e2acac","type":"split","z":"d1395164b4eec73e","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":594,"y":26.00000023841858,"wires":[["7d5fb1326bcbdc61"]]},{"id":"7d5fb1326bcbdc61","type":"switch","z":"d1395164b4eec73e","name":"","property":"parts.index","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":714,"y":26.00000023841858,"wires":[["0e42041dcff44bb4","984e85a78eca56dc"],["9802e41f18e33d4e"]]},{"id":"0e42041dcff44bb4","type":"ui-text","z":"d1395164b4eec73e","group":"9d83cd8b3d5ee33c","order":1,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload}}","layout":"row-spread","style":false,"font":"","fontSize":16,"color":"#717171","className":"","x":874,"y":26.00000023841858,"wires":[]},{"id":"9802e41f18e33d4e","type":"ui-text","z":"d1395164b4eec73e","group":"9d83cd8b3d5ee33c","order":2,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload}}","layout":"row-spread","style":false,"font":"","fontSize":16,"color":"#717171","className":"","x":874,"y":66.00000023841858,"wires":[]},{"id":"984e85a78eca56dc","type":"debug","z":"d1395164b4eec73e","name":"debug 2562","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":714,"y":86.00000023841858,"wires":[]},{"id":"9d83cd8b3d5ee33c","type":"ui-group","name":"Group1","page":"c694d0ebe0d2b702","width":"6","height":"1","order":1,"showTitle":true,"className":"","visible":"true","disabled":"false"},{"id":"c694d0ebe0d2b702","type":"ui-page","name":"Page1","ui":"1805777f90e92057","path":"/page1","icon":"home","layout":"grid","theme":"a965ccfef139317a","order":2,"className":"","visible":"true","disabled":"false"},{"id":"1805777f90e92057","type":"ui-base","name":"dashboard","path":"/dashboard","includeClientData":true,"acceptsClientConfig":["ui-notification","ui-control"],"showPathInSidebar":false},{"id":"a965ccfef139317a","type":"ui-theme","name":"HN Theme","colors":{"surface":"#5c5c5c","primary":"#00fdff","bgPage":"#383838","groupBg":"#4f4f4f","groupOutline":"#858585"},"sizes":{"pagePadding":"12px","groupGap":"12px","groupBorderRadius":"4px","widgetGap":"12px"}}]

Is there a bug here @joepavitt or am I doing something wrong.
Never mind @joepavitt I forgot the split node (Doh)

E1cid
Your a super star, its in and working perfectly thank you

Regards
Andrew

Hi Colin
Many thanks for your help in pointing me in the right direction, I am most grateful

Regards
Andrew

Thank you for your help

Regards
Abdrew

1 Like

Glad to hear you got it working.