I have a raspberry Pi with a Wi-Fi dongle, so standard internet LEDs do not work. I tried to write a script that switches the LED whether the Pi has internet or not.
This is what I have now:
#!/usr/bin/python import urllib2 import time, os os.system("gpio mode 6 out && gpio mode 5 out") loop_value = 1 while (loop_value == 1): try: urllib2.urlopen("http://www.google.com") except urllib2.URLError, e: time.sleep( 1 ) print "Not Connected" os.system("gpio write 6 0 && gpio write 5 1") else: print "Connected" os.system("gpio write 6 1 && gpio write 5 0") loop_value = 1
The problem is that it does not work. can someone tell me how can i detect if my pi has internet or not and then print the LEDs?
source share