Mô-đun Wi-Fi ESP8266
Hầu hết mọi người gọi ESP8266 là một mô-đun WIFI, nhưng nó thực sự là một vi điều khiển. ESP8266 là tên của bộ vi điều khiển được phát triển bởi Espressif Systems, một công ty của Shanghai. Bộ vi điều khiển này có khả năng thực hiện các hoạt động liên quan đến WIFI do đó nó được sử dụng rộng rãi như một mô-đun WIFI.
Để kết nối mô-đun Wi-Fi ESP8266 với board Blue Pill STM32F103C8 và gửi dữ liệu đến một trang web được lưu trữ trên máy chủ web ESP8266, chúng ta cần:
- Board STM32F103C8
- Mô-đun Wi-Fi ESP8266
- Điểm truy cập máy tính xách tay & Wi-Fi


- GND , đất (0 V)
- TX , Truyền dữ liệu UART
- GPIO 2 , Chân vào ra số 2
- CH_PD , chip power-down
- GPIO 0 , Chân vào ra 0
- RST , tín hiệu Reset
- RX , Nhận bit dữ liệu UART
- VCC , nguồn (+3.3 V)
Một số lệnh AT được sử dụng để STM32 giao tiếp với ESP8266:
THÔNG TIN | SỬ DỤNG |
AT | Testphanr hồi của ESP8266, giao tiếp được thì ESP8266 trả lời ‘OK’ |
AT + RST | Mô-đun RESTART |
AT + GMR | Hiển thị CHI TIẾT PHẦN MỀM |
AT + CWMODE = 1 hoặc 2 hoặc 3 | Chế độ Wi-Fi 1-Station, 2- AP, 3-Cả hai |
AT + CWLAP | Liệt kê AP |
AT + CWJAP = SSID,, PASSWORD | Tham gia AP |
AT+ CWQAP | Thoát khỏi AP |
AT + CIFSR | Nhận địa chỉ IP |
AT + CIPMUX = 0 hoặc 1 | Đặt nhiều kết nối 0- Đơn, 1 nhiều |
AT + CIPSTARTAT + CIPSTART = <loại>, <địa chỉ>, <cổng>AT + CIPSTART = <id>, <loại>, <địa chỉ>, <cổng> | Thiết lập kết nối TCP / UDPĐịa chỉ- Địa chỉ IPĐịa chỉ cổng của ipKết nối đơn: Loại-TCP, UDPNhiều kết nối: Id-0 đến 4, Loại-TCP, UDP |
AT + CIPSENDAT + CIPSEND = <chiều dài>AT + CIPSEND = <id>, <length> | Gửi dữ liệuKết nối đơn, Độ dài – Độ dài của dữ liệuNhiều kết nối, Id = 0 đến 4 |
AT + CIPSTATUS | Có trạng thái kết nối |
AT + CIPSERVER = <chế độ>, <cổng> | Đặt làm Máy chủ 0 – Đóng máy chủ, Cổng 1 mở |
AT + CIPCLOSE | Đóng kết nối TC hoặc UDP |
Sơ đồ mạch và kết nối
Dưới đây sơ đồ cho thấy kết nối giữa mô-đun Wi-Fi STM32 & ESP8266 .

Kết nối chân ESP8266 với chân STM32:
ESP8266 | STM32 |
VCC | 3.3V |
GND | G |
CH_PD | 3.3V |
TX | PA3 |
RX | PA2 |
SMT32F103C8 có ba bộ giao tiếp nối tiếp UART:
Serial Port | Pins | Tolerant |
Serial1 (TX1,RX1) | PA9,PA10PB6,PB7 | 5V |
Serial2 (TX2,RX2) | PA2,PA3 | 3.3V |
Serial3 (TX3,RX3) | PB10,PB11 | 5V |

ESP8266 sử dụng giao tiếp nối tiếp để tương tác với vi điều khiển. Vì vậy, ở đây TX & RX của ESP8266 được nối với cổng serial2 (PA2 & PA3) của board STM32.
Giải thích về Code & Nguyên lý hoạt động
Công việc kết nối ESP8266 với STM32 rất đơn giản. Bạn có thể tìm thấy toàn bộ hoạt động trong video được đưa ra ở cuối hướng dẫn này cùng với code.
Chúng tôi sử dụng arduino IDE để viết và tải code lên STM32.
Đầu tiên chúng ta cần thực hiện các kết nối mạch như hình trên trong sơ đồ mạch. Sau khi tải lên code, hãy mở Serial Monitor (Tools>>Serial Monitor) để theo dõi quá trình hoạt động. Bạn sẽ thấy địa chỉ IP trên Serial Monitor, sao chép địa chỉ IP từ Serial Monitor và dán nó vào trình duyệt và nhấp vào để xem trang web của chúng ta. Nhớ kết nối máy tính và mô-đun ESP8266 trên cùng một mạng Wi-Fi.
Code hoàn chỉnh được đưa ra ở cuối bài đăng.
Trước tiên, chúng tôi bắt đầu giao tiếp nối tiếp cho Serial Monitor và cho ESP8266, bằng cách sử dụng hai câu lệnh sau:
Serial.println(cmd); Serial2.println(cmd);
LƯU Ý: Tôi đã sử dụng các chân (PA2, PA3) của cổng serial2 của STM32 vì nó có nguồn 3,3V.
Sau đó, chúng ta cần chuẩn bị sẵn sàng cho ESP8266 bằng cách thoát khỏi mọi AP được kết nối cũ bằng cách đặt lại và đặt chế độ Wi-Fi thành cả 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)
Sau đó kết nối ESP8266 với mạng Wi-Fi . Bạn phải điền chi tiết Wi-Fi của mình như được hiển thị trong đoạn code dưới đây:
connect_wifi("AT+CWJAP=\"Pramo\",\"pokemon08\"",7000); //provide your WiFi username and password here
Sau đó, chúng tôi nhận được địa chỉ IP của mô-đun ESP8266 và hiển thị nó trên serial monitor bằng cách sử dụng code dưới đây
Serial2.println("AT+CIFSR"); //GET IP AT COMMAND if(Serial2.find("STAIP,")) //This finds the STAIP that is the STATIC IP ADDRESS of ESP8266 Serial.print(IP); //prints IP address in Serial monitor
Tiếp theo chúng tôi sẽ viết code HTML cho trang web . Để chuyển đổi code HTML thành code Arduino, bạn có thể sử dụng liên kết này .
webpage = "<h1>Welcome to Circuit Digest</h1><body bgcolor=f0f0f0>"; //This is the heading line with black font colour String 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 paragraph webpage = "<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
Tiếp theo trong hàm void send () , chúng tôi đã in HTML bằng hàm sendwebdata và đóng kết nối máy chủ bằng AT + CIPCLOSE = 0
void Send() //This function contains data to be sent to local server { webpage = "<h1>Welcome to Circuit Digest</h1><body bgcolor=f0f0f0>"; sendwebdata(webpage); webpage=name; sendwebdata(webpage); delay(1000); webpage = "<a href=\"http://circuitdigest.com/\""; webpage+="\">Click Here to get into circuitdigest.com</a>"; webpage+=data; sendwebdata(webpage); Serial2.println("AT+CIPCLOSE=0"); //Closes the server connection }
Sau khi hoàn thành công việc, bạn có thể kiểm tra hoạt động bằng cách mở IP của ESP8266 trong bất kỳ trình duyệt web nào và nhấp vào liên kết hiển thị trên trang web, Click Here to get into circuitdigest.com, như bên dưới

Sau khi nhấp vào liên kết, bạn sẽ thấy trang web hiển thị “Data Received Successfully…..”
Code hoàn chỉnh với Video trình diễn được đưa ra dưới đây.
CODE:
//Interfacing ESP8266 Wi-Fi with STM32F103C8 //CIRCUIT DIGEST //NOTE: Serial is serial monitor with baud rate(9600) //NOTE: Serial2 (TX2, RX2)is connected with ESP8266(RX,TX)respectively with baud rate (9600) String webpage=""; //String variable to store characters int i=0,k=0,x=0; //integer variables String readString; //using readString feature to read characters boolean No_IP=false; //boolean variables String IP=""; //String variable to store data char temp1='0'; //character variable String name="<p>Circuit Digest</p><p>A community of electrical and electronics students, engineers and makers</p>"; //String with html notations String data="<p>Data Received Successfully.....</p>"; //String with html void check4IP(int t1) //A function to check ip of ESP8266 { int t2=millis(); while(t2+t1>millis()) { while(Serial2.available()>0) { if(Serial2.find("WIFI GOT IP")) { No_IP=true; } } } } void get_ip() //After cheacking ip ,this is a function to get IP address { IP=""; char ch=0; while(1) { Serial2.println("AT+CIFSR"); //GET IP AT COMMAND while(Serial2.available()>0) { if(Serial2.find("STAIP,")) //This finds the STAIP that is the STATIC IP ADDRESS of ESP8266 { delay(1000); Serial.print("IP Address:"); while(Serial2.available()>0) { ch=Serial2.read(); //Serial2 reads from ESP8266 if(ch=='+') break; IP+=ch; } } if(ch=='+') break; } if(ch=='+') break; delay(1000); } Serial.print(IP); //prints IP address in Serial monitor Serial.print("Port:"); Serial.println(80); } void connect_wifi(String cmd, int t) //This function is for connecting ESP8266 with wifi network by using AT commands { int temp=0,i=0; while(1) { Serial.println(cmd); //Sends to serial monitor Serial2.println(cmd); //sends to ESP8266 via serial communication while(Serial2.available()) { if(Serial2.find("OK")) i=8; } delay(t); if(i>5) break; i++; } if(i==8) Serial.println("OK"); else Serial.println("Error"); } void wifi_init() //This function contains AT commands that passes to connect_wifi() { connect_wifi("AT",100); //Sends AT command with time(Command for Achknowledgement) connect_wifi("AT+CWMODE=3",100); //Sends AT command with time (For setting mode of Wifi) 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) check4IP(5000); if(!No_IP) { Serial.println("Connecting Wifi...."); connect_wifi("AT+CWJAP=\"Pramo\",\"pokemon08\"",7000); //provide your WiFi username and password here } else { } Serial.println("Wifi Connected"); get_ip(); 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) } void sendwebdata(String webPage) //This function is used to send webpage datas to the localserver { int ii=0; while(1) { unsigned int l=webPage.length(); Serial.print("AT+CIPSEND=0,"); Serial2.print("AT+CIPSEND=0,"); Serial.println(l+2); Serial2.println(l+2); delay(100); Serial.println(webPage); //sends webpage data to serial monitor Serial2.println(webPage); //sends webpage data to serial2 ESP8266 while(Serial2.available()) { if(Serial2.find("OK")) { ii=11; break; } } if(ii==11) break; delay(100); } } void setup() { Serial.begin(9600); //begins serial monitor with baud rate 9600 Serial2.begin(9600); //begins serial communication with esp8266 with baud rate 9600 (Change according to your esp8266 module) wifi_init(); Serial.println("System Ready.."); } void loop() { k=0; Serial.println("Please Refresh your Page"); while(k<1000) { k++; while(Serial2.available()) { if(Serial2.find("0,CONNECT")) { Serial.println("Start Printing"); Send(); Serial.println("Done Printing"); delay(1000); } } delay(1); } } void Send() //This function contains data to be sent to local server { webpage = "<h1>Welcome to Circuit Digest</h1><body bgcolor=f0f0f0>"; sendwebdata(webpage); webpage=name; sendwebdata(webpage); delay(1000); webpage = "<a href=\"http://circuitdigest.com/\""; webpage+="\">Click Here to get into circuitdigest.com</a>"; webpage+=data; sendwebdata(webpage); Serial2.println("AT+CIPCLOSE=0"); //Closes the server connection }
Tham khảo: https://circuitdigest.com/
I’m really loving the theme/design of your weblog. Do
you ever run into any web browser compatibility issues?
A number of my blog audience have complained about
my website not working correctly in Explorer but looks great in Opera.
Do you have any suggestions to help fix this problem?
Whats up very cool site!! Man .. Beautiful .. Superb ..
I’ll bookmark your site and take the feeds also?
I’m glad to search out a lot of useful info here in the publish, we’d like develop
more techniques in this regard, thanks for sharing.
. . . . .
These are genuinely great ideas in regarding blogging.
You have touched some fastidious factors here. Any way keep up wrinting.
Yes! Finally something about bypass shell.
sildenafil contraindicaciones corazon
sildenafil contraindicaciones corazon
Hi there just wanted to give you a quick heads up.
The words in your content seem to be running off
the screen in Safari. I’m not sure if this is a
format issue or something to do with web browser compatibility but I thought I’d post to let you know.
The design look great though! Hope you get the issue fixed soon. Many thanks
Your means of describing all in this paragraph is actually good, every one
be capable of without difficulty know it, Thanks a
lot.
I’m truly enjoying the design and layout of your website.
It’s a very easy on the eyes which makes it much more
pleasant for me to come here and visit more often. Did
you hire out a developer to create your theme? Fantastic work!
I’ve been surfing online more than three hours today, yet I never found any interesting article like yours.
It’s pretty worth enough for me. Personally, if all website owners and bloggers
made good content as you did, the net will be a lot more useful than ever before.
It’s awesome for me to have a site, which is good in support
of my know-how. thanks admin
viagra condom
viagra condom
Useful information. Fortunate me I discovered your site by
accident, and I’m surprised why this accident didn’t took place
earlier! I bookmarked it.
Just desire to say your article is as astonishing.
The clearness in your post is simply nice and i can assume you are an expert on this subject.
Well with your permission allow me to grab your
RSS feed to keep up to date with forthcoming post. Thanks a million and please carry on the rewarding work.
I’m not sure exactly why but this website is
loading extremely slow for me. Is anyone else having this issue or is it a problem on my end?
I’ll check back later and see if the problem still exists.
An impressive share! I have just forwarded this onto a coworker who had been doing a
little homework on this. And he actually ordered me dinner because I discovered it for him…
lol. So let me reword this…. Thank YOU for the meal!!
But yeah, thanx for spending the time to talk about this subject here
on your web page.
Wow, marvelous blog layout! How long have you been blogging
for? you make blogging look easy. The overall look
of your site is magnificent, as well as the content!
I’ve been browsing online more than 2 hours today, yet I never found any interesting article like yours.
It’s pretty worth enough for me. Personally, if all web owners and bloggers made good content as you did, the web will
be a lot more useful than ever before.
İnstagram Takipçileri
İnstagram hesaplarını, kurumsallaşmak, markalaşmak ya da pazarlama
işlerinin artırılabilmesi için kullananlar, takipçi sayılarını
artırarak hedeflerine ulaşabiliyorlar. Firma tüm İnstagram kullanıcılarına takipçi paketlerini
100 takipçi sayısı ile 50.000 takipçi sayısı arasına değişen paketlerden oluşmaktadır.
What a material of un-ambiguity and preserveness of valuable know-how
concerning unpredicted feelings.