1812z's blog
1812z's blog
[教程]更智能的电脑远程开关机-基于继电器实现物理开机

本文只写最重要要的部分,基础内容请看上篇文章 点击

Part.0-准备材料

需要 1.esp-01s开发板

2.继电器

3.杜邦线

4.各种工具

Part.1-写入源码

源码[抱歉,串行了]
keyboard_arrow_down

#define BLINKER_WIFI #include <Blinker.h> char auth[] = “key”; // 编写:1812z char ssid[] = “wifi”; char pswd[] = “wifi密码”; #define BUTTON_1 “ButtonKey” BlinkerButton Button1(“BUTTON_1”); BlinkerText TEXT1(“tex-s”); BlinkerText TEXT2(“power”); BlinkerText TEXT3(“powerj”); void button1_callback(const String & state) { digitalWrite(0, !digitalRead(0)); BLINKER_LOG(“get button state: “, state); if (state == BLINKER_CMD_BUTTON_TAP) { BLINKER_LOG(“Button tap!”); Button1.icon(“icon_1”); Button1.color(“#00FF00”); Button1.text(“短按”); Button1.print(); Blinker.delay(500); digitalWrite(0, !digitalRead(0)); } else if (state == BLINKER_CMD_BUTTON_PRESSED) { BLINKER_LOG(“Button pressed!”); Button1.icon(“icon_1”); Button1.color(“#FF0000”); Button1.text(“长按中”); Button1.print(); } else if (state == BLINKER_CMD_BUTTON_RELEASED) { BLINKER_LOG(“Button released!”); Button1.icon(“icon_1”); Button1.color(“#FF0000”); Button1.text(“成功长按”); // Button1.text(“Your button name”, “describe”); Button1.print(); } else if (state == BLINKER_CMD_ON) { BLINKER_LOG(“Toggle on!”); Button1.icon(“icon_1”); Button1.color(“#FF0000”); Button1.text(“继电器闭合”); // Button1.text(“Your button name”, “describe”); Button1.print(“on”); } else if (state == BLINKER_CMD_OFF) { BLINKER_LOG(“Toggle off!”); Button1.icon(“icon_1”); Button1.color(“#FF0000”); Button1.text(“继电器断开”); // Button1.text(“Your button name”, “describe”); Button1.print(“off”); } else { BLINKER_LOG(“Get user setting: “, state); Button1.icon(“icon_1”); Button1.color(“#FFFFFF”); Button1.text(“?”); // Button1.text(“Your button name”, “describe”); Button1.print(); } } void dataRead(const String & data) { BLINKER_LOG(“Blinker readString: “, data); Blinker.vibrate(); uint32_t BlinkerTime = millis(); Blinker.print(“millis”, BlinkerTime); } String rts()//计算运行时间 { int rt =Blinker.runTime(); int r,e,f,s; String fh; Blinker.delay(100); if(rt >= 86400)//天数 {r = rt / 86400; e = rt / 3600 – r*24; f = rt / 60 – r*1440 – e*60; s = rt – r*86400 – e*3600 – f*60;} else if(rt >= 3600) {r = 0; e = rt / 3600; f = rt / 60 – e*60; s = rt – e*3600 – f*60;} else {r = 0; e = 0; f = rt / 60; s = rt – f*60;} //BLINKER_LOG(r,” “,e,” “,f,” “,s);//输出数据测试 if(f==0 & e==0 & r==0) {fh = String(“”)+ s +”秒”;} else if(r == 0 & e == 0 ) {fh = String(“”)+ f + “分” + s +”秒”;} else if(r == 0) {fh = String(“”)+ e + “时” + f + “分” + s +”秒”; } else {fh = String(“”)+ r + “天” + e + “时” + f + “分” + s +”秒”;} return(fh); } void heartbeat()//心跳 { TEXT1.print(rts()); } void setup() { Serial.begin(115200); BLINKER_DEBUG.stream(Serial); pinMode(0, OUTPUT); digitalWrite(0, HIGH); pinMode(2, INPUT_PULLUP); Blinker.begin(auth, ssid, pswd); Blinker.attachData(dataRead); Button1.attach(button1_callback); Blinker.attachHeartbeat(heartbeat);//附加心跳 } void loop() { int sensorVal = digitalRead(2); Serial.println(sensorVal); if (sensorVal == LOW) { TEXT2.print(“电源断开”); } else { TEXT2.print(“电源接通”); } int sensorVal2 = digitalRead(0); Serial.println(sensorVal2); Blinker.delay(1500); if (sensorVal2 == HIGH) { TEXT3.print(“断开”); } else { TEXT3.print(“闭合”); } Blinker.run(); }

Part.2-接线

总览

https://img2.moeblog.vip/images/ZpHa.png
大概样子

继电器接线:电脑开机线接com与no(不分顺序)   5v供电接继电器vcc和gnd(分+-)如图

供电必须接主板上常供电的5v
如果外接充电器供电,检测功能会失效

https://img2.moeblog.vip/images/ZQKO.png

开发板部分全部用杜邦线延长到继电器即可 但是GPIO2的线从开发板连接到电脑主板5v+ 继电器上的该孔就空着

https://img2.moeblog.vip/images/ZG2o.png

Part.3-手机app界面

界面配置
keyboard_arrow_down

{¨config¨{¨headerColor¨¨transparent¨¨headerStyle¨¨dark¨¨background¨{¨img¨¨assets/img/bg/f5.jpg¨¨isFull¨»}}¨dashboard¨|{¨type¨¨btn¨¨ico¨¨fad fa-arrow-alt-up¨¨mode¨É¨t0¨¨单击¨¨t1¨¨文本2¨¨bg¨É¨cols¨Ë¨rows¨Ë¨key¨¨BUTTON_1¨´x´É´y´Ë¨speech¨|{¨cmd¨¨开关电脑¨¨act¨¨tap¨}÷¨lstyle¨Ê¨clr¨¨#076EEF¨}{ßA¨tex¨ßF¨继电器控制¨ßH¨已接入电脑¨ßJÉßC¨fad fa-digital-tachograph¨ßKÍßLËßM´´´x´Ë´y´ËßO|÷ßTÌßUßV}{ßAßWßF¨文本1¨ßH¨开发板运行时间¨ßJÉßC¨fad fa-database¨ßKÍßLËßM¨tex-s¨´x´Í´y´ÍßO|÷ßTÌßUßV}{ßAßWßF¨状态中心¨ßH´´ßJÉßC¨fad fa-power-off¨ßKËßLËßM´´´x´Ï´y´ËßO|÷ßTËßUßV}{ßAßWßF¨调试—->¨ßH¨手动控制¨ßJÉßC¨fad fa-lock¨ßKËßLËßM´´´x´É´y´ÏßO|÷ßUßVßTË}{ßAßBßC¨fal fa-power-off¨ßEÊßFßhßHßIßJÉßKËßLËßMßN´x´Ë´y´ÏßO|÷¨cus¨¨off¨ßTÊ}{ßAßWßFßaßH¨继电器操作¨ßJÉßC¨fal fa-font¨ßKÍßLËßMßN´x´É´y´ÍßO|÷ßTÌßUßV}{ßAßWßFßaßH¨电脑电源状态¨ßJÉßC¨fad fa-server¨ßKËßLËßM¨power¨´x´Í´y´ÏßO|÷ßTËßUßV}{ßAßWßFßaßH¨继电器状态¨ßJÉßCßZßKËßLËßM¨powerj¨´x´Ï´y´ÏßO|÷ßTËßUßV}{ßAßWßF¨闪烁¨ßH¨为开机¨ßJÉßCßDßKËßLËßM´´´x´Í´y´ÑßO|÷ßTË}{ßAßWßF¨操作和真的开机¨ßH¨长按和短按¨ßJÉßCßnßKÍßLËßM¨tex-l0w¨´x´É´y´ÉßO|÷ßTÌ}{ßAßWßF¨键一样¨ßHßIßJÉßCßnßKËßLËßM¨tex-az0¨´x´Í´y´ÉßO|÷ßTË}÷¨actions¨|¦ßP¦¨switch¨‡¨text¨‡´on´¨打开?name¨ßl¨关闭?name¨—÷¨triggers¨|{¨source¨ß11¨source_zh¨¨开关状态¨¨state¨|´on´ßl÷¨state_zh¨|´打开´´关闭´÷}÷}

https://img2.moeblog.vip/images/ZK7v.jpg

电脑开机检测不太好,不过能用,awa

后续加入wol网络开机

赞赏
如有问题请评论
首页      教程      [教程]更智能的电脑远程开关机-基于继电器实现物理开机

1812z

文章作者

发表评论

textsms
account_circle
email

1812z's blog

[教程]更智能的电脑远程开关机-基于继电器实现物理开机
本文只写最重要要的部分,基础内容请看上篇文章 点击 Part.0-准备材料 需要 1.esp-01s开发板 2.继电器 3.杜邦线 4.各种工具 Part.1-写入源码 源码[抱歉,串行了]keyb…
扫描二维码继续阅读
2020-08-10