1
00:00:00,630 --> 00:00:06,750
In the previous lecture, he learned about some flows, some fluids provide an easy way to organize

2
00:00:06,750 --> 00:00:10,410
your flows so that you can reuse parts.

3
00:00:10,590 --> 00:00:18,060
And in this lecture, I wanted to take another step and take another look into such flows and show you

4
00:00:18,150 --> 00:00:26,810
three different ways by which you can exchange data between a flow and a flow in this lecture.

5
00:00:26,850 --> 00:00:33,660
I have taken the example from the previous lecture and extended it in order to do my three demonstrations.

6
00:00:34,200 --> 00:00:37,770
I'm going to show you how to exchange data between a flow and its flow.

7
00:00:38,070 --> 00:00:40,650
First, by using flow variables.

8
00:00:40,980 --> 00:00:43,200
What I want to show you how to use global variables.

9
00:00:43,200 --> 00:00:49,380
And finally, how to return one or more values from my flow.

10
00:00:50,070 --> 00:00:53,610
Lack of court in this case a right here.

11
00:00:53,910 --> 00:00:55,450
But let's start from the beginning.

12
00:00:55,710 --> 00:01:04,890
Obviously, the easiest way to exchange data between a flow and other flows as well as between a flow

13
00:01:04,890 --> 00:01:08,400
and a sub flow, is to use our global variable.

14
00:01:08,910 --> 00:01:14,280
So in this example, I've got my trigger, as you see in the previous lecture of editor, a little delay

15
00:01:14,280 --> 00:01:18,930
here because there's a few things that are happening as well that I want to make sure that the timings

16
00:01:18,930 --> 00:01:19,530
are correct.

17
00:01:19,860 --> 00:01:27,270
But after 1/2 we go into the DHT 22 sub flow, which we can see here.

18
00:01:27,720 --> 00:01:34,620
This node will go to the sensor and grab the temperature and humidity and print them into the debug

19
00:01:34,620 --> 00:01:44,070
window, but also use these two change nodes to set a global temperature variable and a global humidity

20
00:01:44,070 --> 00:01:45,750
variable, as you can see here.

21
00:01:46,140 --> 00:01:50,310
So just use the global context from the dropdown here.

22
00:01:51,740 --> 00:01:54,170
Back in our main flow.

23
00:01:54,620 --> 00:02:03,020
We wait for 5 seconds and then I use the change node to grab the values stored in the global temperature

24
00:02:03,020 --> 00:02:11,060
and global humidity variables and then set them into the message payload and message humidity variable

25
00:02:11,060 --> 00:02:14,600
should then those can then be printed into the output.

26
00:02:15,870 --> 00:02:16,620
Just like that.

27
00:02:17,370 --> 00:02:18,870
So let's run it.

28
00:02:18,900 --> 00:02:20,640
I'm going to trigger the flow.

29
00:02:21,330 --> 00:02:26,310
Give it a bit of time, especially for the 5 seconds, so that we can grab the global temperatures.

30
00:02:26,310 --> 00:02:27,330
And here they are.

31
00:02:27,750 --> 00:02:30,450
So humidity global and temperature global.

32
00:02:30,900 --> 00:02:32,170
And they say values.

33
00:02:32,700 --> 00:02:42,300
Those values, again, were set inside the flow, using these to know which is to change routes.

34
00:02:43,330 --> 00:02:44,530
So this is easy again.

35
00:02:44,560 --> 00:02:51,070
You can use the same technique to communicate values across flows in a project.

36
00:02:52,420 --> 00:02:57,940
If you want to be a little bit more precise about who has access or which flow, as you'd say, has

37
00:02:57,940 --> 00:03:04,540
access to a particular value, then global via voice is a bit of an overkill.

38
00:03:04,930 --> 00:03:09,430
It's like using a global variable in a regular program.

39
00:03:10,150 --> 00:03:13,570
Best to be avoided and best to have a little bit more control set in.

40
00:03:14,050 --> 00:03:19,120
So another way you can go about doing this is to use a flow variable.

41
00:03:19,720 --> 00:03:27,220
A parent variable can share its flow variables with a sub flow and I'll show you how.

42
00:03:27,610 --> 00:03:29,020
So here we've got the trigger.

43
00:03:29,200 --> 00:03:35,650
I've set the trigger so that it will store the timestamp into the message payload attribute.

44
00:03:36,160 --> 00:03:43,390
So once I click on this button to trigger the trigger node, I will go into the change node.

45
00:03:43,390 --> 00:03:52,120
And in the change node I take the payload time and date stamp and store it in a flow context variable

46
00:03:52,120 --> 00:03:53,470
called trigger time.

47
00:03:53,860 --> 00:03:55,750
So flow don't trigger time.

48
00:03:57,210 --> 00:04:03,450
Then wait for a second and go into the sub flow and inside the sub flow.

49
00:04:03,570 --> 00:04:12,810
Right here in this function I have a little bit of JavaScript code which uses the flow to get API call.

50
00:04:13,230 --> 00:04:20,490
And what I want to do is to get the value stored in the flow trigger time or flow don't actually get

51
00:04:20,490 --> 00:04:20,760
time.

52
00:04:20,760 --> 00:04:29,340
But because this flow trigger time value is stored in a flow variable that was created by the parent

53
00:04:29,880 --> 00:04:39,570
of these sub flow, I need to prepare a dollar sign parent to the name of the variable that I'm accessing.

54
00:04:39,570 --> 00:04:40,050
So.

55
00:04:40,710 --> 00:04:46,800
So the result is that I'm using float to get and then in parentheses it's dollar sign parent which gives

56
00:04:46,800 --> 00:04:54,810
me access to the flu virus of the parent dot trigger time, which is a name of the variable that I want

57
00:04:54,810 --> 00:04:55,350
to access.

58
00:04:56,040 --> 00:04:59,100
I take the content of this.

59
00:05:00,310 --> 00:05:08,110
Variable in my JavaScript program and store it in the payload of the message and then return that message

60
00:05:08,620 --> 00:05:16,180
once the triggered time that is stored in the parent's flow variable is captured by my JavaScript,

61
00:05:16,660 --> 00:05:25,600
it printed out into the debug window by this debug node and the name of this node is Print Flow Timestamp.

62
00:05:25,600 --> 00:05:27,730
That's the one that I'm going to look for in a moment.

63
00:05:27,730 --> 00:05:32,650
When I trigger the flow switch, go back to the main flow and trigger it.

64
00:05:34,670 --> 00:05:35,320
And.

65
00:05:39,420 --> 00:05:48,510
Here is the print flow timestamp output, which is this number here, which is identical to the timestamp

66
00:05:48,660 --> 00:05:51,060
variable that came out of the trigger mode.

67
00:05:51,900 --> 00:05:52,380
Okay.

68
00:05:52,620 --> 00:06:02,880
So this is the second way by which you can exchange data between a flow and any of its sub flows.

69
00:06:05,610 --> 00:06:10,470
I also wanted to show you a way by which you can return one or more values from a subfloor.

70
00:06:10,470 --> 00:06:11,510
You can see it here.

71
00:06:11,520 --> 00:06:18,060
I've got my DHT 22 subfloor, and you can see that there are two connectors coming out of it that I

72
00:06:18,060 --> 00:06:21,810
then connect to debug notes.

73
00:06:22,320 --> 00:06:28,560
The way you can do this is first in your sub flow to create as many outputs as you need.

74
00:06:28,560 --> 00:06:30,660
So in this case I've got two outputs.

75
00:06:31,170 --> 00:06:34,680
I can add more and you can see that output nodes appear.

76
00:06:36,220 --> 00:06:45,550
Or can delete them and then you need to provide some value going into this output set will be then exposed

77
00:06:45,580 --> 00:06:47,320
to the main flow.

78
00:06:47,800 --> 00:06:53,110
In my case, I used a function in this function of got a little bit of JavaScript.

79
00:06:53,320 --> 00:06:59,140
This JavaScript creates the humidity and temperature variables in the humidity variable.

80
00:06:59,500 --> 00:07:07,690
I store message the payload attribute temperature Walsh store message dot humidity attribute.

81
00:07:08,050 --> 00:07:17,590
And then for my return statement, I've got an array and in an array of call it means JSON statement

82
00:07:18,040 --> 00:07:19,570
where I've got two payloads.

83
00:07:19,570 --> 00:07:24,820
One payload has the value of temperature, the second payload, the value of humidity.

84
00:07:25,660 --> 00:07:32,770
And from there I've got my two output connectors which are connect to the output nodes for my stuff

85
00:07:32,770 --> 00:07:33,160
flew.

86
00:07:33,820 --> 00:07:40,240
These will then come out into the main flow where I can connect them to other nodes.

87
00:07:40,240 --> 00:07:43,810
In this case, two other debug nodes for this trigger.

88
00:07:43,930 --> 00:07:50,170
This flow one more time and see what comes out of these two specific nodes.

89
00:07:53,710 --> 00:07:56,410
It's going to take 1/2 to show supply.

90
00:07:56,440 --> 00:08:03,970
Temperature is right here and then the low flow humidity is right here.

91
00:08:03,980 --> 00:08:07,630
Returned by the flew.

92
00:08:09,380 --> 00:08:10,190
And to recap.

93
00:08:11,310 --> 00:08:18,990
There are a few ways by which you can exchange data between a flow and sub flows, and in this lecture

94
00:08:18,990 --> 00:08:20,850
I showed you three of those ways.

95
00:08:21,240 --> 00:08:26,430
It can use flow variables which are accessible from a sub flow.

96
00:08:26,430 --> 00:08:34,830
By using the parent preprint in the name of the flow variable that you want to access, then you can

97
00:08:34,830 --> 00:08:42,930
use global variables which allow data exchange across any flow or sub flows in a project.

98
00:08:43,470 --> 00:08:51,180
And finally, you've learned how you can return one or more values from a sub flow using the function.
