|
代码是下的某音上的爆改车间主任控制灯泡的那一集
#define BLINKER_WIFI
#define BLINKER_MIOT_OUTLET //小爱同学
#include <Blinker.h>
char auth[] = "打码";
char ssid[] = "qiuqiuqiu";
char pswd[] = "打码";
BlinkerButton Button1("btn-on"); //定义按钮数据
BlinkerButton Button2("btn-off");
BlinkerButton Button3("btn-aaa");
bool oState = false;
int counter = 0;
void miotPowerState(const String & state)
{
BLINKER_LOG("need set power state: ", state);
if (state == BLINKER_CMD_ON) { //小爱同学控制开命令
digitalWrite(0, LOW);
BlinkerMIOT.powerState("on");
BlinkerMIOT.print();
oState = true;
}
else if (state == BLINKER_CMD_OFF) { //小爱同学控制关命令
digitalWrite(0,HIGH);
BlinkerMIOT.powerState("off");
BlinkerMIOT.print();
oState = false;
}
}
void miotQuery(int32_t queryCode) //小爱同学控制
{
BLINKER_LOG("MIOT Query codes: ", queryCode);
switch (queryCode)
{
case BLINKER_CMD_QUERY_ALL_NUMBER :
BLINKER_LOG("MIOT Query All");
BlinkerMIOT.powerState(oState ? "on" : "off");
BlinkerMIOT.print();
break;
case BLINKER_CMD_QUERY_POWERSTATE_NUMBER :
BLINKER_LOG("MIOT Query Power State");
BlinkerMIOT.powerState(oState ? "on" : "off");
BlinkerMIOT.print();
break;
default :
BlinkerMIOT.powerState(oState ? "on" : "off");
BlinkerMIOT.print();
break;
}
}
void dataRead(const String & data) // 如果未绑定的组件被触发,则会执行其中内容
{
BLINKER_LOG("Blinker readString: ", data);
Blinker.vibrate();
uint32_t BlinkerTime = millis();
Blinker.print("millis", BlinkerTime);
}
void button1_callback(const String & state) //点灯app内控制按键触发
{
digitalWrite(0,LOW);
BLINKER_LOG("get button staten", state);
}
void button2_callback(const String & state) //点灯app内控制按键触发
{
digitalWrite(0,HIGH);
BLINKER_LOG("get button stateff", state);
}
void button3_callback(const String & state) //点灯app内控制按键触发
{
BLINKER_LOG("get button staten", state);
Blinker.print(state);
if(state=="on"){
digitalWrite(0,LOW);
// Button3.print("on");
}else if(state =="off"){
digitalWrite(0,HIGH);
// Button3.print("off");
}
}
void setup()
{
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
pinMode(0, OUTPUT); //定义io口为输出
digitalWrite(0, LOW); //定义io默认为高电平
Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead);
BlinkerMIOT.attachPowerState(miotPowerState);
BlinkerMIOT.attachQuery(miotQuery);
Button1.attach(button1_callback);
Button2.attach(button2_callback);
Button3.attach(button3_callback);
}
void loop()
{
Blinker.run();
}
上传固件后点灯app设备显示在线,点击按钮开发板上的蓝色指示灯也闪,但是继电器不工作,没有吸合,
开发板是买的这个,供电是5V2A的充电头,点灯科技app设备显示在线,就是继电器不吸合,代码不是很懂。。。不知道是电源的缘故还是固件的原因,还是继电器模块的原因
开发板与继电器模块
供电用的小米充电器5V2A的
点灯app设备在线
|
|