I'm building a security camera system for my home out of a number of raspberry pi's. One of the things each camera system has will be a light to show a internet connection is present. For this I've used the code found at python check to see if host is connected to network and modified it to.
#! /usr/bin/python
import socket
import fcntl
import struct
import RPi.GPIO as GPIO
import time
pinNum = 8
GPIO.setmode(GPIO.BCM) #numbering scheme that corresponds to breakout board and pin layout
GPIO.setup(pinNum,GPIO.OUT) #replace pinNum with whatever pin you used, this sets up that pin as an output
#set LED to flash forever
def check_connection():
ifaces = ['eth0','wlan0']
connected = []
i = 0
for ifname in ifaces:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
socket.inet_ntoa(fcntl.ioctl(
s.fileno(),
0x8915, # SIOCGIFADDR
struct.pack('256s', ifname[:15])
)[20:24])
connected.append(ifname)
print "%s is connected" % ifname
while True:
GPIO.output(pinNum,GPIO.HIGH)
time.sleep(0.5)
GPIO.output(pinNum,GPIO.LOW)
time.sleep(0.5)
GPIO.output(pinNum,GPIO.LOW)
time.sleep(2.0)
except:
print "%s is not connected" % ifname
i += 1
return connected
connected_ifaces = check_connection()
However when I run the code through my Pi the error reads:
pi@raspberrypi ~/Desktop $ while True:
> ^
> TabError: inconsistent use of tabs and spaces in indentation
> ^C
Anyone know the issue? Apologies if it's a basic one, I'm new to Python Programming. In short my hope is that when an internet connection is present the light on pin 8 will turn on.
Thanks!