小爱同学控制不了ESP8266-01s
电灯科技可以控制ESP8266-01s继电器吸合,添加到米家APP后唤醒小爱同学控制不了#define BLINKER_MIOT_LIGHT#define BLINKER_WIFI
#include <Blinker.h>
char auth[] = "309b1594a496";//电灯科技上的密钥
char ssid[] = "绿*泡";//你家的WiFi名字
char pswd[] = "2**P36TG8Z";//你家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();
}
创建设备时,选择 阿里云broker,如果还是不行,请看设备端调试信息
页:
[1]