Skip to content

Instantly share code, notes, and snippets.

@abdullahseba
Last active November 19, 2017 10:54
Show Gist options
  • Save abdullahseba/95deaf681a59de1e14f4738ee50e8970 to your computer and use it in GitHub Desktop.
Save abdullahseba/95deaf681a59de1e14f4738ee50e8970 to your computer and use it in GitHub Desktop.
from time import sleep
import RPi.GPIO as GPIO
import urllib2
import xml.etree.ElementTree as ET
GPIO.setmode(GPIO.BCM)
INPUT_PIN = 10
GPIO.setup(INPUT_PIN, GPIO.IN)
last_state = False
while True:
if GPIO.input(INPUT_PIN) == True and last_state == False:
last_state = True
xml = urllib2.urlopen("http://192.168.1.100/" +
"current_state.xml?pw=admin").read()
rly_state = ET.fromstring(xml).find('Relay12/State').text
if (rly_state == '0'):
urllib2.urlopen("http://192.168.1.100/" +
"current_state.xml?pw=admin&Relay12=1").read()
else:
urllib2.urlopen("http://192.168.1.100/" +
"current_state.xml?pw=admin&Relay12=0").read()
elif (GPIO.input(INPUT_PIN) == False and last_state == True):
last_state = False
xml = urllib2.urlopen("http://192.168.1.100/" +
"current_state.xml?pw=admin").read()
rly_state = ET.fromstring(xml).find('Relay12/State').text
if (rly_state == '0'):
urllib2.urlopen("http://192.168.1.100/" +
"current_state.xml?pw=admin&Relay12=1").read()
else:
urllib2.urlopen("http://192.168.1.100/" +
"current_state.xml?pw=admin&Relay12=0").read()
else:
print 'idle'
sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment