j3r4d
Posts: 2
Joined: Wed Jun 20, 2018 4:58 pm

Help Please to read PC power led

Wed Jun 20, 2018 5:07 pm

Ok I know this will be simple to most of you geniuses but I’m having a rough go of it.

Trying to control a PC remotely with Pi and read the Power LED output from motherboard to test its actually powered on. I have optocoupler on breadboard and have the switching part figured out I just need some help with code to read or test for current? on the power on led pins from PC motherboard. (The LED status indicator normally on PC case) or maybe this isn’t possible since Pi has no analog GPIO? Thanks in advance I have googled for days to no avail.

pcmanbob
Posts: 3984
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Help Please :/

Wed Jun 20, 2018 7:20 pm

Hi.

Seeing as you have already selected an opto isolator for the job and the output side of things that I assume you have connected to the pi working I don't understand why you are having such a problem with the input to the opto isolator.

Seeing as the input side of the opto isolator is just an LED all you need to do is un-plug the existing power LED from the motherboard and connect the opto isolator LED in its place making sure you get it the right way round. there is no need for any resistors as the motherboard takes care of LED current limiting.

Image

So this set up will result in a high on the gpio input pin when ever the PC power LED is on.

So assuming you use GPIO 23 for the input this code will report the state of the PC every 10 seconds.

Code: Select all


import RPi.GPIO as GPIO
import time


GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(23, GPIO.IN)


while True:
    if GPIO.input(23) == 1:
        print ("PC is powered on")
            
    else:
        print ("PC is powered off")
        
    time.sleep(10)
    
Remember we want information.......................no information no help
The use of crystal balls & mind reading is not supported

User avatar
thagrol
Posts: 695
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Help Please to read PC power led

Thu Jun 21, 2018 12:01 pm

The power LED isn't a good choice mostly for the following reasons:
  1. Get the circuit wrong and you risk damaging the motherboard (expensive in both time and money to fix)
  2. Some motherboards pulse the power LED when the PC is in a "suspend to RAM" (aka sleep) state this will give confusing results.
  3. It doesn't tell you anything about the state of the PC's OS. THE LED can be on but the OS might have crashed or the BIOS/UEFI might be running, the boot might have failed, etc.
When I had a need to detect the state of a remote PC I did it by a combination of testing if the OS responded to pings and monitoring the state of the PSU's 3.3v line (on the motherboard power connector). You could monitor the 5v line from a drive power connector instead via an optocoupler.

3.3v line on, no ping reply = PSU on but OS down
3.3v line on, ping reply = PSU on OS OK.
3.3v line off, no ping reply = PSU (and therefore PC off)

If you want details of that project, see here: https://github.com/thagrol/fakewake
Note to self: don't feed the trolls
If you believe "L'enfer, c'est les autres" (Hell is other people) have you considered that it may be of your own making?

j3r4d
Posts: 2
Joined: Wed Jun 20, 2018 4:58 pm

Re: Help Please to read PC power led

Thu Jun 21, 2018 8:35 pm

thagrol wrote:
Thu Jun 21, 2018 12:01 pm
The power LED isn't a good choice mostly for the following reasons:
  1. Get the circuit wrong and you risk damaging the motherboard (expensive in both time and money to fix)
  2. Some motherboards pulse the power LED when the PC is in a "suspend to RAM" (aka sleep) state this will give confusing results.
  3. It doesn't tell you anything about the state of the PC's OS. THE LED can be on but the OS might have crashed or the BIOS/UEFI might be running, the boot might have failed, etc.
When I had a need to detect the state of a remote PC I did it by a combination of testing if the OS responded to pings and monitoring the state of the PSU's 3.3v line (on the motherboard power connector). You could monitor the 5v line from a drive power connector instead via an optocoupler.

3.3v line on, no ping reply = PSU on but OS down
3.3v line on, ping reply = PSU on OS OK.
3.3v line off, no ping reply = PSU (and therefore PC off)

If you want details of that project, see here: https://github.com/thagrol/fakewake

Thank you both for your response. I appreciate your time!

I honestly never thought of just monitoring the 3.3 or 5 rail from PSU that’s actually a way better idea. Thank you! Question, so how could I read from the output of optocoupler controlled by psu 5 or 3.3? Is there a way to test for continuity between two GPIO pins?
Thanks again!

Info:These are mining rigs that I can remote into or ssh just want to set up alerts for when/if they go down and reboot remotely

pcmanbob
Posts: 3984
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Help Please to read PC power led

Thu Jun 21, 2018 8:45 pm

You could use the same basic circuit that posted, but power the LED in the opto isolator from the 5v or 3.3v power rail and the psu ground using a suitable current limiting resistor.

Why do you need to monitor continuity between two GPIO pins? You normally use a pull up or pull down circuit on a gpio input.
Remember we want information.......................no information no help
The use of crystal balls & mind reading is not supported

Return to “Python”

Who is online

Users browsing this forum: No registered users and 14 guests