Extracting data from msg.payload

Hi Everyone,

I have an Arduino connected serially to my Raspberry Pi where I have node-red running. Arduino is sensing temperature data from the sensor and is send to Raspberry Pi.

Everything is working perfect but I have one question, in the debug I am having data in String format with "length=7" but in debug window, the msg.payload shows the String of "length=9" shown in figure below.
Why there is an extra character in msg.payload?
2019-05-09-111057_1824x984_scrot

With the information you have given it is impossible to say, it is not even clear which debug node on the flow is showing that data. If you can select just the nodes needed to show the problem and Export those and paste them here, and explain in more detail what you are seeing, that may help. Read this for help with how to paste a flow here

Better if you can show us how you build the strings, as Colin mentioned above. My guess is that your logic is somehow encoding an escaped null characther (just a guess). This is typical of C (the language) strings.

msg.payload = "\0"+"\n"
return msg;

willl produce:

s-01

1 Like

I am sorry I was not able to clear my point. I have temperature data coming serially from Arduino and I am just observing the output as msg.payload. The temperature data is in String format and I want to find the length of that string.

The problem is when I get this string data, in the debug window(please see the figure below) you can see in red box e.g the temperature data is "24.69,2", which should have the length of 7 but in actual it is 9. There is one "arrow" character in the green box(it has two characters), I want get rid of these additional characters.

Thank you
Zain

Hello Andrei,

Yes, exactly! Can I get rid of this null character? I am 100% sure that the data coming from Arduino has no additional line or null character like "\0" or "\n".

Thank you

Sure you can. Use Javascript trim function: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim

but I have not tested...

1 Like

But if you are 100% sure it’s not coming from arduino, can’t you work back along your flow to find out where it is coming from?

Yes, It worked!! :smiley:

Thank you.

Kind Regards,
Zain

1 Like

Hi ukmoose,

I wrote "I am 100% sure that the data coming from Arduino has no additional line or null character" like "\0" or "\n".

The problem is solved now.

Thank you,

Regards
Zain