Created
April 22, 2017 17:06
-
-
Save raihanba13/7e5b3b18ff0425669d5c74a7151bfdea to your computer and use it in GitHub Desktop.
Home automation project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #This is the simplest code. I used headers from documentation and tried SO answers https://docs.python.org/3.4/howto/urllib2.html#headers | |
| import RPi.GPIO as GPIO | |
| import urllib2 | |
| GPIO.setwarnings(False) | |
| GPIO.setmode(GPIO.BOARD) | |
| GPIO.setup(3,GPIO.OUT) | |
| true = 1 | |
| while(true): | |
| try: | |
| response = urllib2.urlopen('http://mydomain.com/device1.php') | |
| status1 = response.read() | |
| except urllib2.HTTPError, e: | |
| print e.code | |
| except urllib2.URLError, e: | |
| print e.args | |
| print status1 | |
| if status1 =='ON': | |
| GPIO.output(3,True) | |
| elif status1 =='OFF': | |
| GPIO.output(3,False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment