質問編集履歴
4
ミス
test
CHANGED
File without changes
|
test
CHANGED
@@ -58,7 +58,7 @@
|
|
58
58
|
|
59
59
|
|
60
60
|
|
61
|
-
|
61
|
+
html = "<!DOCTYPE html>\
|
62
62
|
|
63
63
|
<html>\
|
64
64
|
|
3
ミス
test
CHANGED
File without changes
|
test
CHANGED
@@ -32,7 +32,7 @@
|
|
32
32
|
|
33
33
|
IPAddress ip(192, 168, 0, 1);
|
34
34
|
|
35
|
-
IPAddress gateway(192, 1
|
35
|
+
IPAddress gateway(192, 178, 0, 204);
|
36
36
|
|
37
37
|
IPAddress netmask(255, 255, 255, 0);
|
38
38
|
|
2
ミス
test
CHANGED
File without changes
|
test
CHANGED
@@ -18,9 +18,9 @@
|
|
18
18
|
|
19
19
|
#include <Servo.h>
|
20
20
|
|
21
|
-
const char* ssid = "NE
|
21
|
+
const char* ssid = "NE6";
|
22
|
-
|
22
|
+
|
23
|
-
const char* password = "q
|
23
|
+
const char* password = "q";
|
24
24
|
|
25
25
|
Servo sv1;
|
26
26
|
|
1
ミス
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,9 +8,57 @@
|
|
8
8
|
|
9
9
|
```HTMLtoc
|
10
10
|
|
11
|
+
#include <ESP8266WiFi.h>
|
12
|
+
|
13
|
+
#include <WiFiClient.h>
|
14
|
+
|
15
|
+
#include <ESP8266WebServer.h>
|
16
|
+
|
17
|
+
#include <ESP8266mDNS.h>
|
18
|
+
|
19
|
+
#include <Servo.h>
|
20
|
+
|
21
|
+
const char* ssid = "NETGEAR76";
|
22
|
+
|
23
|
+
const char* password = "quietcanoe089";
|
24
|
+
|
25
|
+
Servo sv1;
|
26
|
+
|
27
|
+
Servo sv2;
|
28
|
+
|
11
|
-
|
29
|
+
Servo sv3;
|
30
|
+
|
12
|
-
|
31
|
+
// 文字列ではなく、数値配列です。
|
32
|
+
|
33
|
+
IPAddress ip(192, 168, 0, 1);
|
34
|
+
|
35
|
+
IPAddress gateway(192, 168, 0, 254);
|
36
|
+
|
37
|
+
IPAddress netmask(255, 255, 255, 0);
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
const int PIN_LED = 13;
|
42
|
+
|
43
|
+
int data = 0;
|
44
|
+
|
45
|
+
double value;
|
46
|
+
|
47
|
+
String html = "";
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
ESP8266WebServer server(80);
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
void setup(void){
|
56
|
+
|
57
|
+
char output[10240];
|
58
|
+
|
59
|
+
|
60
|
+
|
13
|
-
html = "<!DOCTYPEhtml>\
|
61
|
+
char* html = "<!DOCTYPE html>\
|
14
62
|
|
15
63
|
<html>\
|
16
64
|
|
@@ -36,8 +84,176 @@
|
|
36
84
|
|
37
85
|
<input type=\"text\" ;\">\
|
38
86
|
|
87
|
+
<p>printf("%d",value);</p>\
|
88
|
+
|
39
89
|
</body>\
|
40
90
|
|
41
91
|
</html>";
|
42
92
|
|
93
|
+
sprintf(output, sizeof(output), html, value);
|
94
|
+
|
95
|
+
printf("%s\n", output);
|
96
|
+
|
97
|
+
sv1.attach(14, 800, 2300);
|
98
|
+
|
99
|
+
sv2.attach(13, 800, 2300);
|
100
|
+
|
101
|
+
sv3.attach(12, 800, 2300);
|
102
|
+
|
103
|
+
pinMode(PIN_LED, OUTPUT);
|
104
|
+
|
105
|
+
digitalWrite(PIN_LED, LOW);
|
106
|
+
|
107
|
+
sv1.write(0);
|
108
|
+
|
109
|
+
sv2.write(0);
|
110
|
+
|
111
|
+
sv3.write(0);
|
112
|
+
|
113
|
+
Serial.begin(9600);
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
// WIFI_AP, WIFI_STA, WIFI_AP_STA or WIFI_OFF
|
118
|
+
|
119
|
+
WiFi.mode(WIFI_STA);
|
120
|
+
|
121
|
+
WiFi.config(ip, gateway,netmask);
|
122
|
+
|
123
|
+
WiFi.begin(ssid, password);
|
124
|
+
|
125
|
+
Serial.println("");
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
// Wifi接続ができるまで待機
|
130
|
+
|
131
|
+
while (WiFi.status() != WL_CONNECTED) {
|
132
|
+
|
133
|
+
delay(500);
|
134
|
+
|
135
|
+
Serial.print(".");
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
Serial.println("");
|
140
|
+
|
141
|
+
Serial.print("IPアドレス: ");
|
142
|
+
|
143
|
+
Serial.println(WiFi.localIP());
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
// ローカルネットワーク内のみ有効のmDNS(マルチキャストDNS)を開始
|
148
|
+
|
149
|
+
// bool MDNSResponder::begin(const char* hostname){}
|
150
|
+
|
151
|
+
if (MDNS.begin("petitmonte")) {
|
152
|
+
|
153
|
+
Serial.println("mDNSレスポンダーの開始");
|
154
|
+
|
155
|
+
}
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
// トップページ
|
160
|
+
|
161
|
+
server.on("/", [](){
|
162
|
+
|
163
|
+
// HTTPステータスコード(200) リクエストの成功
|
164
|
+
|
165
|
+
Serial.println(value);
|
166
|
+
|
167
|
+
server.send(200, "text/html", html);
|
168
|
+
|
169
|
+
});
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
// LEDをオン
|
174
|
+
|
175
|
+
server.on("/uho-ON", [](){
|
176
|
+
|
177
|
+
value = analogRead(2);
|
178
|
+
|
179
|
+
Serial.println(value);
|
180
|
+
|
181
|
+
digitalWrite(PIN_LED, HIGH);
|
182
|
+
|
183
|
+
sv1.write(35);
|
184
|
+
|
185
|
+
sv2.write(35);
|
186
|
+
|
187
|
+
sv3.write(35);
|
188
|
+
|
189
|
+
// HTTPステータスコード(200) リクエストの成功
|
190
|
+
|
191
|
+
server.send(200, "text/html", html);
|
192
|
+
|
193
|
+
});
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
// LEDをオフ
|
198
|
+
|
199
|
+
server.on("/uho-OFF", [](){
|
200
|
+
|
201
|
+
digitalWrite(PIN_LED, LOW);
|
202
|
+
|
203
|
+
sv1.write(0);
|
204
|
+
|
205
|
+
sv2.write(0);
|
206
|
+
|
207
|
+
sv3.write(0);
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
// HTTPステータスコード(200) リクエストの成功
|
214
|
+
|
215
|
+
server.send(200, "text/html", html);
|
216
|
+
|
217
|
+
});
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
// 存在しないURLを指定した場合の動作を指定する
|
222
|
+
|
223
|
+
server.onNotFound([](){
|
224
|
+
|
225
|
+
// HTTPステータスコード(404) 未検出(存在しないファイルにアクセス)
|
226
|
+
|
227
|
+
server.send(404, "text/plain", "404");
|
228
|
+
|
229
|
+
});
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
server.begin();
|
234
|
+
|
235
|
+
Serial.println("Webサーバーの開始");
|
236
|
+
|
237
|
+
}
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
void loop(void){
|
242
|
+
|
243
|
+
// Webサーバの接続要求待ち
|
244
|
+
|
245
|
+
server.handleClient();
|
246
|
+
|
247
|
+
}
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
|
258
|
+
|
43
259
|
```
|