If you think about future technologies then the two names, which immediately comes in your mind, are Artificial Intelligence (AI) and Internet of Things (IoT). AI is still in its initial stage and there is lot more to be developed. But IoT is in Growth stage and lot of IoT based products are already there in the market. Also there are many tools and hardware available in the market to make your product talking with ‘things’ in the internet. Among them ESP8266 is the most popular, cheap and easy-to-use module, which can connect your hardware to the Internet.

Components Required

Blue Pill STM32F103C8 board

ESP8266 Wi-Fi module

Laptop & Wi-Fi hotspot

ESP8266 Wi-Fi Module

Most people call ESP8266 as a WIFI module, but it is actually a microcontroller. ESP8266 is the name of the microcontroller developed by Espressif Systems which is a company based out of shanghai. This microcontroller has the ability to perform WIFI related activities hence it is widely used as a WIFI module.

GND, Ground (0 V)

TX, Transmit data bit X

GPIO 2, General-purpose input/output No. 2

CH_PD, Chip power-down

GPIO 0, General-purpose input/output No. 0

RST, Reset

RX, Receive data bit X

VCC, Voltage (+3.3 V)

AT command is used for communicating with ESP8266. The table below shows some of useful AT commands

AT COMMANDS

USE

AT

Acknowledgement returns ‘OK’

AT+RST

RESTART module

AT+GMR

Shows FIRMWARE DETAILS

AT+CWMODE=1 or 2 or 3

Wi-Fi mode 1-Station, 2- AP ,3-Both

AT+CWLAP

List the AP

AT+CWJAP=”SSID”,”PASSWORD”

Joins AP

AT+CWQAP

Quits AP

AT+CIFSR

Gets IP address

AT+CIPMUX= 0 or 1

Set multiple connection 0- Single ,1-multiple

AT+CIPSTART

AT+CIPSTART=<type>,<address>,<port>

AT+CIPSTART=<id>,<type>,<address>,<port>

Setup up TCP/UDP connection

Address- Ip address

Port-port address of ip

Single Connection :Type-TCP, UDP

Multiple Connection: Id-0 to 4,Type-TCP,UDP

AT+CIPSEND

AT+CIPSEND=<length>

AT+CIPSEND=<id>,<length>

Sends data

Single Connection , Length - Length of data

Multiple connection , Id =0 to 4

AT+CIPSTATUS

Gets the connection status

AT+CIPSERVER=<mode>,<port>

Set as Server 0-Server close, 1-Open port

AT+CIPCLOSE

Close TCP or UDP connection

We have created a series of tutorials to understand the ESP8266, starting from beginner to advance level:

First we need to do the circuit connections as shown above in the circuit diagram. After uploading the code, open Serial Monitor (Tools>>Serial Monitor) to view what’s happening. You will see IP address on serial monitor, copy the IP address from serial monitor and paste it in browser and click enter to see our webpage. Remember to connect your computer and ESP8266 module on the same Wi-Fi network.

Complete code is given at the end and well explained by the comments, here we are explaining few important part of it.

First we begin serial communication for serial monitor and for ESP8266, by using following two statements:

Serial.println(cmd);Serial2.println(cmd);

NOTE: I have used pins (PA2, PA3) of Serial2 port of STM32 because it is 3.3V tolerant.

Then we need to get the ESP8266 ready by quitting any old connected AP by resetting it and setting Wi-Fi mode as both AP & STA

connect_wifi("AT",100); //Sends AT command with time(Command for Acknowledgement)connect_wifi("AT+CWMODE=3",100); //Sends AT command with time (For setting mode of Wi-Fi)connect_wifi("AT+CWQAP",100); //Sends AT command with time (for Quit AP)connect_wifi("AT+RST",5000); //Sends AT command with time (For RESETTING WIFI)

Then connect the ESP8266 with Wi-Fi network. You have to fill in your Wi-Fi details as shown in below code:

Then we get the IP address of the ESP8266 module and show it on serial monitor by using below code

Serial2.println("AT+CIFSR"); //GET IP AT COMMANDif(Serial2.find("STAIP,")) //This finds the STAIP that is the STATIC IP ADDRESS of ESP8266Serial.print(IP); //prints IP address in Serial monitor

Next we will write HTML code for the webpage. To convert HTML code into Arduino code, you can use this link.

webpage = "<h1>Welcome to Circuit Digest</h1><body bgcolor=f0f0f0>"; //This is the heading line with black font colourString name="<p>Circuit Digest</p><p>A community of electrical and electronics students, engineers and makers</p>";String data="<p>Data Received Successfully.....</p>"; //These two lines are of two paragraphwebpage = "<a href=\"http://circuitdigest.com/\"";webpage+="\">Click Here to get into circuitdigest.com</a>"; //At last we insert the hyperlink to link the website address

Next in void send() function, we have printed HTML using sendwebdata function and closed the server connection using AT+CIPCLOSE=0

connect_wifi("AT+CIPMUX=1",100); //Sends AT command with time (For creating multiple connections)
connect_wifi("AT+CIPSERVER=1,80",100); //Sends AT command with time (For setting up server with port 80)
}