#define BLINKER_WIFI
#include <Blinker.h>
#include <ESP8266WiFi.h>
char ssid[] = "webserver";      //你的WIFI名
char pswd[] = "www.360xyz.cn";  //你的WIFI密码
char auth[] = "0371ea173c72";
#define D1 5
#define D2 4
#define D5 14
#define D6 12
#define D7 13
#define D8 15
int vibrationTime = 3;  //震动时间

BlinkerButton Button1("btn-hog");
BlinkerButton Button2("btn-1vs");
BlinkerButton Button3("btn-ed9");
BlinkerButton Button4("btn-cjh");
BlinkerButton Button5("btn-94j");
BlinkerButton Button6("btn-u0a");
void setup() {
  pinMode(D1, OUTPUT);
  pinMode(D2, OUTPUT);
  pinMode(D5, OUTPUT);
  pinMode(D6, OUTPUT);
  pinMode(D7, OUTPUT);
  pinMode(D8, OUTPUT);
  digitalWrite(D1, LOW);
  digitalWrite(D2, LOW);
  digitalWrite(D5, LOW);
  digitalWrite(D6, LOW);
  digitalWrite(D7, LOW);
  digitalWrite(D8, LOW);
  Serial.begin(115200);
  Blinker.begin(auth, ssid, pswd);
  Button1.attach(button1_callback);
  Button2.attach(button2_callback);
  Button3.attach(button3_callback);
  Button4.attach(button4_callback);
  Button5.attach(button5_callback);
  Button6.attach(button6_callback);
  Blinker.attachData(dataRead);
}

void loop() {
  Blinker.run();
}
void button1_callback(const String& state) {
  BLINKER_LOG("get button state: ", state);
  digitalWrite(D1, HIGH);
  Button1.color("#00FF00");
  Button1.text("1#正在震动");
  Button1.print();
  delay(vibrationTime * 1000);
  digitalWrite(D1, LOW);
  Button1.color("#000000");
  Button1.text("1#已停止");
  Button1.print();
}

//停止
void button2_callback(const String& state) {
  BLINKER_LOG("get button state: ", state);
  digitalWrite(D2, HIGH);
  Button2.color("#00FF00");
  Button2.text("2#正在震动");
  Button2.print();
  delay(vibrationTime * 1000);
  digitalWrite(D2, LOW);
  Button2.color("#000000");
  Button2.text("2#已停止");
  Button2.print();
}
//下降
void button3_callback(const String& state) {
  BLINKER_LOG("get button state: ", state);
  digitalWrite(D5, HIGH);
  Button3.color("#00FF00");
  Button3.text("3#正在震动");
  Button3.print();
  delay(vibrationTime * 1000);
  digitalWrite(D5, LOW);
  Button3.color("#000000");
  Button3.text("3#已停止");
  Button3.print();
}
void button4_callback(const String& state) {
  BLINKER_LOG("get button state: ", state);
  digitalWrite(D6, HIGH);
  Button4.color("#00FF00");
  Button4.text("4#正在震动");
  Button4.print();
  delay(vibrationTime * 1000);
  digitalWrite(D6, LOW);
  Button4.color("#000000");
  Button4.text("4#已停止");
  Button4.print();
}

void button5_callback(const String& state) {
  BLINKER_LOG("get button state: ", state);
  digitalWrite(D7, HIGH);
  Button5.color("#00FF00");
  Button5.text("5#正在震动");
  Button5.print();
  delay(vibrationTime * 1000);
  digitalWrite(D7, LOW);
  Button5.color("#000000");
  Button5.text("5#已停止");
  Button5.print();
}
void button6_callback(const String& state) {
  BLINKER_LOG("get button state: ", state);
  digitalWrite(D8, HIGH);
  Button6.color("#00FF00");
  Button6.text("6#正在震动");
  Button6.print();
  delay(vibrationTime * 1000);
  digitalWrite(D8, LOW);
  Button6.color("#000000");
  Button6.text("6#已停止");
  Button6.print();
}
void dataRead(const String& data) {
  BLINKER_LOG("Blinker readString: ", data);
  int tmp = data.toInt();
  vibrationTime=tmp;
}