Placeholder Image

字幕列表 影片播放

  • 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 in the past, people have asked me what the difference between Arduino and Raspberry Pi is.

  • And I've said that artery knows they're good for doing things like creating a sensors or being able to trigger physical events.

  • But if you're gonna do something like Renee, a Web server, then you should really use a raspberry pi.

  • And of course, as things go in the technology world, you actually can't kinda sorta can do a Web server off guard.

  • We know.

  • So today I'm going to show you using an Internet shield how to run a website off of your do we know.

  • So basically, you have an Internet shield that's connected to your Arduino, and that Ethernet shield has a micro SD card slot on that C.

  • You can put a micro SD in their and essentially read from the micro SD in order to present a website to whoever will be going to the I P address of your Do we know now?

  • I will say what will say more or less, more or less, I still stick.

  • By my previous opinion, I'm gonna be running a Web server.

  • Uh, at least I would want is a raspberry pi.

  • But, you know, for some reason there might be a reason that you would want to use an Arduino in order to deliver a website from from simple, simple things, such as it's harder to hack something like an Arduino.

  • Since an artery no doesn't have a full fledged operating system, since it doesn't have my speak wheeler PHP or any of that kind of stuff.

  • It's not necessarily as large oven attack risk as something like a raspberry pi might be.

  • But on the other hand, you know you can only do what you could do with this.

  • So basically, when you're using an Internet shield in order to deliver a Web Page two clients, what this will allow you to do is it allow you to send any type of Web page type stuff that would be client side interpreted.

  • So what I mean by that is a t m l right.

  • So it sends the HTML text, and then your Web browser turns that HTML into a website JavaScript Java script is a client side scripting language.

  • So it sends the text to your client and then your client parses what to do with it.

  • So you could again.

  • Obviously, you can use HTML.

  • You can use CSS.

  • You can use JavaScript, those type of languages using are we know if you really want Thio.

  • But do you realize any kind of server side scripting language is we're talking about python PHP, ruby.

  • Any of that type of thing?

  • Uh, you shouldn't try to run off on.

  • Aren't we know again?

  • That is, that is one of those at least a raspberry pi.

  • So why don't I show you how to do today is we're going to use a We're going to create a simple text website.

  • So this will be an HTML website, and on that I will embed an image from fail normal dot com and I will also embed a video from YouTube s O that shows you how to basically do a simple website and be ableto embed assets from other Web properties.

  • Whether it's YouTube, whether it's like anger or website, something like that.

  • Now you can to be clear.

  • You actually can host host pictures and such on the micro SD and be able to present them on a website.

  • But that gets a little bit convoluted, and I think it gets to be a little bit complicated.

  • So for this this particular video, all we're going to be doing is a simple text website where all of the assets are hosted.

  • Somewhere else again, YouTube or fail normal dot com something like that.

  • So with that, let's go over to the work bench so I can show you how to assemble this little project and then I'll show you the code that's involved and then bring it all together.

  • So for this project, we're easy in our standard Arduino, you know, bored like we use for most projects.

  • And we're actually using the standard Ethernet shield from Arduino itself.

  • So this is the Internet shield on purpose from Artemis no dot cc.

  • Now, as with many of these different products, there are clone boards out there.

  • So this is a sane, smart board, and as you can see, there's a little bit of difference between the two.

  • So if you're going to do something like try to build a little Web server like I am just realized if your deal dealing with a different Internet shield, you may run into some some different issues that you have to deal with.

  • So the shield that I am using is the actual reference model that comes from hard.

  • We know.

  • So what we do here is we just, uh, wine all this up.

  • Slot these together, and then that's that's our little package.

  • So this is our little Web server.

  • Then we've got a micro SD, so I got the micro SD.

  • We simply slot that into the back, and there we go.

  • This is going to be our little are doing a Web server for the project, so let's go over and take a look at the code.

  • So before we take a look at the Arduino sketch, let's take a look at the Micro SD card and the HTML file that we're going to be saving there.

  • So the first thing to realize is that the Internet Shield is not able to read the NT F s file system, the AP F s file system or even the X fat file system.

  • It can only read the fat file system so fat 16 or fat 32.

  • Now, if you're using a micro SD card that you you've put into any kind of modern camera or camcorder, it will most likely have formatted your micro SD card to X fat so you can put the index dot HTM HTM file onto an X factor micro SD card.

  • But the Internet shield will simply not be able to read any of that.

  • The first thing you need to dio is if you're using Mac, we're gonna go to the disk utility.

  • If you're using Windows or Lennox, you would do diversion over there.

  • And basically, we're What we're gonna do is we're gonna go down Disk utility.

  • Open this up.

  • We're gonna take a look at the file system for untitled so we can see untitled, and we can see this is m s dot fat 32.

  • So that is what we want.

  • This says something else especially says X fat, which is what most likely say.

  • All you would do is you would format or if you're on Mac, you erase, and then you make sure that you make the M s dos fat file system the one that you select.

  • So again, this is one does that that could be very difficult.

  • Like, Oh, it has X fat.

  • Let me just go through here and you're fat.

  • Finger it or you go through too quickly.

  • You'll put the Mac OS extended or whatever journal file system onto the micro SD card, and then the Arduino still simply won't be able to read it.

  • So one way or the other, you do have to form at the micro SD card for fact, then past that we can go and we can take a look at the code that is on the I hate to say code or you let us a code tags came out.

  • Let's take a look at the HTML.

  • That's only the index s We're gonna call this index dot HTM And so we're actually going to reference this name within the Arduino scare a script sketch.

  • So if you change us to a different name, then we just have to change that name in the sketch.

  • Let's take a look at this.

  • And as you can see right here where I'm just using crappy old standard html p strong, strong is bold.

  • Hey, look, a webpage.

  • Surfer Menard.

  • We know close, strong, close P.

  • Here's a list open on our list.

  • First less diadem Second list died on third list.

  • Item close, close, close and then close on order list.

  • Then we use 82 Here's a picture embedded from the Web.

  • Close age, too.

  • Again, I'm using the image SRC tag on grabbing.

  • I just grabbed a random ass picture off of fail normal dot com, and we go down below.

  • That ate, too.

  • Here's an impediment.

  • Embedded video.

  • And with this I simply used the I frame, thigh frame in bed script that you could grab from YouTube video.

  • And so this is what we're going be presenting as the website.

  • Yes, it's ugly.

  • Yes, it's nasty.

  • Yes, it looks like I'm just trying to explain to you how this stuff works.

  • If you want to make something look nicer, you go ahead and do something.

  • Make something look nicer.

  • I just want to show you that this is going to be able to deliver this HTML code.

  • An important thing to when you're dealing with Arduino is you'll notice that this is just the stock standard html code.

  • So we've done projects in the past where the Arduino has dynamically written HTML for us and with that, you have to use escapes and you have to format things properly so that the article, you know can actually deliver it.

  • The nice thing about being able to read off of micro SD card is you can just simply do this is a cute Now there's no additional escapes.

  • There's no additional weird ass formatting that you have to deal with.

  • The yard we know will simply read from the file and send that over the Web browser so that let's go over and take a look at the art we know code.

  • It's self s.

  • So we have this this code, the first thing we're gonna need to do is add these three libraries with the SP I library the other night library and the SD library.

  • So we need these libraries and work to make this work on.

  • Then we're going to have the Mac address eso again.

  • The Mac address is the unique identify WR for your bueno device on the network.

  • Now, do you realize we're going to projects like this if you only have one?

  • If you only have a single are we know device on your network.

  • You need this Copy and paste this Mac address.

  • Uh, this Mac address doesn't really matter if you only have a single device on the network where you may run into problems.

  • If you have multiple Ethernet Matt Arduino devices on the network, you don't want to just copy and paste this this Mac address because then they'll all be seen as the same device as far as the network is concerned, and you can run into some big problems.

  • So basically, Mac addresses air used in something called AARP address resolution protocol.

  • So address resolution protocol maps I p addresses to mac addresses.

  • So they're supposed to be there, supposed to be globally unique Mac addresses, and then you can assign an i p address to them.

  • So Mac addresses kind like a Social Security number as far as network devices are concerned.

  • So just remember, if you're having multiple of these devices on your network, see what the Mac address is.

  • There should be a sticker on the bottom of your Internet shield on, and then plug in the individual Mac addresses.

  • So anyways, then we're gonna go down we're gonna create the Internet server a reference.

  • So we're gonna call this server and it's gonna be on poor 80 so we can call server and will be poor 80.

  • Then we're going to create the files.

  • They're gonna have a final on that file is going to call Web page.

  • So that's going to be the file that we're going to grabbing from the micro SD card.

  • They were going to go down, and we're going to set up the environment.

  • So the first thing we're gonna do is internet dot Begin.

  • And then this is where we feed the Mac address from up here.

  • Then we're going to do server dot Begin.

  • So this present starts that server service for us and then serial dot began 9600 that starts the serial monitor.

  • And so the zero monitor is going to be important for us, especially in trouble shooting, because the first thing that is going to do is tell us what the hell the I P address is of our Torino device again.

  • Since we're only feeding the Mac address here is going to grab an I P address from the A, C.

  • P and so if we're gonna go to it as a Web page, we need to know what the I P addresses.

  • So cereal, that print line after not internet dot a local i p.

  • So this function returns what the i p addresses and it will print that out on the serial monitor, then here, all of this stuff in here.

  • What this is for is, this is what we're making sure that the SD card is working.

  • So this is one of those things that you could just copy and paste serial dot print line initializing as d card.

  • If not SD began.

  • Four.

  • There's an error success.

  • So else success SD card initialized if not exists.

  • So this is where we're going to be putting in what the name of the HTML file is.

  • So if you're going to change the name HTML found something else.

  • Default dot HTM HTM bob dot HTM Whatever else, this is one of the places you a plug that in.

  • So it's going to look for that if it if it doesn't exist, it's going to print.

  • I can't find the file.

  • If it does exist, it's going to print success.

  • Found the file.

  • Then we're gonna go down, and we're actually gonna take a look at the loop first.

  • Parting this again like most.

  • This stuff is kind of copy and paste with the whole connection to the Internet.

  • Client attorney client client equals servant unavailable If there's a client.

  • Ah, wild client is connected while client is available, which are C client.

  • Read Haba Baba block on dso this here.

  • We're just gonna basically just copy and paste this.

  • This is for the connection where we get to the interesting part.

  • For us today is just this little bit of this a little bit right in here, right?

  • So this is where we actually read from the micro SD card and read the information from micro SD card and point that out to the web browser.

  • So wet.

  • Paige.

  • So we created that file, right?

  • That file variable appear called Web page.

  • So Web page equals s d dot Open.

  • So the s d not open function.

  • We're going open index dot HTM.

  • So, again, this is one of those places where if you change the name of that HTML files, you change that.

  • Here.

  • We're going to open index dot HTM and Web page is going to equal that if Web page.

  • So basically, if webpage exists while what Page is available, but it's kind of interesting.

  • Here is is a curious little function.

  • So client dot right, so client client is the Web browser.

  • So the Web browser that is connected to the yard we know we're going to essentially right to the Web browser Web page dot reed.

  • So what's gonna happen is this function here is going to read the file that's on the micro SD card, and as it's reading it, it's pumping out of what it reads to the to the Web browser.

  • So it's kind of like just the man in the middle, like, Okay, this is what I read.

  • This is what I read this is, whatever this way.

  • And then once it gets finished, Web page dot clothes.

  • And so again, what's nice about this is you notice.

  • As faras, the HTML code is concerned.

  • You don't have any weird, funky stuff with the HTML code.

  • You don't have to escape anything.

  • It is just going to Reed's got a purely read from the file on Spit It Out to the Web browser.

  • Then you're gonna have a break.

  • Then they're gonna have a lot of copy and paste stuff again.

  • You know, if if c equals new line else, if blah, blah, blah delayed one client dot Stop.

  • The main thing in here that you're going to be dealing with worrying about is this part in here and again.

  • You may change that index dot html eso with that, Let me upload the code to the to the yard.

  • We know and put the micro SD card in, and I'll show you how this works.

  • Okay, so here I plugged in the plugged in the Ethernet cable plugged, plugged in the U.

  • S.

  • B cable.

  • So this will give us power and will give us a serial monitor again.

  • Do you remember?

  • If you give this device a static I p address, you don't have to Then plug this into a computer at all.

  • You could simply plug this into a wall outlet or plug this into a USB wall out outlet type thing and have it entirely powered on its own.

  • So just be sitting in a corner and then we have our little micro SD card slotted in up there so that let's go to the computer or tools will go to serial monarch will see what this gives us.

  • Okay, so we have our i p address.

  • 0 10.1 not 14 way the initializing SD card success in success s.

  • So this is a good way to make sure that the SD card is actually being seen and then that the file is found.

  • If you're having any problems, so then we're going to do is run, do it, see?

  • And they were going to go to Google Chrome, and we're going to open this up and wow, they're cool.

  • So basically, this is a webpage that is being presented entirely from our hard We know, right?

  • So, hey, you look a webpage served for Menard.

  • We know here's a list of Ceres that list.

  • Here's a picture and better from the web.

  • So this is the picture that's embedded from Phil normal dot com.

  • Here's an embedded video, and so we have a little embedded video from YouTube.

  • And so that's the basic than you have now.

  • I know it's ugly, it's ugly.

  • But the point that I'm trying t o give you is that this can be done.

  • If you wanna make something that looks nice, you can plug in your CSS and do all the pretty stuff.

  • Format it.

  • But this just shows you that this does in fact work and is being presented from from a simple aren't we know.

  • So that's That's basically what there is to making a little Web server using your Arduino.

  • So now you know how to turn your Arduino into a teeny, tiny little Web server.

  • It's one of those things.

  • Would I do it in the real world?

  • It depends.

  • It depends, right?

  • So if I only had a couple of different clients that would be communicating with this, maybe that would make a little sense.

  • Things like digital displays, that type of thing.

  • Maybe I would do that if I had a very, very simple projects.

  • Maybe I would do that if I had Security concerns were again.

  • I had a simple project, and I wanted something that couldn't be hacked the way a raspberry pi could.

  • Then I might do that.

  • But generally, generally, this is just kind of one of those you know, Neat dog tricks need Arduino tricks.

  • Now go use a real computer to do it better, because the important thing to understand here is again.

  • You can't use any client side server languages, PHP room, beginning that kind of thing.

  • You can't use anything like databases.

  • My sequel database Maria idea be anything like that.

  • Essentially, you can use this to present html CSS Java script, that type of deal on and that's about it.

  • You can you can present images from the micro SD card, but again, that gets a little bit more convoluted.

  • Uh, then, yeah, you probably better off with a raspberry pi.

  • One of things that will say with that Mac address is if you buy the standard again, the actual Internet shield from our do we know there is a sticker on the back, and the sticker on the back gives you the Mac address for this specific device s O.

  • If you're wondering what the Mac address should be, if you buy the reference Ethernet shield, there should be a sticker on the back to tell you what it is and so on.

  • And so, yeah, that's really all there is.

  • Do it again.

  • The one of the big things to be careful about is make sure that your micro SD card is formatted fat, not x fat but fat.

  • If it's warm as extract, it simply will not be seen on.

  • Otherwise, it's going well.

  • Interesting thing that the play around with again, you can try to see how sophisticated you could make it website using one of these views things like eye frames, other things, maybe multiple files.

  • I think you might be surprised about how complex a sight you can create is just gonna take a lot of energy and love it.

  • There's there's a lot better ways to do it, but, you know, Hey, if you want to create a Web server using an ordinary no, at least now you know how to do it.

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.

字幕與單字

單字即點即查 點擊單字可以查詢單字解釋

B1 中級

簡單的網絡服務器與Arduino以太網盾牌。 (Simple Web Server with Arduino Ethernet Shield)

  • 11 0
    林宜悉 發佈於 2021 年 01 月 14 日
影片單字