1
00:00:01,170 --> 00:00:09,000
In this lecture, I'll show you how to send a dummy sensor data to do it, do it know it's just an example

2
00:00:09,000 --> 00:00:18,300
of how you can use the postdated bequest to send us from your especially to to pretty much any web resource

3
00:00:18,300 --> 00:00:22,400
that can receive data via a post hectically request.

4
00:00:23,220 --> 00:00:26,460
So the skips that I have prepared is this one here.

5
00:00:26,760 --> 00:00:31,310
It depends on its own credentials file, which you can see here.

6
00:00:31,590 --> 00:00:34,610
It's the same file that I showed you in the previous lecture.

7
00:00:34,620 --> 00:00:39,960
But in this case of edit, one more key value pair called thing.

8
00:00:40,230 --> 00:00:42,120
I talk about things in a moment.

9
00:00:42,130 --> 00:00:44,910
It's a term used in tweet IO.

10
00:00:45,120 --> 00:00:51,510
It's just a text file for a string value thereof stored here, and it's filename is in square brackets

11
00:00:51,510 --> 00:00:56,300
in the tab, which means that it's already uploaded onto my E.S.P 32.

12
00:00:56,340 --> 00:00:58,510
You can see it right here.

13
00:00:59,700 --> 00:01:00,810
Now back to the script.

14
00:01:01,650 --> 00:01:07,780
This script uses the same components as the one that you learned about in the previous lecture.

15
00:01:08,160 --> 00:01:17,460
So that is the network and your requests, the Jason to importing random, because I haven't got a actual

16
00:01:17,460 --> 00:01:23,220
sensor connected to my security, so I'll be simulating sensor data with random values.

17
00:01:24,800 --> 00:01:31,100
Before we have a look at the details here, let's go to the widowed IIO and have a look at that first.

18
00:01:31,670 --> 00:01:32,550
So do it.

19
00:01:32,610 --> 00:01:40,210
It is a very simple service which operates as a Twitter equivalent, but for machines.

20
00:01:40,580 --> 00:01:47,690
So Twitter is a service where you can send small messages about a couple of hundred characters at most,

21
00:01:48,080 --> 00:01:54,080
and imagine something similar for machines where a machine will be able to send a quick message to a

22
00:01:54,140 --> 00:01:59,420
tweet thing, which is an end point to a particular Eurail called a thing.

23
00:01:59,660 --> 00:02:08,990
And then other people will be able to access that same URL and read the data that the posting machine

24
00:02:09,290 --> 00:02:10,190
has posted.

25
00:02:10,730 --> 00:02:19,640
So if you go to do it today and then click on the play button, this is basically a single page tutorial

26
00:02:19,640 --> 00:02:21,320
on how to use tweet.

27
00:02:21,830 --> 00:02:26,590
I want to concentrate on this segment of this tutorial first.

28
00:02:26,590 --> 00:02:30,860
So see here, there's an example of how to make a post.

29
00:02:31,340 --> 00:02:38,390
So the URL here is the tweet for thing is a name for your machine.

30
00:02:38,840 --> 00:02:44,120
The thing that you machine is tweeting about, and it's a unique name across the tweet network.

31
00:02:44,510 --> 00:02:47,750
So you find a unique name for your thing.

32
00:02:47,930 --> 00:02:50,720
In my case, I call that you Python.

33
00:02:51,230 --> 00:02:57,410
And therefore the food you are real to which you want to post on your machine will post.

34
00:02:57,680 --> 00:03:00,950
Is this this one here?

35
00:03:00,950 --> 00:03:02,090
I've got the example.

36
00:03:02,480 --> 00:03:05,680
Do it or I'll add four, four, three.

37
00:03:05,690 --> 00:03:07,190
So I'm using SSL here.

38
00:03:07,880 --> 00:03:09,770
Do it for.

39
00:03:09,920 --> 00:03:11,090
And then the name of the thing.

40
00:03:11,090 --> 00:03:16,630
In my case I'm going to extract that from the potentials file which is going to be your python.

41
00:03:17,180 --> 00:03:28,580
So if I could say you python here, this is just an example using the tutorial form the key, I'm going

42
00:03:28,580 --> 00:03:29,660
to leave it as blank.

43
00:03:29,930 --> 00:03:38,570
So the way it allows you to purchase keys that allow you to create posts to things that are private,

44
00:03:38,810 --> 00:03:45,280
so only another machine with the appropriate key will be able to read the posts that you've made.

45
00:03:45,830 --> 00:03:50,840
I'm going to not use the key here and therefore my dweebs are going to be public.

46
00:03:51,380 --> 00:03:56,570
And for the content, we need to use Jason for the content here.

47
00:03:56,990 --> 00:04:05,120
Let's keep something very simple and then to go and grab this content here, something I did earlier

48
00:04:05,480 --> 00:04:07,430
and pasted it right there.

49
00:04:09,490 --> 00:04:18,670
And we'd expect the response that this has been has been a successful tweet and this is a response that

50
00:04:18,670 --> 00:04:25,920
comes back now, if I want to get this tweet mentioned, that another especially to someone else that

51
00:04:25,930 --> 00:04:36,280
will be able to receive data from my other remote, especially to all I need to do is to point the recipient,

52
00:04:36,280 --> 00:04:43,680
especially to to this Jerrell with this thing name and make a get request.

53
00:04:43,690 --> 00:04:47,350
You see here, it says get to do a get request here.

54
00:04:47,620 --> 00:04:49,290
And there's the data.

55
00:04:49,780 --> 00:04:54,550
So we thought it provides a very simple intermediary between machines.

56
00:04:55,330 --> 00:05:02,290
You could have one machine making a post and you could have many machines reading from the post, just

57
00:05:02,290 --> 00:05:03,520
like you've got with Twitter.

58
00:05:03,520 --> 00:05:10,660
You've got one person making a tweet and potentially millions of people receiving that tweet in their

59
00:05:11,080 --> 00:05:12,240
Twitter feed.

60
00:05:12,850 --> 00:05:14,890
So let's do it programmatically now.

61
00:05:15,250 --> 00:05:21,310
So I'm using the same construct here to open up the credentials file and get the credentials for the

62
00:05:21,310 --> 00:05:23,080
Wi-Fi network.

63
00:05:23,080 --> 00:05:30,010
And for the tweet thing that I've been using, I've got my head is here, so I need to indicate to tweet,

64
00:05:30,010 --> 00:05:35,170
which is the recipient that I'll be sending a chasten body content type.

65
00:05:35,680 --> 00:05:38,200
So I'm doing that with the headers variable.

66
00:05:38,200 --> 00:05:42,970
I'm going to be using beheaders variable down here when I make my post request.

67
00:05:44,350 --> 00:05:45,460
So let's continue.

68
00:05:45,470 --> 00:05:47,070
I've got the URL for the tweet.

69
00:05:47,710 --> 00:05:55,960
So this is the base Eurail plus the thing name which I'm extracting from the tweets credentials file

70
00:05:57,220 --> 00:06:03,130
and I've got the exact same do connect method as in the previous lecture's example.

71
00:06:03,780 --> 00:06:10,890
I create the W lan object call the do connect method to make the connection happen.

72
00:06:11,710 --> 00:06:18,000
So as long as I have a connection, then print out the address, the acquired IP address.

73
00:06:18,640 --> 00:06:25,510
Now in this example, I chose to use a timer instead of an infinite loop, and I've set the timer to

74
00:06:25,510 --> 00:06:30,860
send out a new tweet every five seconds or 5000 milliseconds.

75
00:06:31,360 --> 00:06:38,840
So when the five seconds expire, the hardware timer is going to call the post to tweet Aisa, which

76
00:06:38,850 --> 00:06:41,460
jumps the execution of the program up here.

77
00:06:42,130 --> 00:06:47,050
So first get a couple of random values for the temperature and humidity.

78
00:06:47,530 --> 00:06:55,890
I create my chasing object like this, so temp is a random temperature and humidity hum.

79
00:06:56,380 --> 00:06:57,820
It's the random humidity.

80
00:06:58,210 --> 00:07:01,420
Then in line eighty nine I make my post request.

81
00:07:01,630 --> 00:07:09,220
There's the post verb, I'm passing on the URL variable and then the head is viable earlier.

82
00:07:09,760 --> 00:07:11,680
And of course the data and the data.

83
00:07:11,710 --> 00:07:14,020
Remember that this is a chasten object.

84
00:07:14,290 --> 00:07:21,670
I'm going to use a dump's command to create the chasten object out of the data variable.

85
00:07:24,260 --> 00:07:33,590
Next in line 90, I get the response from the widowed IYO and amusingly, load's method of the chasten

86
00:07:33,590 --> 00:07:41,230
module to convert that into a valid JSON document, which I stored in the tweet back viable.

87
00:07:41,780 --> 00:07:50,780
And after that, I'm using these constructs here to extract the individual bits of information from

88
00:07:50,780 --> 00:07:55,720
the adjacent object that we thought IO has returned in the first line.

89
00:07:55,730 --> 00:08:02,000
Ninety one, I just print out the entire object, but after that 1992, 92 and onwards, I'm a bit more

90
00:08:02,000 --> 00:08:02,720
selective.

91
00:08:02,720 --> 00:08:07,720
And in this case, for example, I am grabbing the variable stored.

92
00:08:07,870 --> 00:08:13,040
I just go back to the response point here this so you can see the structure.

93
00:08:13,280 --> 00:08:20,900
I'm looking for the width value right here, which itself contains an adjacent document embedded inside

94
00:08:20,900 --> 00:08:22,430
that embedded chasten document.

95
00:08:22,430 --> 00:08:27,800
I'm looking for the created key, which is right here, so I'm putting that as well.

96
00:08:29,020 --> 00:08:35,050
And then this whole construct together, the two kids, right after one after the other, gives me the

97
00:08:36,130 --> 00:08:40,390
time and date when this tweet was captured by tweet what?

98
00:08:40,410 --> 00:08:43,410
I am doing the same thing with a few others.

99
00:08:43,450 --> 00:08:47,170
Let's have a look at, for example, the the humidity.

100
00:08:47,170 --> 00:08:52,930
If you want to get the humidity value from the response body, which you can see right here, the name

101
00:08:52,930 --> 00:08:58,590
of its key is Hum, which is contained inside content, which is contained inside with.

102
00:08:58,930 --> 00:09:04,300
So that's why you see this construct here in line 96.

103
00:09:06,190 --> 00:09:12,760
All right, so let's try it out and see if it actually works, this tap indicates that the script right

104
00:09:12,760 --> 00:09:16,640
now is on my file system, which is OK.

105
00:09:16,900 --> 00:09:19,540
It will still work when I it to the hospital, too.

106
00:09:19,780 --> 00:09:26,160
And I've got my credentials file already uploaded to the two to flash file system.

107
00:09:26,560 --> 00:09:28,420
I'm just going to click on run script.

108
00:09:30,140 --> 00:09:31,430
First time didn't work.

109
00:09:32,650 --> 00:09:33,850
So they can do their work.

110
00:09:33,910 --> 00:09:34,550
Let's try again.

111
00:09:34,640 --> 00:09:43,790
OK, third time did to why there is a failure in the first couple of attempts, but it's OK, right?

112
00:09:43,810 --> 00:09:45,610
So the third one worked.

113
00:09:45,910 --> 00:09:48,490
It can see that every five seconds.

114
00:09:48,820 --> 00:09:53,830
I'm getting a tweet posted to Twitter IIO.

115
00:09:53,830 --> 00:09:56,410
The response comes back and.

116
00:09:58,620 --> 00:10:06,670
It provides me with a response object in its entirety and then decomposed individual components of that

117
00:10:06,930 --> 00:10:07,580
response.

118
00:10:08,220 --> 00:10:09,990
So let's see.

119
00:10:11,160 --> 00:10:20,210
I'm just going to have a look at the guest request here on the tweet board, I'll play page.

120
00:10:20,580 --> 00:10:21,720
I already have the U.

121
00:10:21,720 --> 00:10:25,770
Python thing named inside the field.

122
00:10:26,010 --> 00:10:27,540
You're going to click on Try Out.

123
00:10:29,220 --> 00:10:32,000
And get the latest values, all right.

124
00:10:32,040 --> 00:10:34,080
You can see that again.

125
00:10:36,010 --> 00:10:39,220
Twenty three, twenty eight to 20 to see if this matches.

126
00:10:42,480 --> 00:10:46,560
Thirty four to twenty nine, he killed thirty four, twenty nine.

127
00:10:46,650 --> 00:10:47,970
Right, we are right here.

128
00:10:51,320 --> 00:10:53,060
Let's do one more try out.

129
00:10:54,180 --> 00:11:03,900
Sixteen forty, which are sick and lost values posted so you can see that whatever my device is posting

130
00:11:04,470 --> 00:11:05,460
anyone else.

131
00:11:06,400 --> 00:11:08,470
There is doing a get request.

132
00:11:09,820 --> 00:11:13,600
To this year will be able to get some I'm just going to go to a new.

133
00:11:15,000 --> 00:11:25,890
Tab posted in there and you can see that this is a raw value of the raw wheat that my be 32 has just

134
00:11:25,890 --> 00:11:26,550
posted.

135
00:11:26,670 --> 00:11:30,690
I can just hit refresh and get the very latest each time.

136
00:11:35,650 --> 00:11:36,300
Still unknown.

137
00:11:41,940 --> 00:11:42,270
Become.

138
00:11:43,320 --> 00:11:51,210
All right, so this works and concludes system illustration, just in summary, can say that we don't

139
00:11:51,230 --> 00:11:57,580
improvise a very simple way to set to connect devices together via a Twitter like mechanism.

140
00:11:58,050 --> 00:12:05,730
All you need to do to do one, get request to receive data or one post request to send data from your

141
00:12:05,760 --> 00:12:06,870
ISP three, two.

142
00:12:07,080 --> 00:12:09,990
And you've got these two devices connected.

143
00:12:11,020 --> 00:12:19,180
OK, now let's move on to the next lecture where I'll show you how to use a post request to send a notification

144
00:12:19,180 --> 00:12:20,710
email via this.
