Проблемы с подключением платы esp8266 к точке доступа
16.12.2024, 16:58. Показов 879. Ответов 2
Здраствуйте, вот программирую вездеход на плате esp8266 NodeMCU с вайфай модулем. По-идее плата должна подключаться к точке доступа с заданного устройства, и она подключалась, однако в вездеходе также предусмотрен фоторезистор для фар, и в коде, где фоторезистор работает, ничего не подключается, т.е. в мониторе порта пишет, что он подключился, однако когда заходишь на сайт с интерфейсом видно, что ничего он не подключил, но причём фоторезистор работает в таком варианте. С вариантом кода без фоторезистора всё хорошо, однако мне фоторезистор позарез нужен в этом проекте. Подскажите пожалуйста, что я делаю не так? Пишу код на С#, единственное отличие этих двух кодов - расположение строчки int val = analogRead(PIN_PHOTO_SENSOR); . Схемы прилагаются.
Код с рабочим фоторезистром, но без подключения:
| C# | 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
| #define ENA 14 // Enable/speed motors Right GPIO14(D5)
#define ENB 12 // Enable/speed motors Left GPIO12(D6)
#define IN_1 15 // L298N in1 motors Right GPIO15(D8)
#define IN_2 13 // L298N in2 motors Right GPIO13(D7)
#define IN_3 2 // L298N in3 motors Left GPIO2(D4)
#define IN_4 0 // L298N in4 motors Left GPIO0(D3)
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
String command; //String to store app command state.
int speedCar = 800; // 400 - 1023.
int speed_Coeff = 3;
const char* ssid = "Redmi11"; //Наименовение точки доступа
const char* password = "1234567890";
ESP8266WebServer server(80);
//светодиоды
#define PIN_LED_STOP D0 //стоп-сигнал
#define PIN_LED_1 D1//фары
#define PIN_LED_2 D2
#define PIN_PHOTO_SENSOR A0 //фоторезистор
int val = analogRead(PIN_PHOTO_SENSOR);
void setup() {
pinMode(ENA, OUTPUT);
pinMode(ENB, OUTPUT);
pinMode(IN_1, OUTPUT);
pinMode(IN_2, OUTPUT);
pinMode(IN_3, OUTPUT);
pinMode(IN_4, OUTPUT);
pinMode (PIN_LED_STOP, OUTPUT);
pinMode (PIN_LED_1, OUTPUT);
pinMode (PIN_LED_2, OUTPUT);
Serial.begin(115200);
// Подключение к Wi-Fi
Serial.println("Connecting to...");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected..!");
Serial.print("Got IP: ");
Serial.println(WiFi.localIP());
server.on ( "/", HTTP_handleRoot );
server.begin();
Serial.println("HTTP server started");
server.on("/status", HTTP_handleStatus);
}
void goAhead(){ //вперёд
digitalWrite(IN_1, LOW);
digitalWrite(IN_2, HIGH);
analogWrite(ENA, speedCar);
digitalWrite(IN_3, LOW);
digitalWrite(IN_4, HIGH);
analogWrite(ENB, speedCar);
digitalWrite(PIN_LED_1, HIGH);
digitalWrite(PIN_LED_2, HIGH);
}
void goBack(){ //назад
digitalWrite(IN_1, HIGH);
digitalWrite(IN_2, LOW);
analogWrite(ENA, speedCar);
digitalWrite(IN_3, HIGH);
digitalWrite(IN_4, LOW);
analogWrite(ENB, speedCar);
digitalWrite(PIN_LED_STOP, HIGH);
}
void goRight(){ //влево-вверх
digitalWrite(IN_1, LOW);
digitalWrite(IN_2, LOW);
analogWrite(ENA, speedCar);
digitalWrite(IN_3, LOW);
digitalWrite(IN_4, HIGH);
analogWrite(ENB, speedCar/speed_Coeff);
digitalWrite(PIN_LED_1, LOW);
digitalWrite(PIN_LED_2, HIGH);
}
void goLeft(){ //вправо-вверх
digitalWrite(IN_1, LOW);
digitalWrite(IN_2, HIGH);
analogWrite(ENA, speedCar/speed_Coeff);
digitalWrite(IN_3, LOW);
digitalWrite(IN_4, LOW);
analogWrite(ENB, speedCar);
digitalWrite(PIN_LED_1, HIGH);
digitalWrite(PIN_LED_2, LOW);
}
void goAheadRight(){ //танковый разворот ()
digitalWrite(IN_1, HIGH);
digitalWrite(IN_2, LOW);
analogWrite(ENA, speedCar);
digitalWrite(IN_3, LOW);
digitalWrite(IN_4, HIGH);
analogWrite(ENB, speedCar);
digitalWrite(PIN_LED_1, HIGH);
digitalWrite(PIN_LED_2, LOW);
}
void goAheadLeft(){ //танковый разворот
digitalWrite(IN_1, LOW);
digitalWrite(IN_2, HIGH);
analogWrite(ENA, speedCar);
digitalWrite(IN_3, HIGH);
digitalWrite(IN_4, LOW);
analogWrite(ENB, speedCar);
digitalWrite(PIN_LED_1, LOW);
digitalWrite(PIN_LED_2, HIGH);
}
void stopRobot(){
digitalWrite(IN_1, LOW);
digitalWrite(IN_2, LOW);
analogWrite(ENA, speedCar);
digitalWrite(IN_3, LOW);
digitalWrite(IN_4, LOW);
analogWrite(ENB, speedCar);
digitalWrite(PIN_LED_STOP, LOW);
digitalWrite(PIN_LED_1, LOW);
digitalWrite(PIN_LED_2, LOW);
}
void loop() {
server.handleClient();
command = server.arg("State");
if (command == "F") goAhead();
else if (command == "B") goBack();
else if (command == "L") goLeft();
else if (command == "R") goRight();
else if (command == "I") goAheadRight();
else if (command == "G") goAheadLeft();
else if (command == "S") stopRobot();
//если освещённость больше 500, то включаются фары
int val = analogRead(PIN_PHOTO_SENSOR);
if (val < 500) {
digitalWrite(PIN_LED_1, LOW);
digitalWrite(PIN_LED_2, LOW);
} else {
digitalWrite(PIN_LED_1, HIGH);
digitalWrite(PIN_LED_2, HIGH);
}
}
void HTTP_handleRoot(void) {
String html = "<html><head>"
"<meta charset='UTF-8'>"
"<meta name='viewport' content='width=device-width, initial-scale=1.0'>"
"<style>"
"body {font-family: Arial, sans-serif; background-color: #f0f0f0; color: #333; margin: 0; padding: 0;}"
".container { max-width: 600px; margin: 50px auto; padding: 20px; background-color: #fff; border-radius: 8px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); text-align: center; }"
"h1 { font-size: 24px; margin-bottom: 20px; }"
".button-container { display: flex; flex-direction: column; gap: 10px; }"
".row { display: flex; justify-content: center; gap: 10px; }"
".image-button { background-color: white; color: white; border: none; border-radius: 5px; padding: 15px; font-size: 16px; cursor: pointer; transition: background-color 0.3s, opacity 0.3s; width: 180px; height: 190px; }"
".image-button:hover { opacity: 0.9; }"
".image-button img { width: 100%; height: 100%; object-fit: cover; }"
".image-button-up img { transform: rotate(180deg); }"
".image-button-left img { transform: rotate(90deg); }"
".image-button-right img { transform: rotate(-90deg); }"
".orange { background-color: orange; width: 180px; height: 190px; border: none; }"
"#terminal { background-color: black; color: white; padding: 10px; margin-top: 20px; height: 200px; overflow-y: auto; white-space: pre-wrap; }"
"@media (max-width: 600px) { h1 { font-size: 20px; } .image-button { width: 120px; height: 130px; } .orange { width: 120px; height: 130px; } }"
"</style>"
"<title>Радиоуправляемый танк</title></head><body>"
"<div class='container'><h1>Радиоуправляемый танк</h1>"
"<div class='button-container'>"
"<div class='row'>"
"<button class='image-button image-button-left' onclick=\"sendCommand('I')\">"
"<img src='https://cdn.icon-icons.com/icons2/3991/PNG/512/left_down_arrow_arrow_icon_253889.png' alt='Кнопка' /></button>"
"<button class='image-button image-button-up' onclick=\"sendCommand('F')\">"
"<img src='https://cdn.icon-icons.com/icons2/910/PNG/512/down-arrow_icon-icons.com_71215.png' alt='Кнопка' /></button>"
"<button class='image-button image-button-up' onclick=\"sendCommand('G')\">"
"<img src='https://cdn.icon-icons.com/icons2/3991/PNG/512/left_down_arrow_arrow_icon_253889.png' alt='Кнопка' /></button>"
"</div><div class='row'>"
"<button class='image-button image-button-left' onclick=\"sendCommand('L')\">"
"<img src='https://cdn.icon-icons.com/icons2/910/PNG/512/down-arrow_icon-icons.com_71215.png' alt='Кнопка' /></button>"
"<button class='orange' onclick=\"sendCommand('S')\">Стоп</button>"
"<button class='image-button image-button-right' onclick=\"sendCommand('R')\">"
"<img src='https://cdn.icon-icons.com/icons2/910/PNG/512/down-arrow_icon-icons.com_71215.png' alt='Кнопка' /></button>"
"</div><div class='row'>"
"<button class='image-button image-button-down' onclick=\"sendCommand('B')\">"
"<img src='https://cdn.icon-icons.com/icons2/910/PNG/512/down-arrow_icon-icons.com_71215.png' alt='Кнопка' /></button>"
"</div></div>"
"<div id='terminal'></div>"
"<script>"
"function sendCommand(cmd) {"
" var xhr = new XMLHttpRequest();"
" xhr.open('GET', '/?State=' + cmd, true);"
" xhr.send();"
"}"
"function updateTerminal() {"
" var xhr = new XMLHttpRequest();"
" xhr.open('GET', '/status', true);"
" xhr.onload = function() {"
" if (xhr.status === 200) {"
" document.getElementById('terminal').innerText = xhr.responseText;"
" }"
" };"
" xhr.send();"
"}"
"setInterval(updateTerminal, 1000); // Обновляем каждую секунду"
"</script>"
"</body></html>";
server.send(200, "text/html", html);
}
void HTTP_handleStatus() {
// Считывание значений с датчиков
int lightValue = analogRead(PIN_PHOTO_SENSOR);
//int distanceValue = sonar.ping_cm(); // Считываем расстояние
// int distanceValue = getDistance(); // Получаем расстояние
String led1State = digitalRead(PIN_LED_1) == HIGH ? "ON" : "OFF";
String led2State = digitalRead(PIN_LED_2) == HIGH ? "ON" : "OFF";
String ledStopState = digitalRead(PIN_LED_STOP) == HIGH ? "ON" : "OFF";
// Формирование строки статуса
String status = "Освещенность: " + String(lightValue) + "\n";
//status += "Расстояние до объекта: " + String(distanceValue) + " см\n";
status += "Состояние фары 1: " + led1State + "\n";
status += "Состояние фары 2: " + led2State + "\n";
status += "Состояние заднего фонаря: " + ledStopState + "\n";
// Отправка статуса клиенту
server.send(200, "text/plain", status);
} |
|
Код с рабочим подключением, но фоторезистор не работает:
| C# | 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
| #define ENA 14 // Enable/speed motors Right GPIO14(D5)
#define ENB 12 // Enable/speed motors Left GPIO12(D6)
#define IN_1 15 // L298N in1 motors Right GPIO15(D8)
#define IN_2 13 // L298N in2 motors Right GPIO13(D7)
#define IN_3 2 // L298N in3 motors Left GPIO2(D4)
#define IN_4 0 // L298N in4 motors Left GPIO0(D3)
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
String command; //String to store app command state.
int speedCar = 800; // 400 - 1023.
int speed_Coeff = 3;
const char* ssid = "Redmi11"; //Наименовение точки доступа
const char* password = "1234567890";
ESP8266WebServer server(80);
//светодиоды
#define PIN_LED_STOP D0 //стоп-сигнал
#define PIN_LED_1 D1//фары
#define PIN_LED_2 D2
#define PIN_PHOTO_SENSOR A0 //фоторезистор
int val = analogRead(PIN_PHOTO_SENSOR);
void setup() {
pinMode(ENA, OUTPUT);
pinMode(ENB, OUTPUT);
pinMode(IN_1, OUTPUT);
pinMode(IN_2, OUTPUT);
pinMode(IN_3, OUTPUT);
pinMode(IN_4, OUTPUT);
pinMode (PIN_LED_STOP, OUTPUT);
pinMode (PIN_LED_1, OUTPUT);
pinMode (PIN_LED_2, OUTPUT);
Serial.begin(115200);
// Подключение к Wi-Fi
Serial.println("Connecting to...");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected..!");
Serial.print("Got IP: ");
Serial.println(WiFi.localIP());
server.on ( "/", HTTP_handleRoot );
server.begin();
Serial.println("HTTP server started");
server.on("/status", HTTP_handleStatus);
}
void goAhead(){ //вперёд
digitalWrite(IN_1, LOW);
digitalWrite(IN_2, HIGH);
analogWrite(ENA, speedCar);
digitalWrite(IN_3, LOW);
digitalWrite(IN_4, HIGH);
analogWrite(ENB, speedCar);
digitalWrite(PIN_LED_1, HIGH);
digitalWrite(PIN_LED_2, HIGH);
}
void goBack(){ //назад
digitalWrite(IN_1, HIGH);
digitalWrite(IN_2, LOW);
analogWrite(ENA, speedCar);
digitalWrite(IN_3, HIGH);
digitalWrite(IN_4, LOW);
analogWrite(ENB, speedCar);
digitalWrite(PIN_LED_STOP, HIGH);
}
void goRight(){ //влево-вверх
digitalWrite(IN_1, LOW);
digitalWrite(IN_2, LOW);
analogWrite(ENA, speedCar);
digitalWrite(IN_3, LOW);
digitalWrite(IN_4, HIGH);
analogWrite(ENB, speedCar/speed_Coeff);
digitalWrite(PIN_LED_1, LOW);
digitalWrite(PIN_LED_2, HIGH);
}
void goLeft(){ //вправо-вверх
digitalWrite(IN_1, LOW);
digitalWrite(IN_2, HIGH);
analogWrite(ENA, speedCar/speed_Coeff);
digitalWrite(IN_3, LOW);
digitalWrite(IN_4, LOW);
analogWrite(ENB, speedCar);
digitalWrite(PIN_LED_1, HIGH);
digitalWrite(PIN_LED_2, LOW);
}
void goAheadRight(){ //танковый разворот ()
digitalWrite(IN_1, HIGH);
digitalWrite(IN_2, LOW);
analogWrite(ENA, speedCar);
digitalWrite(IN_3, LOW);
digitalWrite(IN_4, HIGH);
analogWrite(ENB, speedCar);
digitalWrite(PIN_LED_1, HIGH);
digitalWrite(PIN_LED_2, LOW);
}
void goAheadLeft(){ //танковый разворот
digitalWrite(IN_1, LOW);
digitalWrite(IN_2, HIGH);
analogWrite(ENA, speedCar);
digitalWrite(IN_3, HIGH);
digitalWrite(IN_4, LOW);
analogWrite(ENB, speedCar);
digitalWrite(PIN_LED_1, LOW);
digitalWrite(PIN_LED_2, HIGH);
}
/*
void goBackRight(){
digitalWrite(IN_1, HIGH);
digitalWrite(IN_2, LOW);
analogWrite(ENA, speedCar/speed_Coeff);
digitalWrite(IN_3, HIGH);
digitalWrite(IN_4, LOW);
analogWrite(ENB, speedCar);
digitalWrite(PIN_LED_STOP, HIGH);
}
void goBackLeft(){
digitalWrite(IN_1, HIGH);
digitalWrite(IN_2, LOW);
analogWrite(ENA, speedCar);
digitalWrite(IN_3, HIGH);
digitalWrite(IN_4, LOW);
analogWrite(ENB, speedCar/speed_Coeff);
digitalWrite(PIN_LED_STOP, HIGH);
}
*/
void stopRobot(){
digitalWrite(IN_1, LOW);
digitalWrite(IN_2, LOW);
analogWrite(ENA, speedCar);
digitalWrite(IN_3, LOW);
digitalWrite(IN_4, LOW);
analogWrite(ENB, speedCar);
digitalWrite(PIN_LED_STOP, LOW);
digitalWrite(PIN_LED_1, LOW);
digitalWrite(PIN_LED_2, LOW);
}
void loop() {
server.handleClient();
command = server.arg("State");
if (command == "F") goAhead();
else if (command == "B") goBack();
else if (command == "L") goLeft();
else if (command == "R") goRight();
else if (command == "I") goAheadRight();
else if (command == "G") goAheadLeft();
//else if (command == "J") goBackRight();
//else if (command == "H") goBackLeft();
/*else if (command == "0") speedCar = 400;
else if (command == "1") speedCar = 470;
else if (command == "2") speedCar = 540;
else if (command == "3") speedCar = 610;
else if (command == "4") speedCar = 680;
else if (command == "5") speedCar = 750;
else if (command == "6") speedCar = 820;
else if (command == "7") speedCar = 890;
else if (command == "8") speedCar = 960;
else if (command == "9") speedCar = 1023;*/
else if (command == "S") stopRobot();
//если освещённость больше 500, то включаются фары
if (val < 500) {
digitalWrite(PIN_LED_1, LOW);
digitalWrite(PIN_LED_2, LOW);
} else {
digitalWrite(PIN_LED_1, HIGH);
digitalWrite(PIN_LED_2, HIGH);
}
}
void HTTP_handleRoot(void) {
String html = "<html><head>"
"<meta charset='UTF-8'>"
"<meta name='viewport' content='width=device-width, initial-scale=1.0'>"
"<style>"
"body {font-family: Arial, sans-serif; background-color: #f0f0f0; color: #333; margin: 0; padding: 0;}"
".container { max-width: 600px; margin: 50px auto; padding: 20px; background-color: #fff; border-radius: 8px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); text-align: center; }"
"h1 { font-size: 24px; margin-bottom: 20px; }"
".button-container { display: flex; flex-direction: column; gap: 10px; }"
".row { display: flex; justify-content: center; gap: 10px; }"
".image-button { background-color: white; color: white; border: none; border-radius: 5px; padding: 15px; font-size: 16px; cursor: pointer; transition: background-color 0.3s, opacity 0.3s; width: 180px; height: 190px; }"
".image-button:hover { opacity: 0.9; }"
".image-button img { width: 100%; height: 100%; object-fit: cover; }"
".image-button-up img { transform: rotate(180deg); }"
".image-button-left img { transform: rotate(90deg); }"
".image-button-right img { transform: rotate(-90deg); }"
".orange { background-color: orange; width: 180px; height: 190px; border: none; }"
"#terminal { background-color: black; color: white; padding: 10px; margin-top: 20px; height: 200px; overflow-y: auto; white-space: pre-wrap; }"
"@media (max-width: 600px) { h1 { font-size: 20px; } .image-button { width: 120px; height: 130px; } .orange { width: 120px; height: 130px; } }"
"</style>"
"<title>Радиоуправляемый танк</title></head><body>"
"<div class='container'><h1>Радиоуправляемый танк</h1>"
"<div class='button-container'>"
"<div class='row'>"
"<button class='image-button image-button-left' onclick=\"sendCommand('I')\">"
"<img src='https://cdn.icon-icons.com/icons2/3991/PNG/512/left_down_arrow_arrow_icon_253889.png' alt='Кнопка' /></button>"
"<button class='image-button image-button-up' onclick=\"sendCommand('F')\">"
"<img src='https://cdn.icon-icons.com/icons2/910/PNG/512/down-arrow_icon-icons.com_71215.png' alt='Кнопка' /></button>"
"<button class='image-button image-button-up' onclick=\"sendCommand('G')\">"
"<img src='https://cdn.icon-icons.com/icons2/3991/PNG/512/left_down_arrow_arrow_icon_253889.png' alt='Кнопка' /></button>"
"</div><div class='row'>"
"<button class='image-button image-button-left' onclick=\"sendCommand('L')\">"
"<img src='https://cdn.icon-icons.com/icons2/910/PNG/512/down-arrow_icon-icons.com_71215.png' alt='Кнопка' /></button>"
"<button class='orange' onclick=\"sendCommand('S')\">Стоп</button>"
"<button class='image-button image-button-right' onclick=\"sendCommand('R')\">"
"<img src='https://cdn.icon-icons.com/icons2/910/PNG/512/down-arrow_icon-icons.com_71215.png' alt='Кнопка' /></button>"
"</div><div class='row'>"
"<button class='image-button image-button-down' onclick=\"sendCommand('B')\">"
"<img src='https://cdn.icon-icons.com/icons2/910/PNG/512/down-arrow_icon-icons.com_71215.png' alt='Кнопка' /></button>"
"</div></div>"
"<div id='terminal'></div>"
"<script>"
"function sendCommand(cmd) {"
" var xhr = new XMLHttpRequest();"
" xhr.open('GET', '/?State=' + cmd, true);"
" xhr.send();"
"}"
"function updateTerminal() {"
" var xhr = new XMLHttpRequest();"
" xhr.open('GET', '/status', true);"
" xhr.onload = function() {"
" if (xhr.status === 200) {"
" document.getElementById('terminal').innerText = xhr.responseText;"
" }"
" };"
" xhr.send();"
"}"
"setInterval(updateTerminal, 1000); // Обновляем каждую секунду"
"</script>"
"</body></html>";
server.send(200, "text/html", html);
}
void HTTP_handleStatus() {
// Считывание значений с датчиков
int lightValue = analogRead(PIN_PHOTO_SENSOR);
//int distanceValue = sonar.ping_cm(); // Считываем расстояние
// int distanceValue = getDistance(); // Получаем расстояние
String led1State = digitalRead(PIN_LED_1) == HIGH ? "ON" : "OFF";
String led2State = digitalRead(PIN_LED_2) == HIGH ? "ON" : "OFF";
String ledStopState = digitalRead(PIN_LED_STOP) == HIGH ? "ON" : "OFF";
// Формирование строки статуса
String status = "Освещенность: " + String(lightValue) + "\n";
//status += "Расстояние до объекта: " + String(distanceValue) + " см\n";
status += "Состояние фары 1: " + led1State + "\n";
status += "Состояние фары 2: " + led2State + "\n";
status += "Состояние заднего фонаря: " + ledStopState + "\n";
// Отправка статуса клиенту
server.send(200, "text/plain", status);
} |
|
0
|