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
of how you can use the postdated bequest to send us from your especially to to pretty much any web resource
that can receive data via a post hectically request.
So the skips that I have prepared is this one here.
It depends on its own credentials file, which you can see here.
It's the same file that I showed you in the previous lecture.
But in this case of edit, one more key value pair called thing.
I talk about things in a moment.
It's a term used in tweet IO.
It's just a text file for a string value thereof stored here, and it's filename is in square brackets
in the tab, which means that it's already uploaded onto my E.S.P 32.
You can see it right here.
Now back to the script.
This script uses the same components as the one that you learned about in the previous lecture.
So that is the network and your requests, the Jason to importing random, because I haven't got a actual
sensor connected to my security, so I'll be simulating sensor data with random values.
Before we have a look at the details here, let's go to the widowed IIO and have a look at that first.
So do it.
It is a very simple service which operates as a Twitter equivalent, but for machines.
So Twitter is a service where you can send small messages about a couple of hundred characters at most,
and imagine something similar for machines where a machine will be able to send a quick message to a
tweet thing, which is an end point to a particular Eurail called a thing.
And then other people will be able to access that same URL and read the data that the posting machine
has posted.
So if you go to do it today and then click on the play button, this is basically a single page tutorial
on how to use tweet.
I want to concentrate on this segment of this tutorial first.
So see here, there's an example of how to make a post.
So the URL here is the tweet for thing is a name for your machine.
The thing that you machine is tweeting about, and it's a unique name across the tweet network.
So you find a unique name for your thing.
In my case, I call that you Python.
And therefore the food you are real to which you want to post on your machine will post.
Is this this one here?
I've got the example.
Do it or I'll add four, four, three.
So I'm using SSL here.
Do it for.
And then the name of the thing.
In my case I'm going to extract that from the potentials file which is going to be your python.
So if I could say you python here, this is just an example using the tutorial form the key, I'm going
to leave it as blank.
So the way it allows you to purchase keys that allow you to create posts to things that are private,
so only another machine with the appropriate key will be able to read the posts that you've made.
I'm going to not use the key here and therefore my dweebs are going to be public.
And for the content, we need to use Jason for the content here.
Let's keep something very simple and then to go and grab this content here, something I did earlier
and pasted it right there.
And we'd expect the response that this has been has been a successful tweet and this is a response that
comes back now, if I want to get this tweet mentioned, that another especially to someone else that
will be able to receive data from my other remote, especially to all I need to do is to point the recipient,
especially to to this Jerrell with this thing name and make a get request.
You see here, it says get to do a get request here.
And there's the data.
So we thought it provides a very simple intermediary between machines.
You could have one machine making a post and you could have many machines reading from the post, just
like you've got with Twitter.
You've got one person making a tweet and potentially millions of people receiving that tweet in their
Twitter feed.
So let's do it programmatically now.
So I'm using the same construct here to open up the credentials file and get the credentials for the
Wi-Fi network.
And for the tweet thing that I've been using, I've got my head is here, so I need to indicate to tweet,
which is the recipient that I'll be sending a chasten body content type.
So I'm doing that with the headers variable.
I'm going to be using beheaders variable down here when I make my post request.
So let's continue.
I've got the URL for the tweet.
So this is the base Eurail plus the thing name which I'm extracting from the tweets credentials file
and I've got the exact same do connect method as in the previous lecture's example.
I create the W lan object call the do connect method to make the connection happen.
So as long as I have a connection, then print out the address, the acquired IP address.
Now in this example, I chose to use a timer instead of an infinite loop, and I've set the timer to
send out a new tweet every five seconds or 5000 milliseconds.
So when the five seconds expire, the hardware timer is going to call the post to tweet Aisa, which
jumps the execution of the program up here.
So first get a couple of random values for the temperature and humidity.
I create my chasing object like this, so temp is a random temperature and humidity hum.
It's the random humidity.
Then in line eighty nine I make my post request.
There's the post verb, I'm passing on the URL variable and then the head is viable earlier.
And of course the data and the data.
Remember that this is a chasten object.
I'm going to use a dump's command to create the chasten object out of the data variable.
Next in line 90, I get the response from the widowed IYO and amusingly, load's method of the chasten
module to convert that into a valid JSON document, which I stored in the tweet back viable.
And after that, I'm using these constructs here to extract the individual bits of information from
the adjacent object that we thought IO has returned in the first line.
Ninety one, I just print out the entire object, but after that 1992, 92 and onwards, I'm a bit more
selective.
And in this case, for example, I am grabbing the variable stored.
I just go back to the response point here this so you can see the structure.
I'm looking for the width value right here, which itself contains an adjacent document embedded inside
that embedded chasten document.
I'm looking for the created key, which is right here, so I'm putting that as well.
And then this whole construct together, the two kids, right after one after the other, gives me the
time and date when this tweet was captured by tweet what?
I am doing the same thing with a few others.
Let's have a look at, for example, the the humidity.
If you want to get the humidity value from the response body, which you can see right here, the name
of its key is Hum, which is contained inside content, which is contained inside with.
So that's why you see this construct here in line 96.
All right, so let's try it out and see if it actually works, this tap indicates that the script right
now is on my file system, which is OK.
It will still work when I it to the hospital, too.
And I've got my credentials file already uploaded to the two to flash file system.
I'm just going to click on run script.
First time didn't work.
So they can do their work.
Let's try again.
OK, third time did to why there is a failure in the first couple of attempts, but it's OK, right?
So the third one worked.
It can see that every five seconds.
I'm getting a tweet posted to Twitter IIO.
The response comes back and.
It provides me with a response object in its entirety and then decomposed individual components of that
response.
So let's see.
I'm just going to have a look at the guest request here on the tweet board, I'll play page.
I already have the U.
Python thing named inside the field.
You're going to click on Try Out.
And get the latest values, all right.
You can see that again.
Twenty three, twenty eight to 20 to see if this matches.
Thirty four to twenty nine, he killed thirty four, twenty nine.
Right, we are right here.
Let's do one more try out.
Sixteen forty, which are sick and lost values posted so you can see that whatever my device is posting
anyone else.
There is doing a get request.
To this year will be able to get some I'm just going to go to a new.
Tab posted in there and you can see that this is a raw value of the raw wheat that my be 32 has just
posted.
I can just hit refresh and get the very latest each time.
Still unknown.
Become.
All right, so this works and concludes system illustration, just in summary, can say that we don't
improvise a very simple way to set to connect devices together via a Twitter like mechanism.
All you need to do to do one, get request to receive data or one post request to send data from your
ISP three, two.
And you've got these two devices connected.
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
email via this.