
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
WiFiClient wificlient;
int d5 = 14;
int d6 = 12;
int d8 = 15;  //wifi 连接成gas指示灯
void setup() {
  Serial.begin(115200);
  pinMode(d5, INPUT_PULLUP);
  pinMode(d6, OUTPUT);
  pinMode(d8, OUTPUT);
  digitalWrite(d6, LOW);
  digitalWrite(d8, LOW);
  WiFi.begin("webserver", "www.nobiggie.cn");
  delay(500);
  WiFi.mode(WIFI_STA);
  while (1) {
    delay(500);
    Serial.print(" . ");
    if (WiFi.status() == WL_CONNECTED) {
      break;
    }
  }
  Serial.println("FlashConnetWifi->connet");
  digitalWrite(d8, HIGH);
  delay(500);
}

void loop() {
  // put your main code here, to run repeatedly:
  if (digitalRead(d5) == LOW) {
    String a = esp8266Get("http://192.168.1.2:8080/auth/delay");
    if (a.length() > 0) {
      Serial.println(a);
      int aint = a.toInt();
      int aa = aint * 1000;
      digitalWrite(D6, HIGH);
      delay(aa);
      digitalWrite(D6, LOW);
    }
  }
}
String esp8266Get(String string) {
  HTTPClient http;
  String response;
  http.begin(wificlient, string);
  http.setTimeout(2000);
  int httpCode = http.GET();
  // httpCode will be negative on error
  if (httpCode == 200) {
    response = http.getString();
    return response;
  } else {
    return "";
  }
  http.end();
}