We generally want to connect to WiFi as soon as our module starts up, so let’s replace setup()
with the following code:
Note: Don’t forget to substitute <your wifi access point name>
and <your wifi access point password>
with your actual WiFi network name and password otherwise this won’t work.
Before we proceed, make sure your code looks like this except with the right values for the following substituted in:
<your wifi access point name>
<your wifi access point password>
If your ESP8266 is successfully connected to a wifi network, it should automatically be assigned an IP address by the router.
This IP address is what the router (and other devices on your local network / wifi) can use to communicate with your module.
delay(5000);
right before the IP address is printedNote: Pretty much every device which is connected to the internet or to a local network has an IP address, and they communicate with each other by sending “packets” of data which include the destination IP address, source IP address, and any content.
One of the simplest protocols in networking is ICMP Echo request and response, more commonly known as “ping”. If you know a target device’s IP address, you can “ping” it to check if it’s online and working.
ping <your module IP address>
and look for a replyNote: Most devices connected to a network, including your ESP8266 module, will respond to ping requests.
From a networking point of view, your ESP8266 module is the same as your desktop or laptop or phone or any other device connected to the internet. The basic concept behind “Internet of Things” is taking the same networking protocols and infrastructure which allow your computing devices to communicate over the internet, and reusing it to let your microcontrollers and embedded modules communicate over the internet.
If you want a deep understanding of how the internet works, learn about the basic protocols behind it: