-
Notifications
You must be signed in to change notification settings - Fork 1
/
esp8266.ino
63 lines (51 loc) · 1.11 KB
/
esp8266.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
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
const char *ssid = "your-wifi-ssid";
const char *password = "your-wifi-password";
const char *host = "server-ip";
const uint16_t port = 3000;
const uint8_t input = 5;
void setup()
{
Serial.begin(74880);
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
pinMode(input, INPUT_PULLUP);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(200);
Serial.print(".");
}
Serial.println("\r\nWiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void loop()
{
static bool wasDoorOpen = digitalRead(input);
bool isDoorOpen = digitalRead(input);
if (!wasDoorOpen && isDoorOpen)
{
gg();
}
wasDoorOpen = isDoorOpen;
delay(1);
}
void gg()
{
HTTPClient http;
http.begin("http://192.168.1.9:3000/20gg");
int httpCode = http.GET();
if (httpCode == 200)
{
Serial.println("GG");
}
else
{
Serial.println("Game over");
}
http.end();
}