|
本帖最后由 suen.sun 于 2020-4-17 21:31 编辑
1.mini D1 wifi ESP-12F N ESP8266开发板
2.1路 5V继电器模块 高电平触发
3.AMS1117-3.3V原装 SOT-223 稳压芯片4. 10uf电容两只
无电路图,参考抖音 暴改车间主任 视频
esp12f和继电器从电脑主机ATX电源紫色线取常电5V, 检测开机状态是通过ATX电源中任意红色电线的电平(稳压管、滤波)
继电器输出并连电脑主板开机线,模拟点按电源键。
小米手机可以在米家APP绑定其它平台设备(点灯科技);
小爱同学APP里新增个人训练-控制设备,比如“打开电脑”指令为打开绑定的插座设备。即可打开电脑。
*:关闭电脑需要设置windows电源按键为关机(或者休眠)。
[mw_shl_code=arduino,true]
#define BLINKER_WIFI
#define BLINKER_ESP_SMARTCONFIG //开启智能配网
#define BLINKER_MIOT_OUTLET //模拟为小爱同学控制的插座
#define BLINKER_ALIGENIE_OUTLET //模拟为天猫精灵控制的插座
#define OUT_PORT 4 //接继电器信号
#define CHK_PORT 12 //检测是否有高电平(高电平即电脑已开机)
#include <Blinker.h>
#include <Ticker.h>
Ticker myTicker;
int count = 0;
uint32_t lstPw = 0; //默认是关机态
char auth[] = "******";//设备code
#define btn_key "btn_swt"
BlinkerButton BtnRemote(btn_key);
void switchChange(int32_t stateCodeSetting) {
uint32_t nowPw = digitalRead(CHK_PORT);
if ((nowPw == HIGH && stateCodeSetting == 1) || (nowPw == LOW && stateCodeSetting == 0)) {
return;
}
digitalWrite(OUT_PORT, HIGH);
delay(200);
digitalWrite(OUT_PORT, LOW);
}
void btn_callback(const String & state)
{
BLINKER_LOG("Button pressed!");
switchChange(lstPw ? 0 : 1);
}
void aligeniePowerState(const String & state)
{
if (state == BLINKER_CMD_ON) {
switchChange(1);
BlinkerAliGenie.powerState(lstPw ? "on" : "off");
BlinkerAliGenie.print();
}
else if (state == BLINKER_CMD_OFF) {
switchChange(0);
BlinkerAliGenie.powerState(lstPw ? "on" : "off");
BlinkerAliGenie.print();
}
}
void aligenieQuery(int32_t queryCode)
{
lstPw = digitalRead(CHK_PORT);
switch (queryCode)
{
case BLINKER_CMD_QUERY_ALL_NUMBER :
BLINKER_LOG("AliGenie Query All");
BlinkerAliGenie.powerState(lstPw ? "on" : "off");
BlinkerAliGenie.print();
break;
case BLINKER_CMD_QUERY_POWERSTATE_NUMBER :
BLINKER_LOG("AliGenie Query Power State");
BlinkerAliGenie.powerState(lstPw ? "on" : "off");
BlinkerAliGenie.print();
break;
default :
BlinkerAliGenie.powerState(lstPw ? "on" : "off");
BlinkerAliGenie.print();
break;
}
}
void miotPowerState(const String & state)
{
if (state == BLINKER_CMD_ON) {
switchChange(1);
BlinkerMIOT.powerState(lstPw ? "on" : "off");
BlinkerMIOT.print();
} else if (state == BLINKER_CMD_OFF) {
switchChange(0);
BlinkerMIOT.powerState(lstPw ? "on" : "off");
BlinkerMIOT.print();
}
}
void miotQuery(int32_t queryCode)
{
lstPw = digitalRead(CHK_PORT);
switch (queryCode)
{
case BLINKER_CMD_QUERY_ALL_NUMBER :
BLINKER_LOG("MIOT Query All");
BlinkerMIOT.powerState(lstPw ? "on" : "off");
BlinkerMIOT.print();
break;
case BLINKER_CMD_QUERY_POWERSTATE_NUMBER :
BLINKER_LOG("MIOT Query Power State");
BlinkerMIOT.powerState(lstPw ? "on" : "off");
BlinkerMIOT.print();
break;
default :
BlinkerMIOT.powerState(lstPw ? "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 tickHandle() {
count++;
}
void heartbeat() {
uint32_t nowPw = digitalRead(CHK_PORT);
BtnRemote.text(nowPw ? "开机" : "关机");
BtnRemote.print(nowPw ? "on" : "off");
BLINKER_LOG("反馈电平:", nowPw);
}
void setup()
{
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
pinMode(CHK_PORT, INPUT);
pinMode(OUT_PORT, OUTPUT);
digitalWrite(OUT_PORT, LOW);
lstPw = digitalRead(CHK_PORT);
Blinker.begin(auth);
Blinker.attachData(dataRead);
BlinkerMIOT.attachPowerState(miotPowerState);
BlinkerMIOT.attachQuery(miotQuery);
BlinkerAliGenie.attachPowerState(aligeniePowerState);
BlinkerAliGenie.attachQuery(aligenieQuery);
BtnRemote.attach(btn_callback);
myTicker.attach(4, tickHandle);//4s ticked
Blinker.attachHeartbeat(heartbeat);
}
void reconnect() {
BLINKER_LOG("Reconnecting MQTT...");
if (!Blinker.connected()) {
Blinker.connect();
count = 0;
}
}
void loop()
{
Blinker.run();
if (count >= 5) {
if (!Blinker.connected()) {
reconnect();
} else {
count = 0;
}
}
uint32_t nowPw = digitalRead(CHK_PORT);
if (nowPw != lstPw) {
BtnRemote.text(nowPw ? "开机" : "关机");
BtnRemote.print(nowPw ? "on" : "off");
BLINKER_LOG("变化电平:", nowPw);
}
lstPw = nowPw;
}[/mw_shl_code]
|
-
-
|