How to use oled node

#1

Hi,
Installed node-red-contrib-oled and managed to display a string "hello world" with inject node with json payload of { "size":3, "x":1,"y":1,"text":"hello world"}.
(The format obviously require size and x y coordinates to be set.)

How do I replace just the "hello world" with a variable, so I can display the variable?

Thanks,

#2

Hi @kenkoknz

there are a number of ways you can create such an payload. Here are just some using the core nodes available in the palette. Each uses a slightly different syntax. All of these examples assume the text you want to display is in msg.payload and you want to create the JS Object as you describe to wrap it.

  1. A Template node can be used to provide some template text with parts replaced by values provided by the received message. For example, the following template would insert the value of msg.payload into the template (and by default, the Template node sets msg.payload with the result). You would also need to configure the node to 'output as Parsed JSON'

    { "size":3, "x":1,"y":1,"text":"{{payload}}"}
    
  2. A Change node can be do it by configuring it to set msg.payload to the JSONata expression:

    { "size":3, "x":1,"y":1,"text":payload}
    

  3. A Function node is the all-purpose node where you can write whatever javascript you want:

    msg.payload = { "size":3, "x":1,"y":1,"text":msg.payload};
    return msg;
    
#3

Hi @knolleary
Firstly, really appreciate such quick response, as I live in NZ, I tought it is middle of the night elsewhere in the world and everyone is asleep when I posted.

This is magic! I ve spent the last two days searching the internet, but getting frustrated and more confused. Your advise is invaluable for a beginner like me and the best way to learn is by example (as shown by you). One example worth a thousand words.

I used the change node and hey presto it works.
I think I did try the change node before with the same json object, but I think I used "json" instead of "expression type". Have to admit I do not quite understand jsonata.

Also tried the function node and also works, it makes sense.

Do not quite understand the template node and why {{ }} the payload.

Thanks again.

Ken Kok
NZ

Display temp (18b20) on oled with just pi and nodered