-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBellTaskerCamera.ino
More file actions
182 lines (88 loc) · 3.66 KB
/
BellTaskerCamera.ino
File metadata and controls
182 lines (88 loc) · 3.66 KB
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
/* !!!! NoneMCU 1.0 (ESP-12E Module), 80 MHz, 115200, 4M(3M SPIFFS) !!!!!
Tasker Network Event Server
*/
#include <ESP8266WiFi.h>
#include <Streaming.h> // консоль
//#include <ESP8266HTTPClient.h>
#include <Metro.h> // Подключаем библиотеку timer
#define ConsoleComm 1
const byte interruptPin = D1;
const char* ssid = "xxx"; // SSID wifi точки
const char* password = "xxx"; //пароль на wifi точку
const char* host = "xxx.xxx.xxx.xxx"; // ip планшета
bool bell_switch = false; // храним состояние кнопки звонка
bool switch_ignore = false; //флаг начала игнорирования повторного нажатия на кнопку звонка, чтобы не запускать прогу всякий раз
//HTTPClient http;
WiFiClient client;
const int httpPort = xxxx; //порт куда отсылаем POST запрос
Metro timer_bell_ignore = Metro(120000); // Создаем ссылку на таймер не реагирования на однократное нажатие на звонок, чтобы кучу раз не запускать прогу;
void setup() {
Serial.begin(115200);
delay(10);
// Connect to WiFi network
#if ConsoleComm
Serial << "Connecting to "<< ssid << endl;
#endif
WiFi.mode(WIFI_STA); // отключаем AP
WiFi.begin(ssid, password);
#if ConsoleComm
Serial <<"" << "WiFi Connected" << endl;
// Print the IP address
Serial << "IP Address: "<< WiFi.localIP() << endl;
#endif
attachInterrupt(digitalPinToInterrupt(interruptPin), detect_switch, CHANGE);
}
void loop() {
// если кто-то нажал кнопку мы вызываем прогу на планшете, но не чаще 1 раз в timer_bell_ignore мин.
if (bell_switch && !switch_ignore) {
switch_ignore = true;
#if ConsoleComm
Serial << "Bell switch:"<< bell_switch << " Switch_ignore:"<< switch_ignore << endl;
#endif
sendPOST();
bell_switch = false;
}
if (timer_bell_ignore.check() && switch_ignore) {
#if ConsoleComm
Serial << "timer_bell_ignore switch! bell_switch:"<< bell_switch << "switch_ignore:"<< switch_ignore << endl;
#endif
bell_switch = false;
switch_ignore = false; //сбрасываем ключ
}
}
//формируем и отправляем POST запрос
void sendPOST()
{
#if ConsoleComm
Serial << "Prepare POST request... "<< endl;
#endif
if (!client.connect(host, httpPort)) {
#if ConsoleComm
Serial.println("connection failed");
#endif
return;
}
//строка с данными POST запроса
String data = "say"; // слово, что посылаем в POST запросе
// Send request to the server:
client.println("POST / HTTP/1.1");
client.println("Host: server_name");
client.println("Accept: */*");
client.println("Content-Type: application/x-www-form-urlencoded");
client.print("Content-Length: ");
client.println(data.length());
client.println();
client.print(data);
delay(500); // Can be changed
if (client.connected()) {
client.stop(); // DISCONNECT FROM THE SERVER
}
#if ConsoleComm
Serial.println();
Serial.println("closing connection");
#endif
}
//********************обработчики прерываний*******************************
void detect_switch() { // обработка внешнего прерывания. Сработает по переднему фронту
bell_switch = true; // кто-то нажал на кнопку звонка
}