"Function tried to send a message of type string"

6,015 views
Skip to first unread message

Ahmed Garssallaoui

unread,
Apr 25, 2018, 9:17:30 AM4/25/18
to Node-RED
hi guys, 

I am trying to extract the 'body' part of my received mqtt message as a JSON format, the body is in base64.

First I tried to retrieve only the body part so I wrote this function:


return msg.payload.body;


but I got this error:
"Function tried to send a message of type string"

any one can help me to solve this ?? 
1.PNG
2.PNG

Colin Law

unread,
Apr 25, 2018, 10:48:46 AM4/25/18
to node...@googlegroups.com
You must always return a message, you are returning a string. If you want the body in msg.payload then you can do
msg.payload = msg.payload.body;
return msg;

Though if that is all you are trying to do then you can use a Change node set to Move msg.payload.body Into msg.payload

Colin

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/49ad4d71-d0cd-437c-8990-d75e16a454d5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mark Setrem

unread,
Apr 25, 2018, 11:11:15 AM4/25/18
to Node-RED
The docs have a good page on working with messages, it is well worth a read.

https://nodered.org/docs/user-guide/messages

Nick O'Leary

unread,
Apr 25, 2018, 11:12:16 AM4/25/18
to Node-RED Mailing List
Note I've also responded to the same question on StackOverflow.

On 25 April 2018 at 16:11, Mark Setrem <mse...@gmail.com> wrote:
The docs have a good page on working with messages, it is well worth a read.

https://nodered.org/docs/user-guide/messages
--
http://nodered.org

Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send an email to node...@googlegroups.com.

Mark Setrem

unread,
Apr 25, 2018, 12:30:09 PM4/25/18
to Node-RED
Why do people do that? It's very annoying.

Ahmed Garssallaoui

unread,
Apr 26, 2018, 3:36:29 AM4/26/18
to Node-RED
Thank you very much for your help.


On Wednesday, April 25, 2018 at 4:12:16 PM UTC+1, Nick O'Leary wrote:
Note I've also responded to the same question on StackOverflow.
On 25 April 2018 at 16:11, Mark Setrem <mse...@gmail.com> wrote:
The docs have a good page on working with messages, it is well worth a read.

https://nodered.org/docs/user-guide/messages

--
http://nodered.org

Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.

Ahmed Garssallaoui

unread,
Apr 26, 2018, 3:36:58 AM4/26/18
to Node-RED
Thank you very much, that solved my problem


On Wednesday, April 25, 2018 at 3:48:46 PM UTC+1, Colin Law wrote:
You must always return a message, you are returning a string. If you want the body in msg.payload then you can do
msg.payload = msg.payload.body;
return msg;

Though if that is all you are trying to do then you can use a Change node set to Move msg.payload.body Into msg.payload

Colin
On 25 April 2018 at 14:17, Ahmed Garssallaoui <garssalla...@gmail.com> wrote:
hi guys, 

I am trying to extract the 'body' part of my received mqtt message as a JSON format, the body is in base64.

First I tried to retrieve only the body part so I wrote this function:


return msg.payload.body;


but I got this error:
"Function tried to send a message of type string"

any one can help me to solve this ?? 

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.

Ahmed Garssallaoui

unread,
Apr 26, 2018, 3:39:08 AM4/26/18
to Node-RED
Dear Mark, 
When I asked this question, there weren't any answer to that question by that time.
It was answered on stackoverflow after the question was posted here.

Regards

Ahmed Garssallaoui

unread,
Apr 26, 2018, 3:46:12 AM4/26/18
to Node-RED
Thank you
Reply all
Reply to author
Forward
0 new messages