//使用ESP-01s制作物联网台灯,blinker-library-master库请自行下载
- #define BLINKER_MIOT_LIGHT
- #define BLINKER_WIFI
- #include <Blinker.h>
- char auth[] = "ff376716aec4";//电灯科技上的密钥
- char ssid[] = "360WiFi-ABDBDF";//你家的WiFi名字
- char pswd[] = "@XINYU404";//你家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);
- pinMode(GPIO,OUTPUT);
- digitalWrite(GPIO,HIGH);
- Blinker.begin(auth, ssid, pswd);
- Button1.attach(button1_callback);
- BlinkerMIOT.attachPowerState(miotPowerState);
- }
- void loop()
- {
- Blinker.run();
- }
复制代码
|