# 1 "c:\\Users\\32244\\Desktop\\BIlinkerAndHttpsOta\\BIlinkerAndHttpsOta.ino"







# 9 "c:\\Users\\32244\\Desktop\\BIlinkerAndHttpsOta\\BIlinkerAndHttpsOta.ino" 2
# 10 "c:\\Users\\32244\\Desktop\\BIlinkerAndHttpsOta\\BIlinkerAndHttpsOta.ino" 2
# 11 "c:\\Users\\32244\\Desktop\\BIlinkerAndHttpsOta\\BIlinkerAndHttpsOta.ino" 2
# 12 "c:\\Users\\32244\\Desktop\\BIlinkerAndHttpsOta\\BIlinkerAndHttpsOta.ino" 2

void button1_callback(const String & state);
void none_callback(const String & data);
void ot_callback(const String & state);

char *auth = "c7f09e6ce624";
char *ssid = "101_lei";
char *pswd = "leiyun1314";
const String version = "v1";

BlinkerButton Button1("btn-abc",button1_callback);
BlinkerButton ButtonOta("ota",ot_callback);
BlinkerNumber Num("num-yr0");
//////////////////////////////
void setup() {
  Serial.begin(115200);
  Blinker.begin(auth, ssid, pswd);
  pinMode(5, 0x03);
  BLINKER_TAST_INIT(); //保持Blinker连接的函数
  Blinker.attachData(none_callback); //绑定数据输入，但是没有绑定的控件的回调函数
  httpsOtaTurnOn();
  Serial.printf("connect to ssid: %s .\n",ssid);
  while (!Blinker.connected()) {
    Serial.printf(".");
    delay(1000);
    }
}
/****************************/
void loop(){
  delay(5000);
}
//////////////////////////////////

void button1_callback(const String & state){
  static int cont = 0;

  if(cont<100) cont++;
  else cont = 0;
  Serial.println("Firmware online version");
  if(state=="on"){ //开灯
    digitalWrite(5,0x1);
    BLINKER_LOG("get button state:", state);
    Button1.icon("fa-light fa-lightbulb-on");
    Button1.print("on");
  }else{ //关灯
    digitalWrite(5,0x0);
    BLINKER_LOG("get button state:", state);
    Button1.icon("fa-light fa-lightbulb");
    Button1.print("off");
  }
  Num.print(cont);
}
void none_callback(const String & data){

    Serial.println(data.c_str());
}
void ot_callback(const String & state){
  if (state=="on")
  {
    Blinker.print("hello\n");
    ButtonOta.print("on");
    int code = checkNewOTA(version);
    if (code==HTTP_CODE_OK || code == HTTP_CODE_MOVED_PERMANENTLY){
      httpsOtaStart();
    }
  }else if (state == "off"){
    ButtonOta.print("off");
  }
}
