forked from hs3city/ninja-stopwatch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
doom_stopper.ino
73 lines (60 loc) · 1.69 KB
/
doom_stopper.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
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
const char* ssid = "3Maker_wifi";
const char* password = "pass";
String serverName = "http://192.168.8.102:8000/start";
int ledpin = 5; // D1(gpio5)
int button = 4; //D2(gpio4)
int buttonState=0;
void setup() {
pinMode(ledpin, OUTPUT);
pinMode(button, INPUT);
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("Connecting");
while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to WiFi network with IP Address: ");
Serial.println(WiFi.localIP());
Serial.println("Timer set to 5 seconds (timerDelay variable), it will take 5 seconds before publishing the first reading.");
}
void loop() {
buttonState=digitalRead(button); // put your main code here, to run repeatedly:
if (buttonState == 1)
{
digitalWrite(ledpin, LOW);
delay(200);
}
if (buttonState==0)
{
digitalWrite(ledpin, HIGH);
if(WiFi.status()== WL_CONNECTED){
WiFiClient client;
HTTPClient http;
String serverPath = serverName;
// Your Domain name with URL path or IP address with path
http.begin(client, serverPath.c_str());
// Send HTTP GET request
int httpResponseCode = http.GET();
if (httpResponseCode>0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
String payload = http.getString();
Serial.println(payload);
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
// Free resources
http.end();
}
else {
Serial.println("WiFi Disconnected");
}
delay(200);
}
}