B4R Question ESP8266 to turn on/off PC?

susu

Well-Known Member
Licensed User
Longtime User
Hi,
I'm totally new to B4R. I read some tutorials with ESP8266 and just wonder can ESP8266 do this:
Connect 2 Power Button pins from PC mainboard to ESP8266 then control ESP8266 to turn on/off my PC over internet?

If it's not possible, could you please suggest another cheap/easy way to turn on/off PC? Thank you so much.
 

jboavida

Member
Licensed User
Longtime User
WOL (Wakeup On Lan)... Check your bios, activate it, redirect your router ports and send the magic packet from any PC, MAC or Android...
Google for Wake-on-Lan...
 
Upvote 0

susu

Well-Known Member
Licensed User
Longtime User
WOL (Wakeup On Lan)... Check your bios, activate it, redirect your router ports and send the magic packet from any PC, MAC or Android...
Google for Wake-on-Lan...
I know Wake-on-Lan but sometime I need to shutdown/restart PC when it hang (can't not remote access). The only way is long press the power button then press it again to turn on.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
You need to figure out if your MB power button pins expect a Low (to gnd) or a high (to vcc) input, the rest should be pretty easy
 
Upvote 0

susu

Well-Known Member
Licensed User
Longtime User
My local store sells this ESP8266 Easy which had a relay already. Is it work as I want? Thank you.

0lgOOyQl.jpg
 

Attachments

  • wifirelay.jpg
    wifirelay.jpg
    166.5 KB · Views: 407
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
@susu read the MQTT tutorial, look up relays and use an ESP8266.

With B4R is should be (no sorry, it will be) easy and quick to implement. It will basically be the same code I use to control my office lights over the internet but the relay will be connected to your computer's motherboard.

Good luck, I expect that you will have it all up and running in no time whatsoever.

Remember that the ESP8266 needs a 3 volt relay, not a 5 volt relay ;)
 
Upvote 0

susu

Well-Known Member
Licensed User
Longtime User
Thank you Peter,

My electronic knowledge is... zero so I have many questions, could you please help me make it clear?
- What do you mean "Rememberthat the ESP8266 needs a 3 volt relay, not a 5 volt relay"? I really don't understand. The seller of ESP8266 Easy Kit above show me the demo that he can turn on/off the light through wifi/internet. So I think it's possible to control my PC too.
- I want to connect pin 6 & 8 on mainboard by a cable to ESP8266 relay. Is it right or not?
5FT0y.jpg

I used to turn on my PC by connect pin 6 & 8 using a metal clip, it always works
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
@susu I would say that your best bet to make things easier for yourself, would be to use an D1 Mini with a relay shield mounted on top.

Total hardware cost = £3.81

The hardware needed for this project is 1 x D1 Mini, 1 x D1 Mini relay shield and a if need be 1 x DC to DC converter, is this cheap enough for you susu ;) ???

What I would order - links below:
D1 Mini
Relay Shield

Being that the above footprint is relatively small (even with the relay shield on top), I would place the finished project securely into the PC case.

You can use MQTT via an android app of your own design to turn your PC On/Off at will. Erel has already written tutorials on how to implement MQTT into your B4X projects. Using MQTT is really easy, I personally use CloudMQTT as my MQTT broker in my house and over the internet whilst travelling around, you can use CloudMQTT for free, but they also have a paid service.

What I would most probably do (the basics):
  • Connect pin 6 to relay shield centre (common).
  • Connect pin 8 to relay shield right (NC (Normally Closed)).
  • Use ESP8266 (B4R) to activate the relay for 500 milliseconds to turn On your PC. You can activate the relay again for 500 milliseconds to put your computer into sleep mode and again to wake it up (dependig on your Windows power button settings).
  • If your PC is already switched On, use ESP8266 (B4R) to activate the relay for 5000+ milliseconds to turn your PC Off (hard shutdown).
  • You will need to have the D1 mini connected to a constant 5V power feed. You can just cheat and use an external power source like a mobile phone charger going into your computer case to run the D1 Mini 24/7.
I'm not sure if there are any constant 5V or 12V feeds in an ATX power supply/connector when the PC is switched Off (there probably isn't), but if there is you can either tap into the 5V feed or if there is a 12V feed you can drop the voltage down from 12V to 5V to power your D1 Mini by using this DC to DC step down converter.

NOTE: To activate/de-activate the relay on the shield, you need to digital write True/False to pin 'D1' on the D1 Mini.

Sorry, I may have made it sound more complicated than it actually is :oops:. Trust me, it's really easy to implement :D

As you are already an excellent B4A developer, writing the B4R code will be really easy for you to do. Once you have learned the basics on manipulating the Arduino/WeMos I/O pins, everything just falls into place. Watch some YouTube videos on what you can actually do with an Arduino/WeMos (I/O videos), that will give you some great ideas and it will get you thinking.

3V D1 Mini relay shield (sits on top of the D1 Mini)
relay.jpg


Relay shield sitting on top of a D1 Mini (can then carefully be placed into your PC case)
both.jpg


Enjoy...
 
Last edited:
Upvote 0

susu

Well-Known Member
Licensed User
Longtime User
Woah, your answer is very detailed and specific. Thank you so much. I believe I can do it. Now I got to run to buy these boards. ;)
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
You did @susu that's great news.
I take it that you had to use a constants 5V supply from an Android like phone charger (or did you manage to find a 5V supply in your PC case), which MQTT broker did you end up using, or did you use an in house moqueutte solution?

You should post your solution on this forum, I probably would :cool:
 
Upvote 0

susu

Well-Known Member
Licensed User
Longtime User
You did @susu that's great news.
I take it that you had to use a constants 5V supply from an Android like phone charger (or did you manage to find a 5V supply in your PC case), which MQTT broker did you end up using, or did you use an in house moqueutte solution?

You should post your solution on this forum, I probably would :cool:

I used a phone charger. I don't use MQTT solution because I didn't understand it yet :D
I made a "dirty" solution: Wemos Mini keep reading a value from my website, if it's "on" then nothing happen, if it's "off" then Wemos turn my PC off. The value will auto set to "on" later. I'm happy with it now. I need some free time to read more about MQTT.
 
Upvote 0
Top