Help please with directing string arrays to different dashboard elements

#1

I am getting data from an electricity current meter where the amps values are coming in as msg.payload: string[7] and kwh as msg.payload: string[6]
the data comes in as one stream of data from my arduino alternating between the two

i want the string[7] values to go to a gauge and the string [6] values to a text item on the dashboard

i am ok with the dashboard itself but i need to know how to direct the streams of data as above please

i have looked at the Switch node which is where i thought it would be quite straight forward but i dont see anything there that is logically the answer

please help

#2

Hi @cliffpza

if you know for sure the two different strings are consistently those different lengths, then you can configure a Switch node to check the length of msg.payload using a JSONata expression:

[{"id":"bb4089dc.98ca68","type":"switch","z":"24d928f3.3c58f8","name":"","property":"$length(payload)","propertyType":"jsonata","rules":[{"t":"eq","v":"6","vt":"num"},{"t":"eq","v":"7","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":630,"y":60,"wires":[["4fc09522.6f4eec"],["62b0d077.07658"]]}]
#3

The second one should probably be number 7 not string 7 too. It might work either way.

#4

Oops - but yes, it does work even with that as I had tested it before sharing :slight_smile:

#5

Hi @knolleary Thank you very much for your rapid reply.

Sorry i was not clear enough, the issue is not about the length of text but the fact that the data is in two different array elements called msg.payload : string[6] and msg.payload : string[7]
i want these to go to different dashboard nodes based on which array element it is

i need a nodered function that will recognise which array element it is and direct it accordingly

#6

@Colin - thanks for reply, please see my clarification

#7

Hi @cliffpza - that doesn't actually make it clearer. I'm not sure what msg.payload : string[6] means then if not a 6-character string.

Perhaps you could show some specific examples?

#8

Do you mean that msg.payload is an array and you want elements 6 and 7? If so then send it down two wires to two Change nodes one configured to Set msg.payload To msg.payload[6] and the other to Set msg.payload To msg.payload[7]. Then send the outputs of the two Change nodes to the dashboard nodes.

#9

Hi Colin, thank you very much!

#10

Hi @knolleary i think you are right! the string[ ] seems to refer to the length of the string - apologies
What i am getting is in fact string[*] where * = variances depending on string length
I will have to tag my data so i can separate it differenty

#11

If you have control over the data format you could send it as json strings, then decoding will be simple.

#12

Hi Colin

Thank you. I tagged the data and was able to filter as needed. Your advice is much appreciated

Regards

Cliff

Using Outlook for iPhone 8