Even You Can Create an IoT Device
Have you ever wanted to create an IoT device that you could access from anywhere inside your home WiFi network or even reach from outside of your home network? Well, then you’ve come to the right place my friend.
In this post, I’ll show you how to set up a simple web server on your ESP32. If you ever thought that doing so was too hard, then think again, because it’s actually very simple. So… without any further delay, let’s jump right into it.
What is an ESP32?
Let’s start with the basics. If you don’t even know what I’m talking about or you need a quick refresh on some basic hardware, we’ll start with introducing the ESP32.
The ESP32 is a low cost, low power system on a chip, with built in WiFi and integrated dual-mode bluetooth capabilities, created by Espressif Systems. The chip comes in different shapes and sizes, as many companies have adopted the ESP32 into their development chips, so that getting started with your IoT project is quick and easy. No soldering required when using micro controllers with an integrated ESP32. Isn’t that great? 👍
The micro controller that I have been using for my recent word clock project, which you can read more about here, is the Arduino MKR1010 WIFI, which you can pick up for about 30€, either on Amazon or directly from the Arduino store.
With that basic introduction to the ESP32, we can begin our basic IoT project.
Where do I Start?
Once you have your MKR1010, you can start by opening a new sketch in the Arduino IDE. You’ll want to download the correct board to for the MKR1010, which you can do by opening the Boards Manager in the IDE. In the search, type Arduino SAMD Boards. Press “Install” and the IDE will install the necessary boards, one of which will be the MKR1010. Once installed, you can select the MKR1010 and start developing your IoT project with it.
How do I connect the chip to my local WIFI?
We’ll need a library in order to get our chip connected to the local WIFI.
The library that we need is called “WiFiNINA”. Go ahead and install it through the library manager in the Arduino IDE.
Finished? Then we need three lines of code in the setup function of our sketch. The first two lines will be definitions for which WIFI network to connect to. Required are the SSID, the WIFI name, and the password for the network itself.
It’s that simple. If you also want to see the status of the connection of your WIFI connection, you can simply use the following function to see whether the chip is connected and also the IP address of the chip.
Don’t forget to start the serial monitor on a specific baud rate, so that you can see the connection status in the serial monitor.
What if I want to open my own WIFI network?
This is just as simple as connecting to a WIFI network. Instead of using the WiFi.begin function, use the WiFi.beginAP(ssid, password) to start your own network through the chip.
Now that you know how to connect to your local WIFI network and also create an access point on your ESP32 chip, you can get started with the real functionality for your IoT project.