-
Notifications
You must be signed in to change notification settings - Fork 1
/
ESP8266_APmode_HTML_Form_Example.ino
82 lines (53 loc) · 1.67 KB
/
ESP8266_APmode_HTML_Form_Example.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
76
77
78
79
80
81
82
// Libraries
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
// WiFi network
const char* ssid = "ESPTEST";
const char* password = "12345678";
ESP8266WebServer server ( 80 );
void handleRoot() {
String html = "<!DOCTYPE html>";
html += "<html> <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">";
html += "<body> <h2>Formulario</h2>";
html += "<p> A penas um teste</p>";
html += "<form method=\"get\" action=\"/save\">";
html += "SSID:<br>";
html += "<input type=\"text\" name=\"SSID\" value=\"Mickey\"> <br> ";
html += "Senha:<br> ";
html += "<input type=\"text\" name=\"Senha\" value=\"Mouse\"> <br>";
html += "<br>";
html += "<input type=\"submit\" value=\"Enviar\"> </form> </body> </html>";
server.send ( 200, "text/html", html );
}
void handleSave() {
if (server.arg("SSID")!= ""){
Serial.println("SSID: " + server.arg("SSID"));
}
if (server.arg("Senha")!= ""){
Serial.println("Senha: " + server.arg("Senha"));
}
String html = "<!DOCTYPE html>";
html += "<html> <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">";
html += " <body>";
html += "<p> Formulario Enviado </p>";
html += "</body> </html>";
server.send ( 200, "text/html", html );
}
void setup() {
// Start serial
Serial.begin(115200);
delay(10);
WiFi.softAP(ssid, password);
Serial.println();
Serial.print("Server IP address: ");
Serial.println(WiFi.softAPIP());
Serial.print("Server MAC address: ");
Serial.println(WiFi.softAPmacAddress());
server.on ( "/", handleRoot );
server.on ("/save", handleSave);
server.begin();
Serial.println ( "HTTP server started" );
}
void loop() {
server.handleClient();
}