1 00:00:02,320 --> 00:00:08,440 Now that we are done with the first part of our code, let's move on and create a method so that we 2 00:00:08,440 --> 00:00:17,530 can connect to Wi-Fi networks easily listening and void who set up wi fi. 3 00:00:22,910 --> 00:00:23,450 Now, 4 00:00:26,210 --> 00:00:37,190 inside this method to add a delay of twenty milliseconds and serial, the prompt new line. 5 00:00:40,520 --> 00:00:46,120 Let's bring something to tell you, though, that we are connecting to Wi-Fi from the remnants of. 6 00:00:59,860 --> 00:01:01,390 OK, now. 7 00:01:03,040 --> 00:01:03,640 That's right. 8 00:01:03,710 --> 00:01:04,880 The name of the wi fi. 9 00:01:09,920 --> 00:01:24,460 Right is a side after that wi fi dot begin to start connecting to this wi fi, is this I.D. and password. 10 00:01:24,980 --> 00:01:32,600 So it will take the Wi-Fi as ID and password and will try to connect. 11 00:01:33,500 --> 00:01:41,140 Now, we can't otherwise statement if Wi-Fi 12 00:01:44,060 --> 00:01:45,020 the status. 13 00:01:48,090 --> 00:01:49,920 It's not connected 14 00:01:54,260 --> 00:01:59,790 then we need it to delay and try again. 15 00:02:09,130 --> 00:02:16,240 And while it's trying to connect, we need to bring Dot K now. 16 00:02:18,720 --> 00:02:24,210 After this, after the wall, that wall keeps trying, we'll keep trying. 17 00:02:24,240 --> 00:02:27,900 Connecting to the Wi-Fi network we need to add. 18 00:02:29,930 --> 00:02:33,740 Once it's connected, it will keep rolling this until it's connected. 19 00:02:34,250 --> 00:02:41,030 Now, once it's connected, we need to write a serial footprint. 20 00:02:43,550 --> 00:02:47,900 New line now Wi-Fi 21 00:02:51,290 --> 00:02:52,450 is connected. 22 00:02:56,280 --> 00:02:58,590 And we can even print the IP address. 23 00:03:14,310 --> 00:03:19,110 And to print it, we need to call a function called wi fi 24 00:03:21,810 --> 00:03:23,760 dot, local IP. 25 00:03:28,580 --> 00:03:35,420 And this will tell the IP address to which our ISP 32 boards connected and will print it out on the 26 00:03:35,420 --> 00:03:36,100 serial monitor. 27 00:03:36,290 --> 00:03:41,500 Now let's verify the code to make sure that everything is working just fine. 28 00:03:42,660 --> 00:03:43,070 OK. 29 00:03:45,000 --> 00:03:45,680 That's it. 30 00:03:46,200 --> 00:03:48,340 Now, this is the first function. 31 00:03:49,050 --> 00:03:57,990 Now the second function is to reconnect now by void, reconnect. 32 00:04:02,070 --> 00:04:05,240 Now we will loop until we are reconnected. 33 00:04:05,490 --> 00:04:08,310 So we will add our oil statement. 34 00:04:09,360 --> 00:04:15,580 And this is basically a function to make sure that we are connected to the uncute server. 35 00:04:15,750 --> 00:04:18,000 So one 36 00:04:22,980 --> 00:04:26,130 player that connected 37 00:04:28,650 --> 00:04:29,530 is not true. 38 00:04:30,240 --> 00:04:31,290 We need to try. 39 00:04:35,310 --> 00:04:36,090 To reconnect. 40 00:04:37,460 --> 00:04:40,820 So let's try to Brent. 41 00:04:44,790 --> 00:04:55,230 Attempting to reconnect and you take an extra. 42 00:05:00,890 --> 00:05:04,780 OK, now the next line will be on. 43 00:05:08,790 --> 00:05:09,900 The publish 44 00:05:14,580 --> 00:05:19,710 inside, it will write out topic 45 00:05:24,000 --> 00:05:26,640 about how to were. 46 00:05:29,870 --> 00:05:36,770 Now, let's create a random client I.D., strong client I.D.. 47 00:05:39,630 --> 00:05:48,840 Let's call it E.S.P 30 to climb, and you can add anything 48 00:05:51,360 --> 00:05:52,260 after that. 49 00:05:53,820 --> 00:05:57,990 We cannot add client already. 50 00:06:02,510 --> 00:06:05,720 Plus, equal strength. 51 00:06:08,670 --> 00:06:11,970 And so the strength we can add around function. 52 00:06:16,390 --> 00:06:17,250 53 00:06:19,860 --> 00:06:29,040 and for us now, we can make sure that Hicks has the time and this will make sure that each side will 54 00:06:29,040 --> 00:06:34,560 have a new client ID, that is unique because we are getting the value. 55 00:06:35,970 --> 00:06:43,810 And we are adding it to that previous value so we can move this number and each time it will be granted, 56 00:06:43,870 --> 00:06:44,730 it will be this. 57 00:06:46,550 --> 00:06:51,890 Plus, the strength that comes out from this line now. 58 00:06:54,220 --> 00:07:00,730 Let's attempt to connect, right if statement then else. 59 00:07:02,650 --> 00:07:13,600 Let's start with that statement now, inside that statement, we need to ask if a client that cannot 60 00:07:14,140 --> 00:07:22,900 function, which usually takes their client idea to this one, does. 61 00:07:25,480 --> 00:07:32,620 Now we're going to use a function called C String, which basically converts the contents of a string 62 00:07:32,650 --> 00:07:36,880 as a CEO, which is the one that we need for this F statement. 63 00:07:37,570 --> 00:07:52,420 And to use it, we just need to write C, underscore ETR, then we can add INF treaty, use that which 64 00:07:52,420 --> 00:07:59,140 is basically the user name for the server and NQ G.T. password. 65 00:08:08,420 --> 00:08:19,040 OK, last word now, as you can see, uh, it takes the connect function, takes three things the client 66 00:08:19,040 --> 00:08:24,470 ID, the user and the password after that. 67 00:08:25,370 --> 00:08:30,230 If that statement is true, we can can print 68 00:08:32,990 --> 00:08:35,200 the word connected and Barceloneta. 69 00:08:35,630 --> 00:08:37,040 So print newline. 70 00:08:44,210 --> 00:08:52,400 OK, now, once connected, we can publish an announcement by writing client, not publish 71 00:08:56,180 --> 00:08:57,800 inside it, we can write. 72 00:09:00,050 --> 00:09:00,830 I see. 73 00:09:03,760 --> 00:09:04,690 Rhizomes. 74 00:09:08,410 --> 00:09:10,840 And E.S.P, first to. 75 00:09:12,990 --> 00:09:20,700 Now, the announcement will be hello worth. 76 00:09:23,780 --> 00:09:35,000 Now, otherwise, if this condition didn't hit, we need to go to the EL statement and inside it we 77 00:09:35,000 --> 00:09:36,170 need to Roitfeld. 78 00:09:45,290 --> 00:09:58,460 And we can also add another line that says our see equal and leave us space and we will print out the 79 00:09:58,790 --> 00:09:59,780 client state. 80 00:10:00,560 --> 00:10:02,960 So serial, the trend 81 00:10:05,300 --> 00:10:07,250 client, not state. 82 00:10:12,720 --> 00:10:13,230 Now. 83 00:10:14,670 --> 00:10:18,480 Let's make sure that we have everything correct, that client. 84 00:10:22,280 --> 00:10:23,520 The state function. 85 00:10:23,590 --> 00:10:26,900 OK, now try again, five seconds. 86 00:10:39,040 --> 00:10:42,820 And we can add a delay of five or six seconds 87 00:10:46,330 --> 00:10:48,010 to give it time to try again. 88 00:10:48,750 --> 00:10:49,110 OK. 89 00:10:52,580 --> 00:10:59,300 That's it, this is the reconnect function for Van Kutty server. 90 00:10:59,630 --> 00:11:06,190 Now we can have this call at the end, but for now, this is everything that we need. 91 00:11:06,200 --> 00:11:10,580 First, we need to make sure that the client is not connected. 92 00:11:10,970 --> 00:11:17,960 If it's not connected, we need to write that you are attempting to connect and we need to set a client 93 00:11:17,960 --> 00:11:18,510 I.D.. 94 00:11:19,160 --> 00:11:29,270 Now, if we have sent the client already and cutesie user name and password, it will connect if there 95 00:11:29,270 --> 00:11:30,230 is any problem. 96 00:11:30,260 --> 00:11:32,470 There is no Internet connection or any other problem. 97 00:11:32,900 --> 00:11:39,350 It will print failed and it will print the state of this client and will print that. 98 00:11:39,350 --> 00:11:45,920 You should try again in a few seconds and will add a delay to ensure that you are sound after a good 99 00:11:45,920 --> 00:11:47,540 amount of time. 100 00:11:49,490 --> 00:11:57,950 Now, if we didn't verify our code, we would get an OK and all that land, it is not defined because 101 00:11:57,950 --> 00:11:59,360 we have very small. 102 00:12:00,110 --> 00:12:01,400 So let's make it a capital. 103 00:12:05,710 --> 00:12:12,790 OK, Duncan, darling, everything is correct, and the next lesson, we are going to start the set 104 00:12:12,790 --> 00:12:16,330 up and look function coding, but that's it for now. 105 00:12:17,200 --> 00:12:22,930 If you have any questions, please ask in the Q&A about this is Ashar from educational engineering team.