Page 1 of 1
GPIO truning on a light when ethernet is dropped
Posted: Sat Dec 21, 2013 7:20 pm
by Ghostatwar
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 =)
Re: GPIO truning on a light when ethernet is dropped
Posted: Sat Dec 21, 2013 7:38 pm
by DougieLawson
The ethernet already has lights (FDX, LNK) on the board.
Get a glass fibre to transmit those to the outside of the case.
Re: GPIO truning on a light when ethernet is dropped
Posted: Sun Dec 22, 2013 11:51 am
by Mennims
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
Re: GPIO truning on a light when ethernet is dropped
Posted: Sun Dec 22, 2013 11:59 am
by DougieLawson
Lose the connection and the green light goes out. What more do you need?
Re: GPIO truning on a light when ethernet is dropped
Posted: Sun Dec 22, 2013 9:27 pm
by Raspberry Paul
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
#####################################################################