1
00:00:00,660 --> 00:00:02,190
In a previous lecture.

2
00:00:02,280 --> 00:00:09,420
In this course you've learnt about how to create a group that contains multiple notes and the benefits

3
00:00:09,420 --> 00:00:10,170
of doing that.

4
00:00:10,830 --> 00:00:18,720
In this lecture, I'm going to show you a new feature that appeared with no trait version 2.0 that allows

5
00:00:18,720 --> 00:00:21,870
you to set environment variables inside a group.

6
00:00:21,960 --> 00:00:26,880
And once you do that, then those variables will be accessible from any node within this group.

7
00:00:27,630 --> 00:00:33,870
So I've got an extension of the original example that you've seen previously, and in this example I've

8
00:00:33,870 --> 00:00:40,840
got a group already created that contains several debug notes and a change note here.

9
00:00:41,610 --> 00:00:46,800
And before we have a look inside those notes list, check out the group itself, the double click to

10
00:00:46,800 --> 00:00:49,080
open up the properties window.

11
00:00:49,590 --> 00:00:56,910
And then in the environment variables tab can see here that I've got three environmental variables set

12
00:00:56,910 --> 00:00:58,140
for the group itself.

13
00:00:58,710 --> 00:01:05,790
The first one group in VAR one just sets this variable into a fixed string.

14
00:01:06,210 --> 00:01:10,620
So there's a few options here of things that you can store in set environment of.

15
00:01:10,620 --> 00:01:13,830
Our boy just took a string and typed in a bit of text.

16
00:01:14,400 --> 00:01:22,920
The other two are more interesting here because what they do is that they grab a variable and actually

17
00:01:22,920 --> 00:01:24,270
I just found a mistake.

18
00:01:24,270 --> 00:01:25,140
That should be silly.

19
00:01:25,890 --> 00:01:32,250
They just grab a variable that I have already said as an environment variable in this settings file.

20
00:01:32,880 --> 00:01:41,310
So let's switch over to the command line now and have a look at the settings file and just going to

21
00:01:41,310 --> 00:01:43,590
use the cap command for that.

22
00:01:43,860 --> 00:01:46,950
Just need to have a look at the very top of this file.

23
00:01:47,460 --> 00:01:55,830
So at the beginning of this file, outside of the existing module export segment, I have created another

24
00:01:55,830 --> 00:01:58,590
export module to export segment.

25
00:01:58,590 --> 00:02:01,620
And in it I've set a couple of variables.

26
00:02:02,040 --> 00:02:07,170
So each line contains the name for the variable followed by a colon.

27
00:02:07,170 --> 00:02:14,130
Then the words process dot, EMV followed by dot, and then the name of the variable in capitals.

28
00:02:14,490 --> 00:02:21,060
This is a name that I'm using inside node red to access the value for this particular variable.

29
00:02:21,660 --> 00:02:28,650
Let's go back into the file, the settings file and I've got the equals sign and then I'm making a reference

30
00:02:28,650 --> 00:02:35,520
to the operating system function hostname which will return the hostname for my Raspberry Pi.

31
00:02:36,000 --> 00:02:41,700
So this is just one environmental variable that just grabs a piece of information from the operating

32
00:02:41,700 --> 00:02:49,080
system of a comma because then in the next line of code, the second environment variable in this case

33
00:02:49,080 --> 00:02:50,310
it's say a city.

34
00:02:50,820 --> 00:02:55,740
It's just the name that I chose, followed by the colon process that EMV.

35
00:02:55,740 --> 00:03:01,530
And then in capital letters, the name of the environment variable that I'm going to reference from

36
00:03:01,530 --> 00:03:09,480
inside my node, the red node and after the equals sign, just a arbitrary string.

37
00:03:09,480 --> 00:03:12,120
In this case Sydney, which is my city.

38
00:03:12,690 --> 00:03:22,160
So save the updated settings to file and then restart the node red instance like this.

39
00:03:22,950 --> 00:03:29,670
And then the instance at the runtime of the node, for instance, a will pick up this environment variables

40
00:03:29,670 --> 00:03:33,930
and they will be accessible from inside your nodes like this.

41
00:03:34,140 --> 00:03:42,420
So I've got a reference to hostname and city and those are stored in group EMV via two and three respectively.

42
00:03:43,560 --> 00:03:47,250
In my debug notes.

43
00:03:47,250 --> 00:03:50,220
Let's pick up an example and have a look at this one here.

44
00:03:50,220 --> 00:03:59,640
For example, this is just presenting or printing out the value stored in group B in v var three of

45
00:03:59,640 --> 00:04:00,840
the message object.

46
00:04:01,350 --> 00:04:02,730
I've got the same thing here.

47
00:04:04,370 --> 00:04:13,310
So just to recap, before I run this example, you know, trigger it in my group level, I can create

48
00:04:13,310 --> 00:04:22,490
environment variables such as this one here, simply a string or grab values from the operating system,

49
00:04:22,760 --> 00:04:29,720
environmental variables or arbitrary environmental variables that I have set inside the settings file.

50
00:04:30,500 --> 00:04:31,010
All right.

51
00:04:31,960 --> 00:04:36,490
Also, let's check out what's happening in the inject note.

52
00:04:36,940 --> 00:04:40,210
I haven't made any changes compared to what I had in the original example.

53
00:04:40,540 --> 00:04:43,690
I just serve the payload topic which is empty.

54
00:04:44,020 --> 00:04:45,220
And then the message.

55
00:04:45,640 --> 00:04:47,890
Example message here with a bit of text in it.

56
00:04:49,040 --> 00:04:53,080
So I'm going to deploy this flow and then trigger it.

57
00:04:53,090 --> 00:05:02,780
And then you can see that the environment variables that came from the settings file city and hostname

58
00:05:03,260 --> 00:05:10,700
are printed out by the debug nodes as they were set inside the change node.

59
00:05:14,250 --> 00:05:24,090
So just to recap, you can use environment variables in the group level to share the data among all

60
00:05:24,120 --> 00:05:25,920
nodes that are included in the group.

61
00:05:26,340 --> 00:05:35,340
And those environmental variables can be fixed at the group level or the can be fetched or read from

62
00:05:35,340 --> 00:05:36,600
the settings file.

63
00:05:38,220 --> 00:05:42,720
If you want to learn more about environment variables, then have a look at this documentation page.

64
00:05:42,720 --> 00:05:46,560
You can see the URL for this page on your screen right now.
