B1 中級 5 タグ追加 保存
動画の字幕をクリックしてすぐ単語の意味を調べられます!
単語帳読み込み中…
字幕の修正報告
please go to the line, the computer guy dot com and failed normal dot com to see the videos that are too dangerous for YouTube.
Welcome back.
So in this video, we're going to start expanding your horizons on what an art we know, you know, with WiFi or what in our casino, you know, with a network shield can do for you.
So we've done a lot of projects, and in those projects, the yard we know is able to take in information.
And then it's able to output information and may output information to an led light.
I'm a output information to an LCD screen, or it may output information to a Web browser, so this could be very useful in some circumstances.
But it really does have a limited utility.
Wouldn't be it.
Be nice if you could actually send out information from the Arduino to a server and then have that server actually be able to process a response.
So doing things like connecting to twilio or connecting to email service says something along those lines.
One of the great things that you can do with an artery No, you know, with WiFi or just a normal network shield is.
You can actually send data to a server using post, so post is usually used if you're dealing with the Web world.
If you go to an HTML form, you input input your first name, your last main, your email address.
Basically, you hit submit and then that posts that information to a script on a server.
And then that script is able to parse that information and didn't d'oh Whatever it is, you want it to be done so it can either just simply print it out on a screen.
It can print it to a text file.
It can send it to a database, work into a whole bunch of other things.
And so that's one of things that makes post a very valuable tool is now.
You were able to get all of the resource is all of utility out of whatever server you are running versus just dealing with whatever the options yard we know has.
So now you can post to a full fledged Lennox server or a full fledged Windows server use the entire active service.
Active directory service is in order to actually do something based off of the data that is being sent by the Arduino, you know, with WiFi or again if you have a network shield.
So that's what we're going to be showing you today.
Basically, the project that I'm going to do today is I have our standard and along temperature sensor.
So you use this is just the standard sensor toe to give us, like a dynamic, dynamic variables, values for variables.
Then I have the Arduino, you know, with WiFi.
And so what we're going to Dio is we're going to create a sketch for this Arduino, you know, with WiFi, it is going to find out what the temperature is, and then it will post that data to a P eight p script on our server.
And then that PHP script on our server will parse the values of the variables that have given to it, and then it will actually given output.
So all we're going to do today, it is important to understand we're talking about Post.
You can write an incredibly complicated script.
We're just We're just gonna be simple today.
All we're going to dio is we're gonna take the value of the variable we're going to print out a time stamp and then we're going to print out what the temperature is.
That's all we're going to do.
So what are Post is going to dio is the data is gonna be sent from the Arduino.
You know, with WiFi to our PHP script are PHP script is then going to see what the value of the variable is.
It will then print out a time stamp and will print out a temperature on an HTML file that we've created.
And then it will override.
So every time we refresh, we will get a new value for what the temperature and what the time stamp is.
So with that, let's go over the workbench.
I'll just show you how this is built and the more importantly will go to the code.
I'll show you both the Arduino sketch and the PHP script that we're using for this.
Then I'll show you how it all works in the real world.
So this is our project that's been built again for this project.
It's very simple.
We have our standard analog sensor that we've used many times right now.
Eso we haven't plugged in to the five hole we have it plugged into the ground and then for the sensor wire, we have it going to a fire.
So again, it's an analog temperature sensor, so that goes to a five.
And this really all there is to building the project.
So what we're gonna do is we're going to plug this into the computer in order to power the yard.
We know, and to be able to read from the cereal monitor to verify what we're seeing in the Web browser is the same as on the serial monitor.
But do you realize if you don't care about the serial monitor, you can just simply plug this into its own power supply once the code has been uploaded to it and it no longer has to be connected to a computer.
So basically, you could create this project connected to a power supply, put it into your server room or wherever else, and they can just simply truck along without any additional computer being plugged into it so that let's go over and take a look at the sketch and PHP code.
So here's the coat for this particular project.
It is relatively simple, but you do have to make sure you type everything in perfectly.
Remember, you have one computerized device talking to a server and a script, and if you screw anything up, it will not work properly.
So do make sure when you're writing all this out you don't fat finger things because that can run you into some issues.
So the first thing that we have to do is we have to include our libraries.
Where the WiFi nine.
A library here.
This is the library that we use for the Arduino, you know, with WiFi.
And that's all we need is faras libraries or concern.
Then we have the temperature sensor and so we have the sensor pen and we have that defined for a five connected a five like normal that we come down and we have the information required to connect to our WiFi.
Here again, I have a guest network that I've set up in the name of.
That network is test and for me for trouble.
So I don't have to go into stupid troubleshooting.
I just leave the password as blank so I don't run into any random issues.
So SS ideas test password is blank.
Then As far as WiFi connection is concerned, we have to create a variable for status.
We're going to set that to W W L underscore Idol underscore status.
So we're going to simply create the variable status and set it to basically idol to begin with.
Then we're going to come down and we have to create a variable for our server.
So what server are we connected to now?
All you're gonna do with all you're gonna put in here to be clear is the server.
So I have actually created a folder on the flight computer guy dot com server called Test.
You will notice that is not here.
All I want to do is give it the server.
Information will give it the test folder later.
So what?
Coach?
Our server brackets equal.
And whatever Web server your point, investors So www dot you like peter guy dot com, www dot failed normal dot com www dot my domain and dot com.
Whenever server, you're pointing the two.
You are pointing it just to the server here.
You don't put the subdirectories that you're going into then we're going to come down here and we're going to create a strings.
We have to create a couple of variables to in order to send the data with a post.
And so the first variable that we're creating is Post Data.
So this is the data that will be sent using the Post.
They were going to create a string called Post Variable.
So this is the name of the variable that we're going be sending, and we have that temp equals.
So basically, what's going to happen is temp is going temp equals, and then we'll get the number for a temperature Fahrenheit, and all of that will be sent as post so his temp and equals.
You gotta make sure you have the equal there.
So this this right here can basically be whatever the hell you want it to be.
This is whatever variable name you want it to be.
But you do have to have this equal Evia.
So basically saying this variable equals and that's that's how it's gonna gonna work for the post.
Uh, then we have the WiFi client.
So again, this is just more of the WiFi connection, and that's that's that.
Then we're gonna go down, and we're actually going to set up our environment, and this looks basically the same as every other time we're using the WiFi.
We're going to do serial job again.
9600 to start our serial monitor.
Then we're going to do the wild loop.
So this wild loop is what actually connects us to the WiFi network basically attempting to connect to network named test.
Then why find out?
Begin test and the password it will keep looping will keep you in the wild loop until it's actually connected.
Once it's been connected.
Then on the serial monitor, it'll print out Yes.
S I d the name of the s s i d.
And then it will print out the i P address.
So once it's actually connected, it'll print out the S s I d.
And the I P address so that we know it is connected will be able to read that on the serial monitor, and then we get down to the new cool stuff.
We get down to the new cool stuff.
So this is the loop.
So this is Luke that we're going to be going through.
The first part of loop is copy and paste.
So the copy and paste for in order to read from a analog temperature sensor.
This is just that normal thing again.
At this point, just copy.
Pasted.
Keep moving.
This This is what creates the variables for temperature.
See, for temperature Celsius if you want, or temperature f so temperature Fahrenheit is what we care about.
And so what we're going to do here is this Post Data string, right?
So this post answering this variable up here remember, it is a string.
That's what we're going to is post data equals and so post variable.
So what that means is post data equals temp equals and then plus, Tim, pick your f So whatever the value of temper cure F ISS.
So what is going to do is going to say post data equals temp equals 77 or 76.35 or whatever else.
So this is what's going to be sent in the post.
Then we're gonna do is we're gonna come down here, and we're going to go to actually send send the information the Post.
So if client doc connect to server, So server, if we go up here, that's alive.
That Peter guy dot com if connect a server at Port 80.
So if it's able to connect, then what we want to do is client, not print line.
So this is gonna print out to the server that we're connecting Thio Post.
So we're saying this is a post, and this is where you put the sub folder and in the script that you're posting, this is the only place that you put it.
So again, you're creating a test folder or whatever sub folder again.
I would, I would highly argue book.
You should create sub folders if you're doing these tests.
So what we're saying is in the test sub folder, we want to post this to the post dot PHP script.
So I created a post op PHP script, and so this is then sending.
So it's going to the server.
So it's going to be like Peter guy dot com forward slash test forward slash post dot PHP.
Simply saying 80 a t t.
P.
1.1.
There we go down here to the print line, another print line host allowed to create a guy dot com and we tell it what content type Then we tell it the content length And so we get the content length by using this function post data dot length And so this will send.
So basically, what this is doing is this is sending information so that the server knows what's coming.
And then finally, we're gonna come down here.
We're going to do client dot print post data.
So what were sent doing is we're sending the post data, So the post variable plus the temperature farenheit we're sending that to the post dot PHP.
If Klein is still connected and client stops, then one of things that added in here is we're going to serial dot print line post data.
So then, in the cereal monger, we'll also be able to view what the yard we know is sending out to make sure that it's right again when the biggest problems with scripts and servers and all those kinds of things is that you you fat finger something and you put a capital T where you put a cap, you know, you put a capital in their own place, you put a space in the wrong place.
So what this does, is this gonna print out for a troubleshooting procedure will print out to the serial monitor so we know what is actually being sent.
So this is going to get sent to this post dot PHP script.
We go down here.
So here is the PHP script that's going to be parsing the data that has seen being sent by the Arduino using post.
So I have called this post dot PHP.
You can call it basically, whatever the hell you want as long as you you put that name into the yard.
We know code, but do have it end with dot PHP.
So the server knows howto deal with it so that it needs to have that dot PHP extension.
The first thing that we're going to do is we're going to open the PHP script to say we have PHP code here and then we're going to start creating the variables.
So the first variable that I'm creating is dollar sign time.
When you're dealing with PHP, you have to put a dollar sign in front of the variable name.
That's just one of the quirks of PHP.
We have dollar signs time and they were going to make dollar signing time equal to the value of the time function.
So this time function will simply spit out a number, basically the time in computer speak and what I'm using this force.
I'm using this for a troubleshooting procedure, right?
So when I use a Web browser and I go to tempt dot html, I don't want to make sure that it's updating how it's a post update.
I can do that rather easily if I have a time code, right?
So if I go and I refresh the page and the time code updates, then I know that the script is at least functioning.
At least the script is running on and things are being printed.
If I go to the page and the time code does not update, then I know there's a problem with the script.
So So this time code here is not gonna be formatted, and a day and date and time and all that kind of stuff is just gonna be one.
It's just gonna be a pure number that the computer deals with.
All that I care about is from a troubleshooting standpoint, I can see that that number is updating.
This is something that I will probably rip out if I actually is putting this into a production project.
But at least right now I'm using a guest for troubleshooting.
I may rip it out or I'm a format it into a time and date.
That's a little more easy to use.
But here I'm just pulling.
I'm just pulling the wrong number.
Then the next thing that we're going to d'oh, we're going to create the dollar sign temp F So basically the variable for temperature Farenheit We're going to make it equal to dollar sign underscore post bracket, double quotation temp.
So when we go over here to the Arduino code, if we go up, you see how post variable is temp equals.
So that's what we're looking at is we're looking for the value of temp, so temp equals and we come down here so post data is post variable, so tempt equals whatever the temperature is right.
So when we're looking at this for the variable, so we're going to look at what's being sent in that post, and we're going to see the value for temp what temp equals.
And then we're going to set the value of temp F tow, whatever this value ISS, then the next thing that we need is the file.
So whatever you do with PHP basically turned everything into a variable.
Also, we have dollar sign file, and then we have to tell it, What file are we printing this information to?
So we're going to make it equal.
Single quotation mark tempt dot html So more or less you can You can make this whatever the hell you want.
We take temper dot HTM dot html believe oh, bob dot html Whatever, Whatever you're gonna remember, this is simply the file that we're printing out too.
Now with PHP.
If this file does not exist, it will be created.
So you don't have to to create this initial if you don't want Thio.
So you put in whatever name then what we're going to do is we're going to create the data that will be sent to this file.
So what I want to do here is I wanna be I wanna format everything wanna bring.
I want to bring all the data together, the one nice, neat little package so that I can send it to the file.
So what?
I'm gonna be doing here is I'm not Beacon Captain ating.
So basically, I'm super gluing some different variables and data together, So data is going to equal the value of the variable time.
So basically, whatever this time code is, and then to concoct Nate and PHP, you use the period.
So the superglue something to the end.
So we do double quotation marks.
What we're super glowing to the end of time is two spaces, a hyphen and two spaces.
So we're just doing little formatting hears we're gonna have a value of time, space based hyphen, the space space.
Then we're going to do period again.
So this is a super blue, then the dollar temp F So the value for temperature Fahrenheit.
So what it's gonna do is it's gonna give us a time code space, space, hyphen, space space, and then one of the temperature Fahrenheit ISS Then Morgan do is in PHP.
There's this function called file underscore.
Put underscore contents.
Basically this simply rights data to a file, and so we're going to give it the very variable dollar file.
So this this is the file, so we're gonna be sending to temper dot html and then we're going to say send to temper dot html the data.
So we're going to be sending this to tempt out html and that right there is all there is to this particular code s.
So let me upload this code to the yard.
Ueno and I could show you how it works.
So now I'm going to plug the Arduino end to my computer, Said this will give it power.
And I will also be able to read from the cereal monitor with that will go up to tools.
Will go up to serial monitor and see what's going on with it.
So we can see currently that it's trying to connect to the network name test.
This will take about 10 seconds for it to connect.
See here.
Uh, okay.
Now it's connected.
So you've got S S I d test.
We've got the I P.
Address.
1 72 Don't.
16.
42 not five.
And now it's printing out the information.
So tempt equals 68.56 is what is being sent to that.
That script that that post dot PHP script that we have up on a lot of Peter guy dot com.
So then I can go.
I can open up Google Chrome And so, as you can see here, this feline computer guy dot com forward slash test So this is the sub A folder, and then we're going to tempt dot html again.
No fat finger.
Don't be stupid.
Don't don't go to post that PHP Post op P.
D.
B is a script he sent the data to temp dot html is where you're reading it, right in a human readable format.
So I go here, you can see this is the old time code and this is the old temperature.
If I do a refresh, we can see The important thing is we see the new time code and the new temperature again.
One important things to remember is when you're looking at the serial monitor, this is auto updating.
Do you realize if you're looking at this basic web page, literally, all this is is text.
So if you wanted to update, you actually have to click the refresh.
And as you click the refresh, you can see that the temperature changes.
So they're going to say we see right here.
So the temperature stayed the same, but the time code changed.
So we know the script is working now.
If I go here and again, I put my finger on little and a lot of temperature sensor to try to heat it up.
That I can refresh.
There we go.
We see it goes up to 79 11 and then I can refresh.
Recieve goes up to 81.
And if I refresh again, we see it goes to 82.
Fine.
Take my finger off, give it a second, then refresh again, Now goes down to 80.
So this is showing you that the yard we know is sending the data up to that post up here to be script that post a PhD script is parsing that data and sending it over this temp, not html page, and were able to open it up again.
All of this being printed out right now is just pure text.
If you wanted to make this fancy with HTML tags or again, if you want to dump this into a database or whatever else that that's that's up to you.
But this this shows you the basics of using post with the yard.
We know, you know, with WiFi.
And so that's all there is to this particular project again.
It's very simple.
Set up a CE faras hardware is concerned, Then all we're doing is creating a sketch for the yard.
We know we're having that sketch using post.
Send that data to a post about PHP script again.
You can call that whatever you want.
Basically, is just a script in order to parson at it that's coming in through the post and then send it somewhere else.
We just simply sent it to a file as plain text.
But again, if you know what you're doing, you can dump this into any kind of database.
You can parse this with other types of scripts.
You could do all kinds of fancy things.
The main thing I'm just trying to track ticket three TV here is that this can send out a to a server, the server that can then parts that data and then fancy things can happen.
So I think this is an absolutely great tool.
And again, this is one of those things that makes our DWI knows incredibly useful, because imagine if you have artery nose around with all, all types of distance of different sensors.
So imagine if you had some kind of accelerometers.
So if you were in a warehouse environment and is detecting whether whether, like shelving gets knocked or some kind of pallets get knocked if it gets knocked, it could post that data to a server, and then that server would then be able to do things like send out of notification on a twilio.
AP I something like that.
That's one of the really important things to understand what they're doing.
Because a lot of people, a lot of people they look at Arduino, has little or no, you know, it's a little are doing.
Why the hell should I care about her?
You know.
But the reason I get frustrated is it's like anything in technology, each individual component in the technology industry really isn't that that amazing?
What's amazing is when you tile of these things together.
It's not that the yard we know is like the most amazing thing in the world is that the Arduino is something of allows you to create custom sensors that air, then able to send information to servers.
Those servers you can then create scripts that again could do email notifications or SMTP notifications, or fire off all kinds of things.
And that's when I think you have to be thinking around technology.
World is just no hyper don't say, like, How do how do I make money off Arduino?
That's not really That's not really How it works is one of those.
How do I use Arduino and a server and AP eyes and all of these things to solve a problem.
So again, like I say with these little ordinary nose, the great things, too, is you can actually send data from multiple different sensors on the Arduino.
So, I said simply show you how to send information for one variable.
But literally you could have.
You could have 20 different different values being collected by the Arduino.
You could have a light sensors.
You could have accelerometer sensor.
You have temperature sensors, you can have humidity sensors.
And so imagine just if every minute it sends that information up to a server, that server then just dumps that into a database.
And then once it's in a database, you're dealing with sequel and then the sky's the limit.
As Faras how you want to analyze all the data that's in that database.
So this this is why Arduino gets to be really cool again.
You look at it.
Turning on led is printing things out.
LCDs they're not.
That could be very useful.
But one of things that really makes the Arduino a great a great little tool, especially in the I t world, is the fact that you can now send the information to a server.
And then once that information is on a server, once it gets into it dumped into a database or a file, then then a lot of amazing things can happen.
So when you're dealing with the Arduino, this is one thing when you think about is learned the art we know.
But then realize the product's gonna be putting in the field, the products are going to put in the production environment.
It's gonna be hard.
We know with the Lenox server, with AP eyes so on so forth.
So that's all there is to this particular project.
We will do.
More projects were will actually be sending more variables.
If you want to look into a induce a Google search, asi basically this using and again, all it is is post all It isn't if you understand Post.
Uh, but we'll do another project with that in the future.
With this, I just wanted to show you how to use one variable.
Be above.
Send it.
Once you feel comfortable with that, they will start doing more complicated things.
As always, I enjoy doing this.
Video analyst for the CIA, the next door.
コツ:単語をクリックしてすぐ意味を調べられます!

読み込み中…

Write POST Data to Server with Arduino Uno with WiFi

林宜悉 2020 年 3 月 27 日 に公開
お勧め動画
  1. 1. クリック一つで単語を検索

    右側のスプリクトの単語をクリックするだけで即座に意味が検索できます。

  2. 2. リピート機能

    クリックするだけで同じフレーズを何回もリピート可能!

  3. 3. ショートカット

    キーボードショートカットを使うことによって勉強の効率を上げることが出来ます。

  4. 4. 字幕の表示/非表示

    日・英のボタンをクリックすることで自由に字幕のオンオフを切り替えられます。

  5. 5. 動画をブログ等でシェア

    コードを貼り付けてVoiceTubeの動画再生プレーヤーをブログ等でシェアすることが出来ます!

  6. 6. 全画面再生

    左側の矢印をクリックすることで全画面で再生できるようになります。

  1. クイズ付き動画

    リスニングクイズに挑戦!

  1. クリックしてメモを表示

  1. UrbanDictionary 俚語字典整合查詢。一般字典查詢不到你滿意的解譯,不妨使用「俚語字典」,或許會讓你有滿意的答案喔