node-red and raspberry sense-hat

73 views
Skip to first unread message

Michael taradus

unread,
Nov 11, 2017, 4:09:42 AM11/11/17
to Node-RED
Hi im trying to make my sense-hat play diffrent text messages. But im failing when i use a function with this code bellow it works


msg.color = "red";
msg
.background = "black";
msg
.speed = "2";
msg
.payload = "text";
return msg;

But i want to be able to use a text input from my dashboard to decide my text message. And i have node ide how to connect them with code.

My first first try to write a code was this

var text = msg.payload.test;
var colour = msg.payload.colour;


msg
.color = colour;
msg
.background = "black";
msg
.speed = "2";
msg
.payload = text;
return msg;

But i get an error message

test : msg.payload : undefinedundefined

Can any one pls help me out?

Julian Knight

unread,
Nov 11, 2017, 4:45:47 AM11/11/17
to Node-RED
Start by adding a debug node to the output of each of the text and colour picker nodes. Then you will be able to see the structure of the messages they are sending out. Try changing the settings of the debug nodes to show the whole message.
Message has been deleted

Michael taradus

unread,
Nov 11, 2017, 6:30:45 AM11/11/17
to Node-RED

I have already don it it just not included in the picture. 
Thats how i  could see the message.That i wrote in my first post.
test : msg.payload : undefinedundefined

Nick O'Leary

unread,
Nov 11, 2017, 6:51:38 AM11/11/17
to Node-RED Mailing List
Michael, in your flow you have two nodes feeding into one. That means the Function node will be triggered by either the text node or the colour node - but not both at the same time.

Both of those nodes also emit their value as msg.payload, but your Function is trying to access msg.payload.colour and msg.payload.test (also note you have 'test' not 'text'...) - so their values will always be undefined.

You need to use a different approach to do this.

This is where you can use Flow Context to store values between each message event:

 - when a message comes from the colour node, store its payload value in flow.colour
 - when a message comes from the text node, store its payload value in flow.text
 - in both cases then construct a complete message for the sensehat, pulling the latest values from flow context for both color and text. Something like:






The 4 rule change node looks like this:











test : msg.payload : undefinedundefined

--
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/ba314afe-48ba-4762-a399-a5cf25c4ac3c%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Michael taradus

unread,
Nov 11, 2017, 10:26:17 AM11/11/17
to Node-RED
I still cant make it work. Sure the text rolles up on the led matrix but the other values are not changed like the color is not changed and

here is what i have done

The debug i get this in debug output

 msg.payload : string[2]"hi"

Nick O'Leary

unread,
Nov 11, 2017, 10:40:52 AM11/11/17
to Node-RED Mailing List
Your flow screenshot claims the change node only has two rules set... but your screenshot has 4 rules.

Of those four rules, the first is setting msg.text to the value of flow.payload - you have that the wrong way around. it should be set msg.payload to the value of flow.text

If you modify the Debug node to show complete message and not just msg.payload then you can see all the properties you are passing the sensehat node.

Nick

--
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.
Reply all
Reply to author
Forward
0 new messages