Skip to content

Commit

Permalink
Checking internet connection on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
sammachin committed Jan 9, 2016
1 parent b2b5ba3 commit c66df00
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion Main_RPi.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import json
import re
from memcache import Client
import urllib2

#Setup
button = 18
Expand All @@ -21,6 +22,19 @@
mc = Client(servers, debug=1)
path = os.path.realpath(__file__).rstrip(os.path.basename(__file__))



def internet_on():
print "Checking Internet Connection"
try:
r =requests.get('https://api.amazon.com/auth/o2/token')
print "Connection OK"
return True
except:
print "Connection Failed"
return False


def gettoken():
token = mc.get("access_token")
refresh = refresh_token
Expand Down Expand Up @@ -130,11 +144,13 @@ def start():
GPIO.setup(button, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(lights, GPIO.OUT)
GPIO.output(lights, GPIO.LOW)
while internet_on() == False:
print "."
token = gettoken()
os.system('mpg123 -q {}1sec.mp3 {}hello.mp3'.format(path, path))
for x in range(0, 3):
time.sleep(.1)
GPIO.output(24, GPIO.HIGH)
time.sleep(.1)
GPIO.output(24, GPIO.LOW)
start()
start()

0 comments on commit c66df00

Please sign in to comment.