├── .gitattributes ├── README.md └── blinker_xiaoai_dengpao.ino /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # blinker_xiaoai_dengpao 2 | #配套视频的是抖音自制wifi灯泡那集 3 | 4 | #这个是使用电灯科技代码控制esp8266控制继电器作为开关使用的代码 5 | 6 | #默认开灯 7 | -------------------------------------------------------------------------------- /blinker_xiaoai_dengpao.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_WIFI 2 | #define BLINKER_MIOT_OUTLET //小爱同学 3 | 4 | #include 5 | 6 | char auth[] = "*******"; 7 | char ssid[] = "*******"; 8 | char pswd[] = "*******"; 9 | BlinkerButton Button1("btn-on"); //定义按钮数据 10 | BlinkerButton Button2("btn-off"); 11 | bool oState = false; 12 | int counter = 0; 13 | void miotPowerState(const String & state) 14 | { 15 | BLINKER_LOG("need set power state: ", state); 16 | 17 | if (state == BLINKER_CMD_ON) { //小爱同学控制开命令 18 | digitalWrite(0, LOW); 19 | 20 | BlinkerMIOT.powerState("on"); 21 | 22 | BlinkerMIOT.print(); 23 | 24 | oState = true; 25 | } 26 | else if (state == BLINKER_CMD_OFF) { //小爱同学控制关命令 27 | digitalWrite(0,HIGH); 28 | 29 | BlinkerMIOT.powerState("off"); 30 | 31 | BlinkerMIOT.print(); 32 | 33 | oState = false; 34 | } 35 | } 36 | 37 | void miotQuery(int32_t queryCode) //小爱同学控制 38 | { 39 | BLINKER_LOG("MIOT Query codes: ", queryCode); 40 | 41 | switch (queryCode) 42 | { 43 | case BLINKER_CMD_QUERY_ALL_NUMBER : 44 | BLINKER_LOG("MIOT Query All"); 45 | BlinkerMIOT.powerState(oState ? "on" : "off"); 46 | BlinkerMIOT.print(); 47 | break; 48 | case BLINKER_CMD_QUERY_POWERSTATE_NUMBER : 49 | BLINKER_LOG("MIOT Query Power State"); 50 | BlinkerMIOT.powerState(oState ? "on" : "off"); 51 | BlinkerMIOT.print(); 52 | break; 53 | default : 54 | BlinkerMIOT.powerState(oState ? "on" : "off"); 55 | BlinkerMIOT.print(); 56 | break; 57 | } 58 | } 59 | 60 | void dataRead(const String & data) // 如果未绑定的组件被触发,则会执行其中内容 61 | { 62 | BLINKER_LOG("Blinker readString: ", data); 63 | 64 | Blinker.vibrate(); 65 | 66 | uint32_t BlinkerTime = millis(); 67 | 68 | Blinker.print("millis", BlinkerTime); 69 | } 70 | 71 | void button1_callback(const String & state) //点灯app内控制按键触发 72 | { 73 | 74 | digitalWrite(0,LOW); 75 | BLINKER_LOG("get button state:on", state); 76 | 77 | 78 | } 79 | void button2_callback(const String & state) //点灯app内控制按键触发 80 | { 81 | 82 | digitalWrite(0,HIGH); 83 | BLINKER_LOG("get button state:off", state); 84 | 85 | 86 | } 87 | 88 | 89 | 90 | 91 | 92 | void setup() 93 | { 94 | Serial.begin(115200); 95 | BLINKER_DEBUG.stream(Serial); 96 | 97 | pinMode(0, OUTPUT); //定义io口为输出 98 | digitalWrite(0, LOW); //定义io默认为高电平 99 | 100 | Blinker.begin(auth, ssid, pswd); 101 | Blinker.attachData(dataRead); 102 | 103 | BlinkerMIOT.attachPowerState(miotPowerState); 104 | BlinkerMIOT.attachQuery(miotQuery); 105 | Button1.attach(button1_callback); 106 | Button2.attach(button2_callback); 107 | } 108 | 109 | void loop() 110 | { 111 | Blinker.run(); 112 | } 113 | --------------------------------------------------------------------------------