Skip to content

Instantly share code, notes, and snippets.

@hocarm
Created February 21, 2017 09:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hocarm/e6c2a26935abaee077add5ea76005c82 to your computer and use it in GitHub Desktop.
Save hocarm/e6c2a26935abaee077add5ea76005c82 to your computer and use it in GitHub Desktop.
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
WiFiUDP Udp;
void setup() {
int cnt = 0;
//Khởi tạo baud 115200
Serial.begin(115200);
//Mode wifi là station
WiFi.mode(WIFI_STA);
//Chờ kết nối
while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
if(cnt++ >= 10){
WiFi.beginSmartConfig();
while(1){
delay(1000);
//Kiểm tra kết nối thành công in thông báo
if(WiFi.smartConfigDone()){
Serial.println("SmartConfig Success");
break;
}
}
}
}
Serial.println("");
Serial.println("");
WiFi.printDiag(Serial);
// Khởi tạo server
Udp.begin(49999);
Serial.println("Server started");
// In địa chỉ IP
Serial.println(WiFi.localIP());
}
void loop() {
// Nhận gói tin gửi từ ESPTouch
Udp.parsePacket();
//In IP của ESP8266
while(Udp.available()){
Serial.println(Udp.remoteIP());
Udp.flush();
delay(5);
}
}
@bangnguyendev
Copy link

// Nhận gói tin gửi từ ESPTouch
Udp.parsePacket();
//In IP của ESP8266
while(Udp.available()){
Serial.println(Udp.remoteIP());
Udp.flush();
delay(5);
}

khúc này có tác dụng gì vậy bạn?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment