接入小爱控制引脚4
- 通过wifi连接点灯科技
- 将点灯科技设备接入米家
- 小爱同学通过命令发送不同的操作指令控制灯
APP软件有
- 电灯-blinker
- 米家
- 小爱音响
[ESP8266引脚图](ESP8266 GPIO 的指南:引脚图 - 哔哩哔哩 (bilibili.com))
[点灯科技引入](点灯科技 (diandeng.tech))
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
| #define BLINKER_WIFI #define BLINKER_MIOT_LIGHT #define BLINKER_MIOT_OUTLET #define BLINKER_MIOT_SENSOR #define BLINKER_MIOT_FAN #define BLINKER_MIOT_AIR_CONDITION
#include <Blinker.h>
char auth[] = "58347aa10ecb";
char ssid[] = "ChinaNet-aemM";
char pswd[] = "wp907678446";
int colorW = 0;
BlinkerButton Button1("myLamp");
void button1_callback(const String & state) { BLINKER_LOG("get button state: ", state); if (state=="on") { digitalWrite(LED_BUILTIN, LOW); Button1.print("on"); } else if(state=="off"){ digitalWrite(LED_BUILTIN, HIGH); Button1.print("off"); } }
void miotPowerState(const String & state) { BLINKER_LOG("need set power state: ", state); if (state == "on") { digitalWrite(LED_BUILTIN, LOW); Button1.print("on"); BlinkerMIOT.powerState("on"); BlinkerMIOT.print(); } else if (state == "off") { digitalWrite(LED_BUILTIN, HIGH); Button1.print("off"); BlinkerMIOT.powerState("off"); BlinkerMIOT.print(); } }
void miotBright(const String & bright) { BLINKER_LOG("need set brightness: ", bright); colorW = bright.toInt(); BLINKER_LOG("now set brightness: ", colorW); analogWrite(2,100-colorW); BlinkerMIOT.brightness(colorW); BlinkerMIOT.print(); }
void setup() { Serial.begin(115200); BLINKER_DEBUG.stream(Serial); Blinker.begin(auth, ssid, pswd); BlinkerMIOT.attachPowerState(miotPowerState); BlinkerMIOT.attachBrightness(miotBright); Button1.attach(button1_callback); pinMode(LED_BUILTIN, OUTPUT); pinMode(2,OUTPUT); analogWriteRange(100); }
void loop() { Blinker.run(); }
|