This repository has been archived by the owner on Oct 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_10_setupmode.ino
138 lines (118 loc) · 3.74 KB
/
_10_setupmode.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
/**
* 初期化
*/
void setup_setupmode() {
// ファイルシステム初期化
setup_server();
showSetupStartupScreen();
}
void loop_setupmode() {
server.handleClient();
}
/**
* WiFi設定
*/
void handleRootGet() {
String html = "";
html += "<html>";
html += "<head>";
html += "<meta charset='UTF-8'>";
html += "<style>";
html += " input { width:200px; }";
html += "</style>";
html += "</head>";
html += "<h1>" + product + " Settings</h1>";
html += "<form method='post'>";
html += " <br>";
html += " 以下の設定は、接続先WiFiの情報です。面倒ですが正しく設定して下さい。<br>";
html += " 2.4GHz帯のみ対応しています。<br>";
html += " <input type='text' name='ssid' placeholder='ssid' autofocus><br>";
html += " <input type='text' name='pass' placeholder='pass'><br>";
html += " 以下の設定は、mDNS(Rendezvous) の名前です。LAN内の他の端末等と重複しないようにして下さい。<br>";
html += " ハイフン、アンダースコアを使用すると名前解決に失敗する可能性があるため非推奨です。<br>";
html += " <input type='text' name='mdnsname' placeholder='mdnsname' value='" + ssid + "'><br>";
html += " <br>";
html += " <input type='submit' value='設定する'><br>";
html += "</form>";
html += "<br>";
html += "<hr>";
html += product_long + ", Copyright 2018 ziomatrix.org.";
html += "</html>";
server.send(200, "text/html", html);
}
void handleRootPost() {
String ssid = server.arg("ssid");
String pass = server.arg("pass");
String mdnsname = server.arg("mdnsname");
SPIFFS.begin();
// 設定ファイル
File f = SPIFFS.open(settings, "w");
f.println(ssid);
f.println(pass);
f.println(mdnsname);
f.close();
// 設定済みフラグファイル
File f2 = SPIFFS.open(configured_file, "w");
f2.println("ok");
f2.close();
String html = "";
html += "<html>";
html += "<head>";
html += "<meta charset='UTF-8'>";
html += "<style>";
html += " input { width:200px; }";
html += "</style>";
html += "</head>";
html += "<h1>" + product + " setting done</h1>";
html += "SSID " + ssid + "<br>";
html += "PASS " + pass + "<br>";
html += "mDNS " + mdnsname + "<br>";
html += "<br>";
html += "Restart (power off then power on) to use above setting.<br>";
html += "設定が完了しました。リセットボタンを押して再起動して下さい。<br>";
html += "<br>";
html += "<a href='/'>setting again</a>";
html += "</html>";
server.send(200, "text/html", html);
}
/**
* 初期化(サーバモード)
*/
void setup_server() {
byte mac[6];
WiFi.macAddress(mac);
// SSID は eb3macaddress
ssid = product_short;
for (int i = 0; i < 6; i++) {
ssid += String(mac[i], HEX);
}
Serial.println("SSID: " + ssid);
// Serial.println("PASS: " + pass);
/* You can remove the password parameter if you want the AP to be open. */
// WiFi.softAP(ssid.c_str(), pass.c_str());
WiFi.softAP(ssid.c_str());
server.on("/", HTTP_GET, handleRootGet);
server.on("/", HTTP_POST, handleRootPost);
server.begin();
Serial.println("HTTP server started.");
}
void showSetupStartupScreen() {
// display init and show initial screen
display.init();
if (needFlip) {
display.flipScreenVertically();
}
display.setFont(ArialMT_Plain_16);
display.clear();
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.drawString(0, 0, product_long);
display.drawString(0, 16, "Setup mode.");
display.drawString(0, 33, "http://" + WiFi.softAPIP().toString() + "/" );
display.setFont(ArialMT_Plain_10);
display.drawString(0, 52, ssid);
display.display();
delay(1000);
}