# Msg.payload return String with numerous symbols

**URL:** <https://discourse.nodered.org/t/msg-payload-return-string-with-numerous-symbols/10486>\
**Category:** General\
**Created:** [24 April 2019 03:55 UTC](https://discourse.nodered.org/t/msg-payload-return-string-with-numerous-symbols/10486 "2019-04-24T03:55:20Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![FreshMeat](https://avatars.discourse-cdn.com/v4/letter/f/c4cdca/32.png) [@FreshMeat](https://discourse.nodered.org/u/FreshMeat)\
**Post date:** [24 April 2019 03:55 UTC](https://discourse.nodered.org/t/msg-payload-return-string-with-numerous-symbols/10486/1 "2019-04-24T03:55:20Z")

</div>

Hi !

I am pretty sure this a stupid question, but I can't get over it !!

I've done a simple node which consist in reading a value from an OPC UA server (Schneider M241 PLC). But the message returned is filled of symbols. Also, when I change the value of the string for a shorter one, the remaining characters of the older value stays in place (ie: OLD=ABC123, NEW=XYZ then msg.payload=XYZ123).

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/d/df8d88a6e0d006eeafb69f2cd6f861bccd811da7.png)

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [24 April 2019 04:52 UTC](https://discourse.nodered.org/t/msg-payload-return-string-with-numerous-symbols/10486/2 "2019-04-24T04:52:26Z")

</div>

Believe me what I assure you the only dumb question is the one you don't ask.

I'm good at asking questions.

Looking at what you posted - and I am not an expert - I think your data is formatted as JSON.

Put a `JSON` node between the OPC UA (the right most blue one) and the debug node.

See if that helps.

Another thing is to actually put TWO debug nodes there.

Why?

Well, by default the debug node shows you ONLY the msg.payload.  
But it can show you EVERYTHING as well.

So?

Well, if I am correct and the data is a JSON format: it is structured differently to _normal_. Be it there is such a thing.

_Usually_ you get something like:  
`msg.payload = "This is the payload"`  
`msg.topic = "This is the topic"`  
`msg.colour = "blue"`  
`msg.time = "12:22:18"`  
`msg.date = "24 April 2019"`  
msg. (and so on)

You can make a lot of stuff in a message.

Just usually it is only the payload which is of importance.

Yeah, so?

Well, sometimes, when you have to send a message over a protocol - say MQTT, which is a well used protocol in NR - you only can send the msg.payload and msg.topic.

I may not be 100% correct, but I am explaining what is going on.

So: those nodes are sending all their data in a JSON packet/encoding.  
This allows all the other stuff to go thorough something like MQTT.

Therefore you put it through a `JSON` node and look at it with a DEBUG node and you will see it all "taken apart" and in a format which is like I explained with the msg.colour etc.

Double click on the `debug` node and select `complete message object`.  
Then when something comes in, you click on the little \> symbol and expand that part of the message and you will see all the sub-components.

I hope that helps.

And again: I am not an expert.

---

<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:** [24 April 2019 07:27 UTC](https://discourse.nodered.org/t/msg-payload-return-string-with-numerous-symbols/10486/3 "2019-04-24T07:27:59Z")

</div>

That sounds as if the string you are sending back does not have any indication of where the end of the string is, so it is getting a buffer full of data where the end portion is whatever was lying about in memory, or in the second case the end of the message you put there the first time.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [24 April 2019 10:02 UTC](https://discourse.nodered.org/t/msg-payload-return-string-with-numerous-symbols/10486/4 "2019-04-24T10:02:31Z")

</div>

I don't know enough about opcua or plc in general... but as Colin says it looks like it's just reading back one "chunk" of data. Not sure if you need to terminate the string when you write it in the first place, or if the plc should do that for you, or if you can set it to read only a certain number of characters, etc. For example strings in C are often terminated by the 0x00 character. You may need to read up on your plc some more to work out what is really needed.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [24 April 2019 10:33 UTC](https://discourse.nodered.org/t/msg-payload-return-string-with-numerous-symbols/10486/5 "2019-04-24T10:33:44Z")

</div>

> [@FreshMeat](#):
>
> Also, when I change the value of the string for a shorter one, the remaining characters of the older value stays in place (ie: OLD=ABC123, NEW=XYZ then msg.payload=XYZ123).

Null (0x0) terminate your string in the PLC.

Typically, this is achieved by either using STRING type functions to write the string in memory or appending a zero value byte after the last character.

---

<div class="post-metadata">

**Author:** ![FreshMeat](https://avatars.discourse-cdn.com/v4/letter/f/c4cdca/32.png) [@FreshMeat](https://discourse.nodered.org/u/FreshMeat)\
**Post date:** [24 April 2019 19:56 UTC](https://discourse.nodered.org/t/msg-payload-return-string-with-numerous-symbols/10486/6 "2019-04-24T19:56:10Z")

</div>

Thanks everyone on helping me ! It helped to resolve my problem.

The reason of my problem:  
In my PLC the STRING have defined length. So, node-red, fill the "empty" parts of the string with all those symbols.

What I did to resolve:  
In the PLC code, I filled the string with a symbol that in my case should never have to be used. Then I remove this symbol with a string node.

I do not know if it the most elegant way to solve it, but it worked!

---

<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:** [24 April 2019 20:02 UTC](https://discourse.nodered.org/t/msg-payload-return-string-with-numerous-symbols/10486/7 "2019-04-24T20:02:13Z")

</div>

Why not use null, as suggested by others?

---

<div class="post-metadata">

**Author:** ![FreshMeat](https://avatars.discourse-cdn.com/v4/letter/f/c4cdca/32.png) [@FreshMeat](https://discourse.nodered.org/u/FreshMeat)\
**Post date:** [24 April 2019 20:57 UTC](https://discourse.nodered.org/t/msg-payload-return-string-with-numerous-symbols/10486/8 "2019-04-24T20:57:47Z")

</div>

I didn't figured out how to use it in the PLC
