Placeholder Image

Subtitles section Play video

  • please go to the line the computer guy dot com, in order to view schematics, code and Maur for the projects that you are learning about.

  • Welcome back.

  • So one of the big uses for art we know projects is to tell end users when there is a problem.

  • So let's say you have a server room.

  • You're worried about the server room overheating, and so you put in some kind of led light system.

  • So basically, if the temperature is below, a certain level of the light is green.

  • If a typical goes above a certain level.

  • But the light is red, right?

  • That's the type of project you could d'oh with an art.

  • We know.

  • But one of the problems comes up is what happens if there's not a user there to visually see whatever type of notification that you're trying to present.

  • So what if somebody is not looking at a Web browser to see a notification event?

  • What happens if a user is not even in the building to see an led turn on or turn off?

  • Wouldn't it be nice if you're good?

  • We know project could send you a notification using S M T p basically using email service is so whatever email client you have, whether you have a desktop computer, whether you have some kind of smart phone or whether you even have a smart watch, you can get notifications no matter where in the world you are, what time of day it is so on and so forth.

  • And so the project that I'm going to show you how to do today is we're going to use a simple and along temperature sensor.

  • And when the temperature gets above a certain level, what's going to happen is our Arduino, you know, with WiFi is going to post to a PHP script on a server.

  • And then that server is going to send out an email using the mail of function within PHP.

  • And once that email is sent out, then I can reserve the email on whatever email client that I am using.

  • So the important components that we're gonna be needing for this project today was we're gonna use the Arduino, you know, with WiFi that we have been using.

  • I am going to be using a simple and along temperature sensor.

  • Now.

  • It is important, understand?

  • I use the analog temperature sensor because it's just a very easy sensor to use on.

  • Give it thresholds for code within the artery.

  • No, but realize you can use any sense.

  • Or basically, you can state if a sensor triggers or the value gets to a certain you know, height or searching low, you can trigger an event to happen, so it is important to realize that.

  • But so we're using the artery.

  • No, no, no.

  • We're using a basic analog temperature sensor, and then what we're going to use is we're going to use the post function within the post ability within the artery.

  • No una WiFi to post up to AP AP script on a share hosting plant.

  • So it is important understand with this project that I am using a shared hosting plan from Go Daddy.

  • And there's a reason I'm using a shared hosting plan from Go Daddy.

  • In order to send out the email, we're going to use a PHP function simply called mail.

  • So if you're using the PHP scripting language, there is a function that you could use Cold Male, and what that male function does is you give it the variables that you're giving it, and then it uses whatever the default email service for that server is to be able to send out the e mails.

  • When you're building your Web server, you install a Paki, you install my sequel.

  • You would sell PHP well.

  • One of the things that's installed by default on most share hosting platforms is also an email service.

  • So they have already installed the email service.

  • They have already configure the email service.

  • They have already done all that.

  • So when you call the male function within PHP, it simply uses all that to send out the S and T P.

  • Massive.

  • So what is important to understand that if you decide to build your own lamp server to do this project, you're going to have to install your own email service is, and that could be a pain in the butt.

  • To be polite, it could be a payment about.

  • This is one of those times, especially if you are learning you're not planning to put this into a production environment, I would highly recommend you simply spend $5 a month for a shared hosting plan again, Whether it's go, Daddy, Daddy, your host Gator, I don't care who it is.

  • Spend a couple of dollars so that you don't have to build your own server for this particular project.

  • But this is just something to keep in mind.

  • So even if you have a lamp server, even if you have a full Web server with PHP installed if you said the post to that server to the script on that server, that server will not be able to use the mail function unless you have configured the email service is on the server.

  • So just keep that in mind.

  • With this project, we're going to be using a shared hosting plan, and that's what I would highly recommend for you, especially if you're learning.

  • And honestly, even if you're not learning, if this isn't like this is a high security is not high security type message and that you're doing honestly.

  • I just pay $5 a month for a share of hosting plan, just so I don't have to worry about it.

  • But yeah, that's me so that let's go over, take a look, how to physically build this project, and then I will show you the code.

  • Both yard we know code and the PHP code that's required to make this project function.

  • So this is the physical build for our project.

  • And you have probably seen this physical build a number of times before.

  • If you've been watching my other videos again, all we're doing is we're using analog temperature sensor, and we're using this in order to get dynamic readings to be able to trigger events to happen based off of those readings again, you could have motion sensors here.

  • You could have distance sensors here you get of all kinds of different sensors here.

  • I'm just simply using a temperature sensor because it gets the point across.

  • So we have the analog temperature sensor analog temperature sensor.

  • We have this coming to five volt for power we have is going to ground for ground and then the sensor pan for this particular project.

  • We're using a five, but you could use a zero through a five, I guess.

  • Used a five for this.

  • Now, we are going to be powering this off of our computer today, so I'm gonna be plugging this into the computer.

  • This will give us power and will also allow us to see what's going on with serial monitor.

  • But do you realize that if you don't need the cereal, not monitor functionality?

  • You could simply have this plugged in using a normal 12 volt connection or some kind of other USB power supply and have this completely separated for computer.

  • So you could just put this powered up into your server room.

  • And then everything that I'm showing you today will work so long as it's able to actually connect to the WiFi network.

  • So with that, let's go over and start taking a look at the code.

  • So when we're looking this project, it is important to remember that we're going be writing to different programs.

  • So we're going to be writing a sketch for the Arduino and then for our share hosting server.

  • We're also going to be right in a p A P script.

  • So this is again one of the reasons why I laugh so hard when people ask what one what one?

  • The language they should learn if they want to be a coder, because in reality, even something as simple as what I'm showing you today actually uses multiple languages in order to make this thing work.

  • So I really want you to start realizing that when you start thinking about Cody and we start thinking about the coyote world, it's not about learning one product or one language.

  • It's about learning all the different tools that are required in order to get done whatever it is you're trying to accomplish.

  • So first, let us go and take a look at this sketch.

  • So this is the Arctic doing now sketch that I've created and this sketch is what will be uploaded to the art.

  • We know Bono with WiFi.

  • The first thing that we need to do is we need to include the library for the WiFi for the art we know, you know, with WiFi.

  • So we use WiFi Naina for most of my projects here.

  • Then we need to define the sensor pin.

  • So we're simply defining the analog pen a five as the sensor pin.

  • So this is where we'll be getting readings for the temperature sensor.

  • The next thing that we need to do is we need to give the information for how to connect to the WiFi networks of char s s I D.

  • And I have a guest network called Test and that guest network has no password again.

  • I do this to make my life easier, so I don't have to troubleshoot networking problems while I'm trying to do something else.

  • If you have a password or whatever else, you would plug that password in there, then we're gonna come down.

  • We're gonna create a variable for status for the WiFi network.

  • We're basically going to send it to idle.

  • So this is for when we're trying to connect to the WiFi network.

  • This is used for the for the wild loop for trying to connect.

  • Then we're going to come down for the server.

  • So char server.

  • So this is the server that we're going to be connecting?

  • Thio s.

  • So for today, I'm actually using the fail normal dot com server.

  • So it's www dot fail normal dot com.

  • Now it is important to understand is I am not putting any folder structure here.

  • I am not putting the script information here.

  • I am simply putting the server that I'm pointing acid WW dot fail normal dot Com Www You are the computer guy dot com.

  • Whatever the domain name is for your server, just put that there.

  • You do not put the folder.

  • You did not put the script name.

  • You don't put anything else there.

  • They were gonna come down.

  • We're going to create a string four post data.

  • So post data is the data that we are actually going to be sending to the server for that post.

  • So we just create that variable there, and then I'm also creating a string, and I'm going to call it a post variable, and it's going to tempt equals.

  • So basically, this is simply the name of the post variable that I'm sending.

  • So temp equals 86 temp equal 76 p equals 102.

  • So basically, when I send the information in a post, I have to say, with the variable name is so that I can that I can pull out what the value for the variable name is.

  • So here, that variable name variable name is actually temp, and then it's going to be equals.

  • So I just put that all here together.

  • So whatever your your variable name is, you know, time equals distance equals whatever they were gonna come down.

  • We're gonna set up the clients a WiFi client client again.

  • This is just simply required for the WiFi network.

  • Copy and paste.

  • Shove it in.

  • Now that we've done that, we have to set up our environment.

  • So we go into a void set up to set up the environment.

  • The first thing we're going to do is cereal about began 9600 to start serial monitor.

  • This is mainly just for troubleshooting purposes.

  • Then we're going to go into the wild loop.

  • This wild loop is what connects us to the WiFi networks awhile, while a status does not equal wirelessly connected a serial, a print, blah, blah, blah WiFi not begin.

  • And this is the function to bribe the S S I.

  • D.

  • And the password to try to connect to the WiFi network.

  • It keeps looping through there until that it actually connects.

  • And then once it actually connects to the WiFi network, it breaks out.

  • Same thing is normal.

  • Then what we have down here is we're simply going to print out to the serial monitors some basic information, so we know a little bit about what's going on with art.

  • We know s we're going to print out the s s I d So what?

  • The s s i d is And we're also going to print out the i P address.

  • So once it's been connected, it'll say it is connected to this s i s s I d.

  • It's connected to test, and this is what I p addresses in case we need that.

  • So now we're going to go down and we're going to go into the loop.

  • That's actually gonna provide the cool functionality, right?

  • The first thing in this loop is we have the simple copy and paste math here for coming up with the temperature.

  • So in order to basically, you have to grab the voltage value, you have to grab the value that the animal temperature sensor is providing.

  • And then you do a bunch of math on that to turn into a temperature in Fahrenheit.

  • This is that math again.

  • We've talked about it for other projects.

  • Copy and paste that if you want to look not learn more about it, take a look at those other projects.

  • Then we're gonna come down here and we're gonna take this post data variable.

  • So that string that we create it up here, string, post data and we're going to make it equal to post variable was going to be equal to tempt equals and then plus, so what this does, is it It's called concatenation.

  • So contamination is when you when you kind of super blue things on to the end of each other.

  • So what it's gonna do is going to do temperature, attempt equals and then the value for temperature f.

  • So we create a variable temperature f here.

  • So this is a temperature of Fahrenheit, and so we're going to do temp equals.

  • Whatever the value of temperature F is, there's no space, there's nothing there.

  • This is all just sandwich together, and that becomes our post data, and that is what will be posted to the server.

  • Then we're gonna come down here to the actual if statement and so four hour if statement we have.

  • If temperature F is greater or equal to 80 so 80 degrees is what I figure is too high a temperature.

  • If that happens, then what we're going to do is we're going to connect, and we're going to send the post at so then we'll say if client not connect server at 80 so server server is up here, so that's www dot fail normal dot com.

  • And 80 is the port, right?

  • So if client doc connect, so if it can connect to www dot feel normal dot com at poor 80 then go through and do the rest of this.

  • So then we're going to do client so clients it is ascending out to the client that you've connected to.

  • So this is sending out to that Web server that you're connected to.

  • It's sending to www dot fail normal.

  • That very important.

  • When you talk about, we're talking about printing.

  • It's important who you're printing, too.

  • So this is printing out to the client you connected.

  • Thio cereal is printing out to the cereal, so once we've connected, we're going to client that print lines were sending on.

  • It's gonna be a post, so we're gonna say Post and then this is where we put in the folder structure and the script that we're actually pointing at.

  • So I have created a folder called Test on Fail normal dot com and then PHP script we were sending this post data to is email script dot PHP and they were simply saying is a T T p 1.1.

  • So this is where you put that folder structure and the actual script that you're sending this to again.

  • Remember, this is PHP and everything else, so things like capitalization does matter.

  • So make sure all your capitalization is right anyway, so we're gonna post they were going to say the host.

  • So what is the host?

  • We just put in the w w dot failed horrible dot com.

  • So host and server should remain the same.

  • They were a new client, not print line caught content type.

  • So we're gonna be telling it what type of content this is.

  • And so we're saying former U.

  • R L encoded.

  • That's for the post.

  • Then we're gonna tell it how long the data is the content length on.

  • That's what we do here.

  • We have a variable for figuring out what the content like that we're sending it to again.

  • At this point, this is just copy of paste.

  • And then finally, after what we do, all of that, we actually send the post data.

  • It's a client, not print post data, and that post data is going be temperature equals, whatever the value of temperature is, and that would be that would be sent up there.

  • Then what we're going to do is on this serial monitor.

  • So this is cereal print line.

  • Just so I know that this has occurred, we will.

  • We will print out email sent.

  • So we'll say email sent front line, and then it'll print another line and tell us what the value of temperature F is.

  • Just so we know when it got said again for doing any kind of trouble shooting here, then if the client is still connected, then the client is going to stop again.

  • This is copy and paste now, one of things.

  • It's not copy and paste.

  • Here is this delay.

  • Delay.

  • This is something you got to think about as a coder, and this is gonna be your decision.

  • You can do whatever the hell you want right here, but basically we need to some type of a limiter.

  • Remember that when you're dealing with Arduino Arduino diskettes looping Lupin, Lupin!

  • Lupin!

  • Lupin!

  • Lupin!

  • Lupin!

  • Lupin!

  • Lupin!

  • Lupin!

  • Lupin!

  • Lupin!

  • Right!

  • And so if you look at this, if you look at this, if you don't put any kind of delay in here.

  • Guess what's gonna happen as soon as the temperature goes above 80 degrees in your server room, you are going to get spam to hi Helen bag because it is going to run through this every time it loops.

  • So if it's above 80 degrees, it will send an email, sent an email, sent an email, sent a team.

  • I'll send an email, and all of sudden you've literally got 1000 e mails and your your mailbox, right?

  • Because basically, if it's above 80 that I'm sending the post, it goes to PHP script PHP script fires off email that's not useful to anybody.

  • So what I have done here is I've put in a delay of 60,000 so one that 1000 milliseconds equals one second.

  • So 60,000 milliseconds equals basically one minute, 60 seconds.

  • So what's gonna happen is if the temperature goes above 80 it will do.

  • It will<