├── .DS_Store ├── README.md └── blinker_app_xiaoai └── blinker_app_xiaoai.ino /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baogaichejian/blinker_xiaoai/e45f827c0970d44c4c541e8633753575d1cd2c78/.DS_Store -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # blinker_xiaoai 2 | # 这是点灯科技的平台联动小爱同学的控制esp8266的代码 3 | # 控制继电器开机电动模式 4 | # 代码是点灯科技官方文档中的代码重新整合后修改而成 5 | # 详细资料请查看点灯科技官方文档 6 | -------------------------------------------------------------------------------- /blinker_app_xiaoai/blinker_app_xiaoai.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_WIFI 2 | #define BLINKER_MIOT_OUTLET //小爱同学 3 | 4 | #include 5 | 6 | char auth[] = "********"; //设备key 7 | char ssid[] = "********"; //路由器wifi ssid 8 | char pswd[] = "********"; //路由器wifi 密码 9 | BlinkerButton Button1("btn-abc"); //定义按钮键名 10 | bool oState = false; 11 | int counter = 0; 12 | void miotPowerState(const String & state) 13 | { 14 | BLINKER_LOG("need set power state: ", state); 15 | 16 | if (state == BLINKER_CMD_ON) { //小爱同学控制开命令 此处修改为点动模式,适合按钮操作, 17 | digitalWrite(0, LOW); 18 | delay(200); 19 | digitalWrite(0, HIGH); 20 | BlinkerMIOT.powerState("on"); 21 | 22 | BlinkerMIOT.print(); 23 | 24 | oState = true; 25 | } 26 | else if (state == BLINKER_CMD_OFF) { //小爱同学控制关命令 此处修改为点动模式,适合按钮操作, 27 | digitalWrite(0,LOW); 28 | delay(200); 29 | digitalWrite(0, HIGH); 30 | BlinkerMIOT.powerState("off"); 31 | 32 | BlinkerMIOT.print(); 33 | 34 | oState = false; 35 | } 36 | } 37 | 38 | void miotQuery(int32_t queryCode) //小爱同学控制 39 | { 40 | BLINKER_LOG("MIOT Query codes: ", queryCode); 41 | 42 | switch (queryCode) 43 | { 44 | case BLINKER_CMD_QUERY_ALL_NUMBER : 45 | BLINKER_LOG("MIOT Query All"); 46 | BlinkerMIOT.powerState(oState ? "on" : "off"); 47 | BlinkerMIOT.print(); 48 | break; 49 | case BLINKER_CMD_QUERY_POWERSTATE_NUMBER : 50 | BLINKER_LOG("MIOT Query Power State"); 51 | BlinkerMIOT.powerState(oState ? "on" : "off"); 52 | BlinkerMIOT.print(); 53 | break; 54 | default : 55 | BlinkerMIOT.powerState(oState ? "on" : "off"); 56 | BlinkerMIOT.print(); 57 | break; 58 | } 59 | } 60 | 61 | void dataRead(const String & data) // 如果未绑定的组件被触发,则会执行其中内容 62 | { 63 | BLINKER_LOG("Blinker readString: ", data); 64 | 65 | Blinker.vibrate(); 66 | 67 | uint32_t BlinkerTime = millis(); 68 | 69 | Blinker.print("millis", BlinkerTime); 70 | } 71 | 72 | void button1_callback(const String & state) //点灯app内控制按键触发 73 | { 74 | BLINKER_LOG("get button state: ", state); 75 | digitalWrite(0,LOW); 76 | delay(200); 77 | digitalWrite(0, HIGH); 78 | } 79 | 80 | void setup() 81 | { 82 | Serial.begin(115200); 83 | BLINKER_DEBUG.stream(Serial); 84 | 85 | pinMode(0, OUTPUT); //定义io口为输出 86 | digitalWrite(0, HIGH); //定义io默认为高电平 87 | 88 | Blinker.begin(auth, ssid, pswd); 89 | Blinker.attachData(dataRead); 90 | 91 | BlinkerMIOT.attachPowerState(miotPowerState); 92 | BlinkerMIOT.attachQuery(miotQuery); 93 | Button1.attach(button1_callback); 94 | } 95 | 96 | void loop() 97 | { 98 | Blinker.run(); 99 | } 100 | --------------------------------------------------------------------------------