Placeholder Image

Subtitles section Play video

  • 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.