I'm trying to get a python script to read the contents of a text file and if it's 21 turn on a LED but if it's 20 turn it off. The script also prints out the contents of the text file on the screen.
The contents print out works all ok but the LED does not turn on.
import wiringpi2
import time
wiringpi2.wiringPiSetupGpio()
wiringpi2.pinMode(17,1)
while 1:
fh=open("test1.txt","r")
print fh.read()
line = fh.read()
fh.close()
if line == "21":
wiringpi2.digitalWrite(17,1)
elif line == "20":
wiringpi2.digitalWrite(17,0)
time.sleep(2)