ESP8266 with Arduino 5 – Connecting to WiFi
Sometimes you found include carrot but b 82 66 y capital, w capital f, i dot h tag and then in our code we need to do a couple things. The first thing were going to need is were going to need to new variables, were in a variable called um, a const r pointer dont worry about what that those words mean its just. What the same requires called ssid. This is going to be the access point in this case, where you, a r sd underscore g. U e s t when youre bringing this home youre going to want to change that to your homes, wi fi, or also your constant car array password, which in this case is going to use empty, quotes. Youll put your password in there, but theres no password for the krds sd guest network, so well. Leave that as it is now were going to go down to do scroll down to the section of code where i have it again: ive memorized this im. Looking at all the stuff that ive written before so in our setup, we are going to remove on these initial pieces and im going to move these two sections right under the display in it. Well, now we have a display in it. We have the pin stuff. The last thing were going to do is were going to add a new or do a wi fi again comma password. Now this will not happen instantaneously.
There can be some time um. I typically want to display something on the screen to show me whats happening, and what i found worked pretty well is i just have it go between going switch between connecting to and wi fi, so its connecting to wi fi, connecting to wi fi connecting to wi Fi first im going to bring my font size up to 16 because i know its a valid font size because i did some googling and now were going to do is create a new variable called boolean called toggle thats, going to be equal to false. Now were going to check to see while were trying to so, while by status, not equal to wl underscore connected. Basically, while were not connected, were going to take and display two messages. So first were going to see, if were in toggle, so if its, if toggles already fired off once, were going to display clear and were going to display, draw underscore comma y so in the middle of the screen, because we already have that saved earlier um. Well, actually, use lets do 32, so keep that corrected connecting then display display and were also going to take and before we do that we can actually turn off progress or toggle equals false actually actually make this true well start on the true level and then well Go back so now. The else statement for this is were going to steal all the code for ourselves because im lazy, ctrl c, except where i make the toggle true.
So if toggle is true, which it is its going to do, this toggle is now false. Its going to clear right connecting display and then go through loop and check again now toggle is false. So now its going to go and set toggle true its going to clear to say, instead of connecting it say to wi fi in fact, lets make this episode. Two were gon na, say two um lets make this connecting to, and here were going to just put the ssid. Oh, oh, it says what network trying to hit so its going to be connecting to the ssd connecting to ssid and now after weve done that were going to wait a second and check again and now this should loop back and forth and when its finished were Then going to set the font back to um a reasonable subject back to 10., and then our other program will run so lets upload again ill pause, while it uploads, because you dont need to see green bars and of course, i mistyped wi fi, its capital, w Capital f so again, im going to upload and pause, and this time ive started the video a little bit while its uploading, so that you can see as soon as it uploads what happens. Ninety percent hundred percent restarting connecting to guest connecting to guest that fonts a little big. So maybe we can make this instead of 16 lets, try 14 upload and again im going to pause it well, so ive realized, so 14 is not a valid font.
I actually want to do so. 10 and 16 is the next one so well go believe it. I guess 16, but well move the font up a hair for 2.4, and i forgot to actually do something once you connect so before i upload again lets add one more thing, which is we want to display at the smaller font. The location also is going to change yourself to left justified, so im going to copy that line and then center were going to do left and then were going to do um a clear and then im going to display dot draw string at zero, comma, zero thats. The top left hand corner um two and then the next line well put the i the name, zero, comma ten and then lets on the third line well display our ip address, which is going to be important later. This way draw string 0, comma, 20., comma anyway. You get that its gon na be wi, fi, dot, local ip to string c underscore str. Basically, we want to be in the right format. For the thing, this is the magic line, change this ip address data to a standard string and its a c string so that it can talk too. So we are going to take and re upload, oh and before i upload were going to make sure we do. The most important thing lets play uploading them across the video again cause. You dont need to see that again, ive typed wi fi wrong.
Every time as before i start the video back up, so we can see it go if you have trouble with uploading. Try to unplug things and restart the device by hitting the switch. Now we can see says connecting two heres, the yes connecting to krc guest, and this will blink back and forth until it gets connection which could take up to um 30 seconds or so at most and there we go. We are connected. We have an ip address and we can start doing stuff with the web server from here. Of course, if i press the button well go back to our other program now they are left justified. If i want to change the alignment in my code, i would take and then bring my after. I did this before. I start my program ill bring it back to center. If i want to not going to bother uploading again from here, well start building the more complete portion believe it or not, of creating the web page. So we can actually access stuff on here.