Hi
In my project, I have sensor that can send 2 data. Height and Profile number
height when have object it have value but don't have object it = 0
Profile number it counted values indefinitely when start sensor.
I want to hold profile number first value when height > 0 and last value when height = 0.
There are 3 types of context:
1 - node
2 - flow
3 - global
node is local to that node
flow is local to that flow/tab
global is visible to all nodes in all flows/tabs.
Here is a basic run down on how to use it:
Say you want to store a value coming in as the default msg.payload
let value = msg.payload;
context.set("name",value);
Now: value isn't a number. I am just not good at using/finding the right terms. But it gets what is the msg.payload.
"name" - again: bad word - is what ever you want to call it.
There are some rules how to name them and which case they are.
eg: Namename'MyName and myname
All different. So be careful.
To get that value to use later on:
let something = context.get("name");
Now something is what the msg.payload was.
Hope that helps.
But reading what you say I am not sure this is going to help.
I read it as you get a message which has 2 parts: Height and Profile number
So it may not be as simple as simply getting msg.payload. But that's a whole other story.
I don't know method. Array[0] is Height value and array[1] is Profile number when array[0] > 0 I want hold or keep array[1] as default and when array[0] = 0 again I want hold or keep array[1] is the last value.
Ok, we are going to have to teach you how to paste things rather than screen shots.
As good as they are, when it comes to picking apart data: not very good.
On the right side of the screen there is the debug window where you are seeing the data/outputs.
Each part (line/section) has options.
In the top right corner there is an option to copy the entire message to the clipboard.
You will see this when you move the mouse over it you will see a small icon of a clipboard appear and a little pop up text something about "Copy to clipboard".
Click it then you can paste it here.
But it isn't *THAT simple.
Before you paste it, look at the top of the "window" where you will be typing and there are a few buttons.
One of them looks like this: </>
Click that button then paste the code where the text is.
That will preserve any special stuff which may be needed.
Hi, it is not 100% clear what you mean by "I want to hold profile number first value when height > 0 and last value when height = 0." but here is my best guess...
let parts = msg.payload.split("\t");
if(parts.length >= 2) {
let height = Number(parts[0]);
let profileNo = Number(parts[1]);
if(height == 0) {
flow.set("height_0_profileNo", profileNo);
}
let height_not_0_first_time__profileNo = flow.get("height_not_0_first_time__profileNo");
if(height > 0 && height_not_0_profileNo == null) {
flow.set("height_not_0_first_time__profileNo", profileNo)
}
}
Then you can access flow.height_not_0_first_time__profileNo and flow.height_0_profileNo using a change node or switch node or anywhere access to flow context is accessible.