Before we can use the Wi-Fi chip that is on the board, we need an Arduino library to be able to control it. The library for this chip is called the WiFi101
library and you can find it inside the Arduino library manager.
To access the library manager, simply go to Sketch | Include Library | Manage Libraries inside the Arduino IDE. Then, type wifi101
to find the library:
To install the library from there, simply click on the Install button just next to the library version.
Let's now connect the board to your Wi-Fi network. The sketch is quite long here, so I have split it into three parts.
This is the main part of the sketch, which will actually connect your chip to your local Wi-Fi network:
What you actually need to change here are the following lines:
You need to change those lines to put your own Wi-Fi network's name and password. This is something you will have to do in all the sketches for the rest of this book, as we are always going to connect the Arduino board to the local Wi-Fi network.
Then, the following function will print data about your IP address:
And this function will print data about the current Wi-Fi network to which your Arduino board is connected:
It's now time to finally test this sketch and connect your board to the Internet! You can get the whole sketch from the GitHub repository of the following book:
https://github.com/marcoschwartz/iot-arduino-cookbook
Now, make sure to change your Wi-Fi name and password inside the sketch, and then upload the sketch to the board. Immediately open the Serial monitor. This is what you should see:
If you can see something similar, congratulations, your board is now connected to your Wi-Fi network and to the Internet (assuming your Wi-Fi router is connected to the Internet).