-
Notifications
You must be signed in to change notification settings - Fork 0
/
frimware-ota-station.ino
75 lines (68 loc) · 1.94 KB
/
frimware-ota-station.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <ESP8266HTTPUpdateServer.h>
const char* ssid = "Chu Quang";
const char* password = "1234567890";
const char* host = "ESP8266";
const char* updatePath = "/update";
const char* updateUsername = "admin";
const char* updatePassword = "admin";
ESP8266WebServer webServer(80);
ESP8266HTTPUpdateServer httpUpdater;
//-----------------------------------------//
const char MainPage[] PROGMEM = R"=====(
<!DOCTYPE html>
<html>
<head>
<title>ESP826</title>
<style>
body{
text-align: center;
}
</style>
<meta name="viewport" content="width=device-width,user-scalable=0" charset="UTF-8">
</head>
<body>
<div>
<button onclick="window.location.href='/update'">UPLOAD FIRMWARE</button><br><br>
</div>
<script>
</script>
</body>
</html>
)=====";
void setup(void){
Serial.begin(115200);
Serial.println();
Serial.println("Đang khởi động chương trình...");
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while(WiFi.waitForConnectResult() != WL_CONNECTED){
WiFi.begin(ssid, password);
Serial.println("Kết nối Wi-Fi thất bại, đang thử lại...");
}
Serial.print("Địa chỉ IP: ");
Serial.println(WiFi.localIP());
MDNS.begin(host);
MDNS.addService("http", "tcp", 80);
httpUpdater.setup(&webServer, updatePath, updateUsername, updatePassword);
webServer.on("/",[]{
String s = MainPage;
webServer.send(200,"text/html",s);
});
webServer.begin();
Serial.println("Khởi động Webserer, thành công.");
//=========Chương trình Chính=====//
pinMode(D4,OUTPUT);
//============End=================//
}
void loop(void){
MDNS.update();
webServer.handleClient();
//====Chương trình Chính==========//
digitalWrite(D4,!digitalRead(D4));
delay(500);
//=========End====================//
}