Ghostatwar
Posts: 2
Joined: Tue Sep 10, 2013 8:00 pm

GPIO truning on a light when ethernet is dropped

Sat Dec 21, 2013 7:20 pm

Hi all

2nd post here and was just wondering how possible it would be to lets say send 3.3v to one of the gpio pins when the Ethernet drops or when the Ethernet is active, so E.G surfing the web on the pi (because the Ethernet is in use one of the pins get 3.3v) or (if someone wasn't using the Ethernet / the pi is not connected to the internet one the pins would get 3.3v )
ether would work.

would prefer the 2nd option. that way when the pi is inside a case I can tell if the pi has lost connection, could put a small red LED in the case.

Thanks =)

User avatar
DougieLawson
Posts: 39121
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: GPIO truning on a light when ethernet is dropped

Sat Dec 21, 2013 7:38 pm

The ethernet already has lights (FDX, LNK) on the board.

Get a glass fibre to transmit those to the outside of the case.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Mennims
Posts: 105
Joined: Sun May 19, 2013 9:37 am

Re: GPIO truning on a light when ethernet is dropped

Sun Dec 22, 2013 11:51 am

What I think he is trying to say here is, when the internet drops, as in the Ethernet is plugged in but here is no actual connection to the internet, then a gpio pin is triggered to turnon an led. What he needs is a software that wil receive tiny amounts of data from a special web address every designated amount of time, i.e 5 seconds, and if it receives the data the light will turn on (or if it was on previously it will continue to light up) or turn off it receives no data

User avatar
DougieLawson
Posts: 39121
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: GPIO truning on a light when ethernet is dropped

Sun Dec 22, 2013 11:59 am

Lose the connection and the green light goes out. What more do you need?
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Raspberry Paul
Posts: 86
Joined: Mon Jun 10, 2013 3:40 pm
Contact: Website

Re: GPIO truning on a light when ethernet is dropped

Sun Dec 22, 2013 9:27 pm

I use the following code to detect when the wireless network connection has dropped, and to try and bring it back up. It lights an LED on pin 24 if the network is down.

The IP address 192.168.1.1 is the router. It's pinged 15 times, and if it errors more than 10 it's classed as faulty

The code was originally used for network throughput and error rates so there might be a bit of extracode.

Code: Select all

def checknetworking():
    PingIPAddress = "192.168.1.1"
    TTLTotal = 0
    FailedCount=0
    FaultyNetwork=1
    
    print (str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M")) + " Checking Network")

    while (FaultyNetwork > 0):
        for x in range(0, 15):
            cmd="ping -c 1 "+ PingIPAddress +" | grep 'time=' | cut -d ' ' -f 7 | cut -d ' ' -f1"
            TTL = run_cmd(cmd)
            TTL = TTL.replace("\n", "")
            TTL = TTL.replace("time=", "")
            if (TTL == ""):
                TTL = "0"
                FailedCount = FailedCount + 1
            
        print (str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M")) + " Network Failed Count = " + str(FailedCount))
        
        if (FailedCount < 10):
              FaultyNetwork = 0
        else:
            print (str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M")) + " Network connection down! Attempting reconnection. Fault count = " + str(FaultyNetwork))
            GPIO.output(24, True)
            pdsWriteLog("No Networking" + str(FaultyNetwork) )
            run_cmd("ifup --force wlan0")
            sleep(10)
            FailedCount = 0
  
#####################################################################
http://www.raspberrypaul.co.uk

Return to “General discussion”