#define BLINKER_MIOT_LIGHT
#define BLINKER_WIFI
#include <Blinker.h>
#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
//needed for library
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <CustomWiFiManager.h> //https://github.com/tzapu/WiFiManager
char auth[] = "e4858d05dae6";//电灯科技上的密钥
char ssid[] = "";//你家的WiFi名字
char pswd[] = "";//你家WiFi的密码
int GPIO=0;
#define BUTTON_1 "ButtonKey"
BlinkerButton Button1("anniu");//这个anniu必须要和电灯科技上的按键相同
void button1_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
digitalWrite(GPIO,!digitalRead(GPIO));
Blinker.vibrate();
}
void miotPowerState(const String & state)
{
BLINKER_LOG("need set power state: ",state);
if (state == BLINKER_CMD_OFF) {
digitalWrite(GPIO, HIGH);
BlinkerMIOT.powerState("off");
BlinkerMIOT.print();
}
else if (state == BLINKER_CMD_ON) {
digitalWrite(GPIO, LOW);
BlinkerMIOT.powerState("on");
BlinkerMIOT.print();
}
}
void setup() {
Serial.begin(115200);
WiFiManager wifiManager;
wifiManager.autoConnect("AutoConnectAP");
pinMode(GPIO,OUTPUT);
digitalWrite(GPIO,HIGH);
Blinker.begin(auth, ssid, pswd);
Button1.attach(button1_callback);
BlinkerMIOT.attachPowerState(miotPowerState);
Serial.println("connected...yeey :)");
}
void loop()
{
Blinker.run();
}
电灯科技 配网 小爱同学
最新推荐文章于 2024-01-12 11:56:41 发布