1
00:00:00,660 --> 00:00:06,870
High in the previous lecture, he learned about messages, which is the primary method by which a note

2
00:00:06,870 --> 00:00:08,930
will pass data to another note.

3
00:00:09,570 --> 00:00:12,000
There's another way to do that as well.

4
00:00:12,010 --> 00:00:15,830
And that is done by our variables with variables.

5
00:00:15,840 --> 00:00:24,730
It's possible to pass data between notes in the same flow, but also notes across different flows.

6
00:00:25,110 --> 00:00:32,910
So I'm going to give you a few examples, a few demonstrations that use messages that use variables

7
00:00:33,150 --> 00:00:33,970
to do that.

8
00:00:34,470 --> 00:00:40,470
I want to point out that there is a very good page, a the competition page in the note read website,

9
00:00:40,680 --> 00:00:41,700
which is this one here.

10
00:00:41,700 --> 00:00:44,430
And I encourage you, of course, to have a look at this.

11
00:00:44,760 --> 00:00:47,640
It will give you a lot of details in this lecture.

12
00:00:47,650 --> 00:00:49,870
I'm going to focus on examples.

13
00:00:50,460 --> 00:00:57,780
So a central concept in note read is the context, which has got the same meaning as a context in programming

14
00:00:57,780 --> 00:00:58,950
and programming language.

15
00:00:59,340 --> 00:01:08,270
So when it comes to variables in note read, the context can be the node or a flow or global.

16
00:01:08,730 --> 00:01:15,240
So node, of course, means that you can create fireballs that are only accessible inside the node in

17
00:01:15,240 --> 00:01:15,810
particular.

18
00:01:15,820 --> 00:01:25,500
That is true for function nodes where you write small javascript flow means the context within a flow.

19
00:01:25,620 --> 00:01:27,090
OK, within a tab.

20
00:01:27,090 --> 00:01:35,880
All of the nodes inside ATAP, which is a flow, can access variables that have been created within

21
00:01:35,880 --> 00:01:36,570
this flow.

22
00:01:36,900 --> 00:01:43,740
And then for the global variables, we are talking about variables that can be accessed and can be shared

23
00:01:44,010 --> 00:01:53,480
across multiple flows to demonstrate the different kinds of variables, especially flow and global variables.

24
00:01:53,490 --> 00:02:00,020
I'm going to use my DHT 22 example flow as the starting point.

25
00:02:00,390 --> 00:02:04,960
So this is the flow that you are already familiar with from the previous lecture.

26
00:02:05,430 --> 00:02:13,770
What I'll do is I'm going to disable those debug messages and I've just actually added another debug

27
00:02:13,770 --> 00:02:22,350
node here so that I can print out the temperature and humidity to the back window.

28
00:02:22,410 --> 00:02:27,890
So if I trigger it, actually should deploy first or trigger this flow.

29
00:02:27,900 --> 00:02:29,040
And this is what you get.

30
00:02:29,520 --> 00:02:37,350
The idea here is that instead of printing out the temperature and humidity, connecting the debug nodes

31
00:02:37,350 --> 00:02:46,110
directly to the DHT 22 node, what I'll do is I'm going to store these two values in flow and in global

32
00:02:46,110 --> 00:02:54,780
variables and then access them by triggering a different part of the flow or by getting them in a totally

33
00:02:54,780 --> 00:02:57,950
different flow and presenting them into the deep window.

34
00:02:58,270 --> 00:03:03,270
Again, I'm going to start with local flow variables.

35
00:03:04,140 --> 00:03:10,200
There's a couple of different ways to work with variables, whether they are global or flow, and that

36
00:03:10,200 --> 00:03:18,960
is by creating them and accessing them programmatically inside a function node or by using one of the

37
00:03:19,170 --> 00:03:23,340
compatible nodes to first I'm going to work with a compatible node.

38
00:03:23,340 --> 00:03:27,480
And then I'm also going to show you the second way of doing that through functions, which is obviously

39
00:03:27,480 --> 00:03:28,540
a lot more flexible.

40
00:03:29,010 --> 00:03:33,520
So before we can read a flow variable, we need to create it.

41
00:03:33,690 --> 00:03:41,320
And to do that will use the change node and grab a node and place it up here and then connect Mattituck

42
00:03:41,350 --> 00:03:46,350
22 node to the change node inside the change node.

43
00:03:47,190 --> 00:03:51,900
I'm going to create two rooms I'm going to set.

44
00:03:53,020 --> 00:03:54,010
A flu.

45
00:03:55,300 --> 00:03:56,650
A variable called.

46
00:03:58,520 --> 00:03:59,420
Temperature.

47
00:04:01,720 --> 00:04:11,050
To whatever message DOD payload contains, as you know, payload is the variable that contains the temperature,

48
00:04:11,590 --> 00:04:13,560
and then I'm going to do the same thing for humidity.

49
00:04:13,570 --> 00:04:15,550
I'm going to set the humidity flow.

50
00:04:19,230 --> 00:04:21,750
To message dot.

51
00:04:23,420 --> 00:04:24,200
Humidity.

52
00:04:27,270 --> 00:04:33,630
And that's it, I might put another debug message here so that.

53
00:04:35,470 --> 00:04:40,840
Let's see, I'm going to add another message and set the payload that will come out of the change node

54
00:04:40,990 --> 00:04:44,590
to say something like variables set.

55
00:04:45,920 --> 00:04:55,450
All right, so then that output will go into the debug node here and I'm going to give it a name, Farabaugh

56
00:04:57,380 --> 00:05:00,380
Verbose set confirmation.

57
00:05:01,160 --> 00:05:01,700
All right.

58
00:05:03,660 --> 00:05:12,000
So what I've got now is that the G20 to take a measurement, it will pass the data onto the change through

59
00:05:12,270 --> 00:05:16,740
the change, is going to set the Flotard temperature and Flotard humidity variables.

60
00:05:17,280 --> 00:05:26,340
And then it's also going to set the message payload vulnerable to this string so that in the next note,

61
00:05:26,340 --> 00:05:34,600
the debug note, I'm just going to print out that message that the variables have been set and confirmation.

62
00:05:35,290 --> 00:05:37,040
Now, let's see how that works so far.

63
00:05:37,680 --> 00:05:44,940
I'm going to deploy and then trigger this flu and you can see that virus said.

64
00:05:45,270 --> 00:05:46,680
So we want to be able to read them.

65
00:05:46,680 --> 00:05:47,050
Right.

66
00:05:47,430 --> 00:05:52,120
So let's go ahead and do the reading of those flu variables to do that.

67
00:05:52,140 --> 00:06:05,310
I'm going to use an inject note and in that inject note, I am going to read a flu virus first the temperature.

68
00:06:08,380 --> 00:06:12,580
I'll give it a name, read SLU.

69
00:06:13,760 --> 00:06:22,280
Temperature, I read, read low temperature variable underneath the second topic.

70
00:06:23,260 --> 00:06:36,950
Done and then printed out to the back window, I just say show temperature, actually low temperature

71
00:06:36,950 --> 00:06:37,330
Vudu.

72
00:06:41,230 --> 00:06:47,050
Like that, and I'll do the same thing for humidity, so I just copy and paste.

73
00:06:48,610 --> 00:06:59,830
The original note and change this to humidity, and now I want to get the humidity flow variable, variable.

74
00:07:01,880 --> 00:07:02,420
Like that.

75
00:07:04,240 --> 00:07:15,940
I can actually connect this node to the same debug node if I want, and I can just say show flow values.

76
00:07:19,010 --> 00:07:28,640
Like this sense for both of these inject notes, the message is printed or is stored inside the message

77
00:07:28,640 --> 00:07:30,930
payload vulnerable and that should work.

78
00:07:30,950 --> 00:07:31,670
I'm going to test that.

79
00:07:31,670 --> 00:07:35,210
And if it doesn't work, I'm going to split up into two debug nodes.

80
00:07:36,110 --> 00:07:36,530
All right.

81
00:07:36,540 --> 00:07:40,220
So let's deploy that and clean up.

82
00:07:40,430 --> 00:07:46,070
And first, we want to get a reading from the data twenty to sensor.

83
00:07:46,760 --> 00:07:47,710
So there's the reading.

84
00:07:48,560 --> 00:07:54,680
And next, I want to read the flow variables first, the temperature one.

85
00:07:55,670 --> 00:07:56,390
There it is.

86
00:07:58,240 --> 00:08:08,470
And then second, the slow bearable for humidity and there it is so they can see these two sub flows

87
00:08:08,470 --> 00:08:15,220
are not connected through wires or no messages are being passed around directly, but they do communicate

88
00:08:15,220 --> 00:08:16,960
via flow variables.

89
00:08:18,130 --> 00:08:28,360
And to stop flooding the debug window with messages every 10 seconds from the day to I'm just going

90
00:08:28,360 --> 00:08:31,000
to disable those to debug notes.

91
00:08:31,330 --> 00:08:31,960
All right.

92
00:08:35,570 --> 00:08:42,080
One thing to notice here is that every time that the teacher, 22, is triggered and then the flow variables

93
00:08:42,080 --> 00:08:48,020
are changed or updated, I get confirmation that variables have been set from this dybbuk.

94
00:08:49,700 --> 00:08:51,050
Now, let's do the same thing.

95
00:08:51,050 --> 00:08:57,360
But past those variables over to a second flow in a different tab.

96
00:08:57,500 --> 00:09:01,150
So to do that, we need to use global variables.

97
00:09:01,940 --> 00:09:03,980
So let's go ahead and do that first.

98
00:09:04,010 --> 00:09:10,240
I'm going to go back into my change mode and add another two sets.

99
00:09:10,880 --> 00:09:16,190
So the first one is going to go to a global temperature.

100
00:09:18,630 --> 00:09:24,180
Vargas is going to set the global temperature variable and of course, we want to grab the value from

101
00:09:24,180 --> 00:09:26,520
message payload for this.

102
00:09:27,120 --> 00:09:30,180
And the second one, you can probably guess it will do the same thing.

103
00:09:30,180 --> 00:09:31,590
But for global.

104
00:09:31,590 --> 00:09:36,330
So I'm just going to copy humidity and then.

105
00:09:37,530 --> 00:09:41,130
The value for the global humidity variable will come from.

106
00:09:42,720 --> 00:09:56,660
And g humidity, so the message object to humidity and done, then I'm going to copy these three modes.

107
00:09:56,960 --> 00:10:04,970
So command to see, to copy, I'm going to place them in my new flow, in the verbose flow, and I'm

108
00:10:04,970 --> 00:10:06,650
just going to change.

109
00:10:08,320 --> 00:10:09,730
Flow to global.

110
00:10:11,350 --> 00:10:18,550
And again, flew to grovel for the payload, and that should be enough.

111
00:10:18,820 --> 00:10:25,720
I'm just going to change this to show global values, global values and.

112
00:10:26,690 --> 00:10:27,260
Deploy.

113
00:10:29,500 --> 00:10:30,220
All right.

114
00:10:32,310 --> 00:10:44,060
Let's trigger the DHT 22 sensor variables set and then go into the variables and context example flow

115
00:10:44,060 --> 00:10:45,440
and take a reading.

116
00:10:51,240 --> 00:10:57,010
So the second one, the humidity works, the first one does not, why's that global temperature so much

117
00:10:57,030 --> 00:10:58,830
of miswired something?

118
00:10:58,830 --> 00:11:04,350
Let's go back in my rules and let's see.

119
00:11:06,320 --> 00:11:07,820
Humidity did not work.

120
00:11:09,110 --> 00:11:12,130
So this is interesting, so I'll just show you again the problem here.

121
00:11:12,470 --> 00:11:15,670
So let's have a look at the global variables.

122
00:11:15,680 --> 00:11:18,800
I'm going to trigger the temperature variable first.

123
00:11:19,010 --> 00:11:19,280
Hmm.

124
00:11:20,000 --> 00:11:24,380
And it's giving me the variable set, which is not temperature.

125
00:11:24,380 --> 00:11:25,790
I'm going to look into this in a moment.

126
00:11:26,240 --> 00:11:28,110
And what about the humidity?

127
00:11:28,490 --> 00:11:28,790
Yes.

128
00:11:28,790 --> 00:11:29,910
And humidity works.

129
00:11:30,440 --> 00:11:31,700
So there's a little bug here.

130
00:11:32,420 --> 00:11:34,850
Let's try and figure out why this is happening.

131
00:11:34,850 --> 00:11:37,190
So I'm going to go back to my DHT.

132
00:11:37,190 --> 00:11:44,570
Twenty two example Fluked and then inside the change node and let's see.

133
00:11:46,150 --> 00:11:53,050
I think the problem is right here, as you can see, that in this step, in this rule, I should say,

134
00:11:53,500 --> 00:12:03,130
we said the payload to be viable set just a string of text, and then in the next one, setting temperature

135
00:12:03,130 --> 00:12:11,140
to be the payload, which is what I've set of reset to be the string, Viterbo said.

136
00:12:11,710 --> 00:12:13,720
So this is where the bug is to fix it.

137
00:12:13,720 --> 00:12:25,600
I to move the payload set to the bottom of the list of rules so that the global temperature variable

138
00:12:25,600 --> 00:12:30,250
is set to meet such payload before message payload is changed.

139
00:12:30,790 --> 00:12:31,130
All right.

140
00:12:31,180 --> 00:12:31,990
So that you do it.

141
00:12:32,110 --> 00:12:33,190
Can we deploy again?

142
00:12:34,670 --> 00:12:35,390
And.

143
00:12:36,810 --> 00:12:39,330
The flow still still working.

144
00:12:40,010 --> 00:12:41,860
I'm going to trigger it, actually, just to be sure.

145
00:12:41,880 --> 00:12:45,390
OK, and then going to verbals and check.

146
00:12:46,910 --> 00:12:50,660
Temperature in this twenty two degrees and the humidity.

147
00:12:50,690 --> 00:12:51,770
All right, so that works.

148
00:12:52,100 --> 00:13:01,460
So I can see that we can use global variables set by this change room so that these variables can be

149
00:13:01,460 --> 00:13:04,430
accessed across multiple flows.

150
00:13:05,210 --> 00:13:11,770
Now, one thing that I also want to do is to have the ability to clear those variables.

151
00:13:12,410 --> 00:13:19,950
So I'm going to show you how to do that in a moment, again, using the change rule.

152
00:13:20,390 --> 00:13:30,020
But before we do that and show you how to reset or how to to clear the flow or global variables, I'm

153
00:13:30,020 --> 00:13:37,560
going to show you how to set them and treat them using JavaScript inside a function node.

154
00:13:38,060 --> 00:13:46,250
So let's pick a function going to place set up here and connect it to the to the twenty two node like

155
00:13:46,250 --> 00:13:48,680
this and then in it.

156
00:13:52,360 --> 00:13:59,980
I'm going to just do a bit of copy paste to save a bit of typing like this, so programmatically you

157
00:13:59,980 --> 00:14:08,350
can set a flow variable by using Flotard set first parameter to give you a variable, a name, and then

158
00:14:08,350 --> 00:14:10,890
the second parameter, whatever value you want to store in it.

159
00:14:12,310 --> 00:14:19,180
In this case, I'm going to store the value stored in message humidity inside the humidity, flue variable

160
00:14:19,540 --> 00:14:26,650
and the value stored in a mosquito payload inside the temperature through variable.

161
00:14:27,310 --> 00:14:32,490
It's going to give this function a name and that's about it.

162
00:14:32,500 --> 00:14:38,200
I don't really care what comes out of it because I am not going to connect anything to this particular

163
00:14:38,200 --> 00:14:38,970
function node.

164
00:14:39,340 --> 00:14:40,050
All right.

165
00:14:40,840 --> 00:14:44,470
So this is how you can set a variable.

166
00:14:44,860 --> 00:14:54,130
And now let's read those two local or flow variables using a function node and a little bit of JavaScript

167
00:14:54,130 --> 00:14:54,710
inside it.

168
00:14:55,210 --> 00:14:57,310
So here's my function node.

169
00:14:57,340 --> 00:15:03,000
I'm going to go in and copy a little bit of code that does the reading.

170
00:15:03,670 --> 00:15:05,920
So it looks like this very simple.

171
00:15:05,950 --> 00:15:13,060
I'm using slow dot get and pass on the name of the flow Viterbo that I want to get the value off and

172
00:15:13,060 --> 00:15:15,940
whatever comes back will store it in the humidity.

173
00:15:15,940 --> 00:15:23,260
Local actually node variable and doing the same thing for the temperature variable.

174
00:15:23,830 --> 00:15:24,280
All right.

175
00:15:24,280 --> 00:15:33,640
Now I would like to get those two variables sent out to debug nodes and I want to have two different

176
00:15:33,640 --> 00:15:35,800
debug nodes connected to this function.

177
00:15:36,190 --> 00:15:39,640
So I'm going to create a an array.

178
00:15:40,730 --> 00:15:48,020
They contained two small Jason documents inside, so each one has got its own payload, first one has

179
00:15:48,020 --> 00:15:49,920
got the temperature of the second one, the humidity.

180
00:15:50,180 --> 00:15:51,710
You've seen this notation before.

181
00:15:52,130 --> 00:15:54,170
So this is going to have to outputs.

182
00:15:55,520 --> 00:16:00,110
And before I forget, I will give this function or a name.

183
00:16:02,260 --> 00:16:09,670
All right, so here is our function and we need to Depok notes.

184
00:16:16,610 --> 00:16:26,120
Of course, I could simply connect those two outputs to this debug note, but just keep things tidy

185
00:16:26,120 --> 00:16:27,320
and separate for now.

186
00:16:28,220 --> 00:16:28,640
All right.

187
00:16:28,640 --> 00:16:31,120
So the first one is going to be the temperature.

188
00:16:33,050 --> 00:16:35,870
It's going to float temperature.

189
00:16:37,570 --> 00:16:40,780
And the second one is going to be the slow.

190
00:16:43,120 --> 00:16:43,990
Humidity.

191
00:16:45,980 --> 00:16:54,590
And lost, I need some way to trigger this function, so again, I'll use and inject Nood.

192
00:16:59,790 --> 00:17:07,740
All right, I just send that a number does really matter what it is, whatever it is, it will trigger

193
00:17:07,740 --> 00:17:10,080
the funky mood chocolate trigger.

194
00:17:15,840 --> 00:17:26,970
All right, to deploy, clean up and first trigger the DG to sensor variables is set and then let's

195
00:17:26,970 --> 00:17:31,380
trigger the function to rip them out that you.

196
00:17:33,030 --> 00:17:40,560
OK, now the last thing to do is to expand our function here so that it also sets global variable so

197
00:17:40,560 --> 00:17:46,590
that we can read them from a separate flow, you can probably figure out how to do that is very easy.

198
00:17:46,620 --> 00:17:53,970
So first, I'm just going to duplicate these two lines and instead of flow will say global.

199
00:17:59,870 --> 00:18:15,260
And done, then I'm going to copy this set of notes and pasted in my separate smile like that, and

200
00:18:15,260 --> 00:18:18,650
all I've got to do to make this work is to change flow.

201
00:18:20,200 --> 00:18:20,860
To global.

202
00:18:25,020 --> 00:18:32,130
And that you work, so let's give this a go and deploy and clean, the robots are already in memory,

203
00:18:32,140 --> 00:18:33,710
so I'm going to click on Trigger.

204
00:18:34,710 --> 00:18:42,280
These are the flu viruses that these are the global variables now coming through the debug window.

205
00:18:42,960 --> 00:18:43,370
Awesome.

206
00:18:43,380 --> 00:18:47,340
So now you know how to use both global and flu variables.

207
00:18:47,730 --> 00:18:53,070
One thing I should mention is that these variables and the values are stored in memory.

208
00:18:53,580 --> 00:19:01,980
When you deploy the flu or even if you go through full deployment or even a restarting of the Flo's,

209
00:19:02,340 --> 00:19:10,860
those variables still remain in memory and they will only change if you do so via the function or change

210
00:19:10,860 --> 00:19:11,250
node.

211
00:19:11,580 --> 00:19:20,640
Now, if you want to reset or even delete these variables in order to start from a clean slate, that's

212
00:19:20,640 --> 00:19:25,770
particularly important when you are debugging and you're testing a new flu, then you have to do that

213
00:19:25,770 --> 00:19:28,260
manually again using change mode.

214
00:19:28,270 --> 00:19:35,430
So let's do that now, can take a change node and then go in and say that this is going to be a node

215
00:19:35,430 --> 00:19:45,150
that cleans or cleans or variables and just choose the delete rule.

216
00:19:45,540 --> 00:19:46,710
So you want to delete.

217
00:19:48,480 --> 00:19:49,320
Humidity.

218
00:19:51,790 --> 00:19:52,750
At the flow level.

219
00:19:53,980 --> 00:19:54,610
Delate.

220
00:19:57,060 --> 00:20:02,500
Actually makes the global humidity and then another to delete.

221
00:20:04,830 --> 00:20:05,520
Flo.

222
00:20:07,740 --> 00:20:08,430
Temperature.

223
00:20:10,540 --> 00:20:11,560
And again, the late.

224
00:20:14,440 --> 00:20:15,640
Global temperature.

225
00:20:18,010 --> 00:20:22,990
And I want to also set the notification, so I'm going to use a debug.

226
00:20:24,600 --> 00:20:28,560
Note to indicate to me that fireboats had been deleted.

227
00:20:29,010 --> 00:20:34,920
All right, then let's have our debug window to confirm deletion.

228
00:20:37,710 --> 00:20:43,770
So I'm going to call it delete confirmation, and again, I need the trigger, so I'm going to copy

229
00:20:43,770 --> 00:20:48,960
the trigger note and connected to the change node.

230
00:20:49,450 --> 00:21:00,500
All right, so I'm going to deploy and first, let's see what is inside our flow variables.

231
00:21:00,580 --> 00:21:02,670
So I'm going to trigger flood variables.

232
00:21:02,670 --> 00:21:04,980
And you can see that they do have defined values.

233
00:21:05,580 --> 00:21:07,530
Then I'm going to trigger the cleaner.

234
00:21:07,800 --> 00:21:11,150
So trigger plenel variables and variables deleted.

235
00:21:11,490 --> 00:21:18,030
Then I'm going to trigger again the arete flow variables.

236
00:21:19,260 --> 00:21:21,780
So now let's have a look at the flow variables.

237
00:21:21,800 --> 00:21:24,180
You can see that they are not defined.

238
00:21:25,050 --> 00:21:25,650
I just noticed.

239
00:21:25,710 --> 00:21:27,390
Need to make a little correction here.

240
00:21:27,510 --> 00:21:29,580
So this should be get not set.

241
00:21:30,870 --> 00:21:31,270
Right.

242
00:21:32,070 --> 00:21:38,580
OK, now if I want to reset the global flow variables, I just need to trigger this sub flow.

243
00:21:39,750 --> 00:21:45,390
So that's a value stored in those variables and then I can check them out again and you can see that

244
00:21:45,390 --> 00:21:46,290
they're now set.

245
00:21:48,330 --> 00:21:51,400
Same thing happens, of course, at the global context.

246
00:21:51,420 --> 00:21:54,990
So right now, the global context has got values.

247
00:21:56,870 --> 00:22:06,920
If I clean those variables again, because in the meantime, they would sit so clean them and then test

248
00:22:06,920 --> 00:22:08,690
them, they could see that different.

249
00:22:15,260 --> 00:22:21,380
OK, so with this, you now know everything you need to know to be able to work with flow and global

250
00:22:21,380 --> 00:22:25,310
variables in the context of this project.

251
00:22:25,700 --> 00:22:33,430
So in the remaining lectures in this section, I'm going to demonstrate the use of several other notes

252
00:22:33,560 --> 00:22:37,550
from the left toolbar that will be using in this project.
