Problem to display state from device

Hi kuema,

Currently I had created a global variable as "global.glo" = 1. And if I want to get this global variable by using a switch node or change node. Do you have any idea on how to do it? I can't find any example for getting global variable with these nodes. :joy_cat:

Thanks & Regards.

Have a look at the docs, specifically the "Using context in a flow" section.

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

The user guide and the Cookbook are always worth reading. Most of the concepts are explained there nicely. :sweat_smile:

This link only show how to set and delete context in a flow. Doesn't teach how to read or get from flow or global. :rofl:

Works the same way. You can use a change node to assign the context value to a message property.

image

Sorry, I don't know whether this way correct to read or not. :cry:

Use "Set" to assign one property value to another (as in the screenshot I provided).

The example posted by @kuema sets msg.payload to current value of the global variable, so effectively it reads the global into msg.payload.
Also, in a Function node you can use global.get() to read a global into a variable.

1 Like

Thank you Colin for the info, I tried to get from a function node and it's work. :heart_eyes:

The link posted earlier links to the writing functions page which explains how to use context in a function node in more detail

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.