75 lines
1.8 KiB
Arduino
75 lines
1.8 KiB
Arduino
|
#define BLINKER_ESP_TASK
|
|||
|
#define BLINKER_WIFI
|
|||
|
|
|||
|
#define ON HIGH
|
|||
|
#define OFF LOW
|
|||
|
|
|||
|
#include <Blinker.h>
|
|||
|
#include <WiFi.h>
|
|||
|
#include <freertos/FreeRTOSConfig.h>
|
|||
|
#include "httpslei.h"
|
|||
|
|
|||
|
void button1_callback(const String & state);
|
|||
|
void none_callback(const String & data);
|
|||
|
void ot_callback(const String & state);
|
|||
|
|
|||
|
char *auth = "05e4cd637e1f";
|
|||
|
char *ssid = "101_lei";
|
|||
|
char *pswd = "leiyun1314";
|
|||
|
|
|||
|
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(LED_BUILTIN, OUTPUT);
|
|||
|
BLINKER_TAST_INIT(); //<2F><><EFBFBD><EFBFBD>Blinker<65><72><EFBFBD>ӵĺ<D3B5><C4BA><EFBFBD>
|
|||
|
Blinker.attachData(none_callback); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>룬<EFBFBD><EBA3AC><EFBFBD><EFBFBD>û<EFBFBD>аĿؼ<C4BF><D8BC>Ļص<C4BB><D8B5><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
httpsOtaTurnOn();
|
|||
|
while (!Blinker.connected()) {
|
|||
|
Serial.printf("connect to ssid: %s failed\n",ssid);
|
|||
|
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"){ //<2F><><EFBFBD><EFBFBD>
|
|||
|
digitalWrite(LED_BUILTIN,ON);
|
|||
|
BLINKER_LOG("get button state:", state);
|
|||
|
Button1.icon("fa-light fa-lightbulb-on");
|
|||
|
Button1.print("on");
|
|||
|
}else{ //<2F>ص<EFBFBD>
|
|||
|
digitalWrite(LED_BUILTIN,OFF);
|
|||
|
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");
|
|||
|
httpsOtaStart();
|
|||
|
}else if (state == "off")
|
|||
|
{
|
|||
|
ButtonOta.print("off");
|
|||
|
}
|
|||
|
}
|