 Okay, so here I have two ESP8266s. They're both already programmed with almost identical programs. Just one is the example that I'm going to show you the code for that will ping my computer locally. The other one already has keys and stuff on it to connect to my Films are Chris server. So I want to show you that code because there's private information on there. But let me go ahead and show you this one. So let me switch over here to the computer. Yeah, let's do this. Okay, right here. If you can read that. Let me sit right here while I just switch over to the view on the computer here. Okay, so here I have busy box running. I'm about to start running it. HTTPD. So it's just a web server. It can be running any web server. But I'm just using this as an example. I'm going to be running on port 9999. So that that's just a port I'm not using right now, because it's just an example. Then I do dash VV for verbose so we can get the output of the screen F forces it into the foreground to the background because right now I'm just showing this to you to show you how the the signal comes in. So I'm going to plug in the example ESP8266. And it'll take a second to connect. Oh, hold on. Let me unplug that and actually start up the server. Okay, now I'm going to plug in the ESP8266. It should take a couple seconds to connect to my server and then it's going to do an HTTP request to this computer. There we go. And these files actually don't exist. It's just an example. That's what we get the four on one. But you know what? It ran the one URL immediately, then it waited five seconds. And then every second after that it's going to ping the second URL. Okay, so it pings the first URL the second it boots up, waits a certain amount of time, a longer amount of time, pings the URL and then for every second after that it loops. And as you'll see as we get further into this little test you'll see how what I'm using this for. So let's see. So again that's the code here on this ESP8266 chip which is the example code. Again this is identical code just with different URLs and security keys on there. Plus with the, I'm going to show you the code here that I used. And yeah, so let's go ahead and look over here at the Arduino code, the ESP8266. Okay, so here is the code. And it's basically the basic example for HTTP request a client, HTTP client, web client for the ESP8266 when you install the ESP8266 modules for your Arduino interface. This is the example with a few changes. So let's look over it. You're including some header files here for the ESP8266 and Arduino or defining serial so we can troubleshoot it through serial connection. Then we're going to enable the ESP8266 Wi-Fi multi. That's just in the default example. This allows you to specify multiple access points. So I'm only using one but you can make a list of them and it will check for each one and connect to whichever one it finds first. Here you would define, you type in the name of your access point, name of your wireless router and then the password for your wireless router there. Then here you put the URLs for the two different URLs that you want to hit up. And then here are your delays. So we got delay of one second which really never gets used because it gets over written by D2 and D3. This one is 300,000 milliseconds so that is our five minutes. This one is one minute and then we're saying connection number zero. I'll explain that in a moment. Next our setup basically we're setting up mostly serial port stuff here. All serial port stuff here so that again you can troubleshoot if it's not connected to your Wi-Fi. You can see what's going on through USB serial connection. And then here it's going to output to the serial display. It's going to tell you it's waiting to connect. It's trying to connect, trying to connect, trying to connect. And then it's delaying one second. It's going to print a little dot each time. And here is where it's going to try to access to your access point with its password that we defined up above. Very basic stuff that if you work with the ESP8266 at all you've done that. It's in basically every example in some form or another. Then we've got our main loop here. Okay. So what main loop is going to do is it's going to loop and it's going to try to connect. It's going to check are we connected? If we are connected it's going to do something. If we are not connected, oh see I realized I should have changed this to D. Doesn't really matter. If we are not connected it's going to wait one second which again I set a variable for that up here and I should have changed this. Let's do it now. D. There we go. Okay. So it checks. If you're not connected it waits one second and checks again. It does that over and over again until it shows that you're connected to some wireless access point. Then we're enabling HTTP client and calling it HTTP. We're printing something to the serial port letting you know that it's trying to connect to a web server. Then we've got check. Is the connection equal to zero? Which it is the first time around right here. And then if it is well we're going to add one to itself so it's going to be something higher than zero. So next time around it won't run this function anymore or this option here it will run this. And so again if it's the first time that it's connected this round it will try an HTTP request and change your delay to delay one which in this case was the five minutes. Then it's going to print output to serial port. It's going to get your HTTP code whether it was successful 404. You know 404 not found. If the code is greater than zero well then we're going to print that to the serial port. And if the HTTP code is okay we're going to grab the string and print that to serial port. So actually like half our code here is just troubleshooting for you know sending stuff to the serial connection which again is in the default code. If I wrote this from scratch I probably wouldn't put all that in there but it's from the default code so I just left it in there it's a good way to troubleshoot. But for the actual functionality of this we can get rid of half you know all the serial code stuff. Serial port stuff. Anyway and then we'll and then we'll delay D which D will change to either D1 or D2. So what does this mean? Again let me explain what's happening here. The ESP8266 this one or this one turns on tries to connect to a wireless access point. Keeps checking in I connected and I connected once it's connected it's going to continue with its its loop. And if it's the first time that it's gone through this loop successfully connected to Wi-Fi it's going to connect to one URL. Then it's going to change its delay from one second to five minutes in this case. And from there it is going to then do a second HTTP request and it's going to do that request and then it's going to change the delay from five minutes to one minute and it's going to continue to loop doing that second URL one minute at a time. So let's real quick look over the code real briefly again. We got our include our headers saying up serial port connecting our saying up so we can connect to Wi-Fi saying our AP or access point and its password what URLs we want to connect to and then our delays the initial delay is one second once it successfully connects to the first URL it's going to set the delay to five minutes which is the 300,000 milliseconds then it's going to continue a loop a second time and this time it's going to reset the delay to one minute. And so the first time around it's going to do this every time after the first connection it's going to do this second URL which again you want to replace these with URLs you want to connect to a lot of serial port stuff actually connecting to the access point and this is the loop that here it checks is this the first time we're connecting if so add one to it so that we know that we've already connected once and do that first URL change your delay second time around which would be five minutes later you know connect to the second URL and then reset your delay one minute and it's going to keep looping like that over and over again and the rest of the magic is done on the server side just if those connections are successful so there's URLs the script on the other side so this actually doesn't submit any information to the URLs in this case you could make it do something but right right really what I'm looking for is a timestamp that is logged when a URL is hit which I'm dumping to a file and then also if the second URL is hit log that as well but also send a text message so let me show you why I created this okay so let me show you what this project is for I'm gonna take the ESP that we just programmed and we're gonna go outside so come with me okay kids working on school say hi Amber okay so I'm gonna go outside and I'm gonna put the ESP down in my garage real quick so this is something they're gonna work on today but let me explain the issue and the solution and why I'm doing this today okay so I live out in the sticks so I have well water so this is my aerator tank so let me explain the situation so all the way over here go this way I have an in-ground pump so that goes down into my well it goes through that pipe under the ground all the way back over here to where my air raider is now I just realized I forgot my little camera stand so it comes up through this pipe and goes up into the tank here okay so actually I take that back it actually comes in through this little tube into that pipe anyway let me explain this to you why I'm doing this let me let me get my camera stand while I'm talking to you about this so two or three months ago I had no water and I fixed this thing a number of times myself but what I thought I had was a bad well pump actually as I'm walking by in the garage here here is my old well pump okay if you look at it right here oh this is heavy there's a big crack on it so what happened was I had a bladder valve which I'll show you in a minute I just want to get my camera stand so I don't have to hold this the entire time let's see okay got the camera stand now let's go okay so I just wasted your time for two minutes okay so little wooden cameras actually phone stand that I made just out of a piece of wood but it will help me prop this phone up so if you guys aren't familiar with well systems which living out here for seven years fixing it all the time you learn a lot so I guess I'll use the camera stand since I brought it out maybe I'll hold it for this part okay so anyway water comes from the pump over there the ground underground into this tank sprays it let me take the lid off this so and here we have these little sprinkler heads that spray down into here and fill this up when the water gets low the way that's controlled is by a little dip switch in here it's a this right here so if you can see that when it's tilted up it turns the pump off when it's tilted down turns it on I'll talk more about that in a moment over here I promise there's a the ESP is going to come in to play here in a moment we have this bladder valve so in here there's a bunch of air at the top and a valve at like a bladder that moves up and down so that the pump doesn't have to run all time this pressurizes the house while the pump in here there is a pump inside this tank as well as well and the well okay this down here and line you up okay so here's the issue I used to have a bladder valve over here which was not necessary all that supplied was the hose spigot over by the pump there really the people normally you have a bladder valve before the tank to power sprinklers I don't have sprinklers what happened was that bladder valve went bad the bladder and it got a hole and the whole thing filled with water so what that caused was for my pump underground to run constantly which can burn up the motor itself the pump but in my case I don't even know if the pump still works it wiggled off the the screws the threads fell and cracked the threads that's what that that crack was we just looked at needless to say that's expensive those pumps are easily $700 if not more plus paying someone to come and fix it so at the time I was like okay how can I prevent this so this right here is a pressure gauge when the pressure is low it would turn on the pump when the pressure was high it would turn it off again and would fill that bladder valve now since we removed the bladder valve because that would have been next $200 that I didn't need what we ended up doing was using the dip switch which used to control this little valve here which would allow the water in because the bladder valve would have pressure so we got rid of this which is nice because these die every year to and they're like 12 bucks but it's paying the butt when they die if you don't have one on hand so now when that float inside this tank gets low what it's going to do is turn on the pump directly so there's no bladder valve so last time the since the bladder valve went bad it ran all the time and fell off well this morning my wife woke me up because it was running and running running seems like our little float valve is going bad I couldn't get turn off I shook a whole bunch you can feel the little switch inside there rattle around and it started working again by assume it's not going to last much longer so I ordered a new one off of Amazon was gonna take two or three days to get here hopefully for now it's it's gonna work though but we don't want that pump running because if it runs until it burns out or falls off again again that's close to a thousand dollars to replace so last time this happened with the bladder valve problem I decided to that I was going to hook up an ESP that will alert me when it's been running for more than five minutes and that's exactly what I just did so in the example I shortened the time but in the final example it I created the ESP I programmed it so it cooks to my Wi-Fi which hopefully I get a signal out here I should sends a signal to a log so that way I can track when this pump is turning on and off I can see how often it does it but if it runs for more than five minutes because it shouldn't run for more than a minute maybe two I haven't actually timed it but it's not very long just to flip the top of this tank again if it runs for longer than that it hits another URL which is going to send me a text message so now I just have to wire the ESP a 266 into this little junction box here which used to be a pressure switch still technically is but isn't actually measuring any pressure so let's go ahead and unplug it so I don't let you get myself and again if I haven't already said don't try this at home I'm not a professional when it comes to high voltage and whenever you mess with high voltage make sure you know what you're doing so you don't electrocute yourself I'm not telling you to do this I'm just showing you what I'm doing so I'm gonna unplug the pump and going to unscrew a little top here before with the Sun behind me I was probably a silhouette but here we go we got this I'm gonna lift this off and we got three wires here and all wire nut it off and they're hooked to things so I need to figure out which two of these sends out the power which should be about 240 volts when when the pump is on once I determine that I can hope the ESP 8266 up in it I know ESP 8266 doesn't run at 240 volts I've got a solution for that so come with me and actually I left that solution inside I think or is it a micro hush where did I leave that okay here it is right here so I have this let's turn on the light so you can see it so what this does or it's supposed to do is take that high voltage and confer it down to five volts this was a couple of dollars I hope that it works and doesn't burn down my house so again I left my camera stand outside but what I need to do is I need to solder this to the ESP 8266 and then I need to connect the other side to the high voltage so while I am testing things outside let me plug in my soldering iron I'm like love love my my workbench here it's great isn't it okay plug that in so that can start heating up and what I'm gonna do is I'm gonna take this multimeter and go check the power outside so let's go do that these streams are fun I prefer to edit this stuff it's I don't bore you but I thought this would be a good thing time killer since we're trying to go all day streaming here again we're gonna check it is currently unplugged the wires over there okay let me grab my little camera stand here line this camera up okay so what I'm going to do is I'm going to set my multimeter mine to 500 there because again that should be over 200 volts and I'm just going to kind of guess I'll try this one this one and get that up in there okay that should be good enough so I'm gonna plug it in okay it's plugged in and I'm actually getting 400 volts so I don't that's not the right one so let's unplug that okay let's try this one and this one and plug it in again I shouldn't see voltage so I flip that dip switch okay so we're not getting any voltage right now so let me go ahead and push this dip switch down see it should have turned on the second I push down I had to shake it and that's the problem so here now you're seeing 400 that doesn't sound right should be to something that's odd but I'm getting a voltage reading so those are two wires I need to hook up I don't know why it's giving up that much voltage though okay let's go ahead and unplug that let me see something let me get another multimeter I do have another one I'm pretty sure I had the settings right on that I only have one of these power converters so I want to make sure let's try this little cheapo one see if I get the same little reading on there because we should be seeing something over 200 not in the almost 500 range which maybe I'm finding more problem this adjusts to the brightness I go like this well I'm a little washed out right now oh and it's getting worse okay anyway let's go ahead it's unplugged again right there so me that one that one I think that's in there good turn on the multimeter okay yeah I don't know what's different on the other multimeter but I am getting 240 some odd volts right here so I should mark those so that I hook up the right ones or just remember because it's I'm gonna do it in a moment I'll leave those in there I will unplug it again and let's go solder that solder and iron should be heated up by now I wish my camera would adjust to the lighting properly okay and again I forgot my camera stand let's see sorry for the lighting issue okay I got my ESP a 266 space here okay got this here we go wet my little sponge I'll be back in a moment okay I'm back thank you for being patient so again this whole thing is just an alert system you'll log when that pump goes on and off and alert me if it runs more for more than five minutes here's ESP a 266 now I just have to remember oh it's behind the camera right here so the red side should take in the higher voltage and then the output should come to here which I should be able to solder to the ground and 5 volts down here at the end of the ESP a 266 so I'll solder this here the other side I'm gonna wire nut onto I have some wire here to extend it so it's not just hanging right off the the wire there it's will be out of the way and where are my helping hands again I hope this isn't boring you guys too much trying to do this streaming thing unedited what I do is try to get the solder make sure I got the right yep now I'm a horrible solderer so we'll see how long this takes for me to get right there we go we got some solder on there five volts the first one yep so there's one whoops and my helping hand just fell off its little arm slide that back on hot soldering iron let's put the soldering iron down so I don't burn myself anymore there we go wire here okay unplug the soldering iron that was simple enough now let's see right here where's my camera it's on the side okay right there not beautiful but functional okay now again I'm going to take this little wire and extend what's on here so I'm going to cut this strip this strip a little bit more than that that off okay let's trip this a little bit coming off the device so go right this one here just give a little bit more for the wire nut to grab on to I actually how did I think about it it's too late because I already soldered it onto here I should have hooked this up and made sure it's really putting out five volts so that doesn't just fry this ESP 266 if it does I'm done with this project for now and I'm out a $3 board so let me get some wire nuts should be somewhere over here okay and we're oh there's the one like where did the wire I just trip go okay so I'm going to twist this on here and twist it on with the wire go and other side again I am not an electrician don't do this at home I just don't much rather have this hooked up and not hopefully not lose another thousand dollar pump okay okay here we go now again right now I'm just gonna hook this up and then probably off-camera I'm going to put this inside some sort of container probably some Tupperware container something hot glue it all so that's not exposed to the weather but for right now it's a sunny day there shouldn't be any raining and I just want to get hooked up because I'm in mean to do this for months and after today's morning little fiasco of our pump having problems I just want to get this done so let's go do this I stripped the other end there oh I only stripped one of the two on the other end okay hold on okay bring my camera stand let's get going let's see is it going to adjust when I walk out into the light here not really want to be like that I'll just be a white glow and that's bad okay it's still unplugged right right here so we know that we're good looking at this one and that one and this side doesn't matter whether I hook it up to positive or negative so I will just take out that and screw that back on a little tug it seems secure pull out this other side take the wire nut off and put the wire nut back on give the wire a little tug that's loose let's put it back in a little better this on here okay that seems a little more secure now for the moment of truth I should be able to plug this in and check my server and see if it gets a signal maybe I'll see here a pop and my ESP will be fried we're gonna plug this in the water turned on I didn't have any lights on my ESP 8266 program to go on I should have set it to light up when it sends a signal I suppose I could hook up the multimeter now and see if I'm getting voltage through there oh there was a blue light and I am getting voltage there's a blue light just coming on when I touch the multimeter to it though oh then it's off and I'm not getting any voltage now so best thing for me to do now is go inside and check if I am getting a signal to my service because hopefully again I don't even know if I'm getting a Wi-Fi signal out here I know I do in my backyard but there's a few more walls between here my backyard is just going out the back door just lying a site almost from my router let's go ahead and check this out and going inside I'll be able to reset my camera well hey sweetie and now it's super dark because the camera is not adjusting okay put this right here and switch back over to the computer okay so I have a command that's going to pull the last log and tell me how long since last time the pump ran so pump was on two minutes 23 seconds ago so I think we were successful awesome so let's see oh look you know restarting the camera got to fix its exposure so I hope that you understood what I was doing so again all that that that ESP is doing is when it's powered on it connects to my local Wi-Fi and immediately once it's connected which should take a couple of seconds it will request a do an HTTP request to my films by Chris server in this example in this case with a security key and through HTTPS and all this is if they request a successful the server logs to a file a time stamp then it waits for five minutes if the power is still on in five minutes it does a HTTP request to a separate second URL on the same server and it will send me an alert through a text message so someone's probably gonna ask how do you get the ESP a 266 to send a text message it doesn't it's doing HTTP request and my web server is sending a text message basically through email because you can email text messages which is something I've mentioned before just Google it or I'll probably maybe I'll talk about later today but you can basically send an email to any cell phone that you know the phone number and the provider you send it to an email address based on that and it comes through as a text so that's what my server does and it takes five to ten seconds usually for a text to come through that way but if the pump if the powers on for five minutes or more I'm gonna get one of those and then it's going to continue looping and in this case every minute after that it's going to send an alert letting me know that pump is running it's still running it's still running if it never reaches the five minute mark which it shouldn't all I have is a log but I'm collecting the log so I know how often it turns on and off because I am kind of curious and you know data is knowledge and knowledge is power so the more I know about how that turns on and off when it turns on and off I can do you know diagrams charts and I can just learn a little bit more about how often that pump runs and how much often turns on and off when I'm home when I'm not home is it turning on when no one's home because it shouldn't if if no one's home and the pump starts running there is probably water leaks somewhere so that's good to know so yeah so I hope that was I know again the camera angles aren't the best in this example I prefer editing and stuff like that but again for a stream like this I thought that that would be a good thing to go over something I've been planning to do for a while I'm glad I finally sat down and did I do a stuff to go out there later on and close that weather proof it which I'm just for now probably just again gonna cut a hole on top of a container put in there tape it shut and super glue gun about around the wires and stuff like that but yeah so that's what I've set up so let's see what are we going to work on now