|
Post by betterboy on Nov 27, 2013 5:53:57 GMT -8
Hi,
I've gone into my page and set up buttons to refresh other controls. Do you have an example of what your feedback button code looks like inside Local.py?
bb
|
|
|
Post by SDL on Nov 27, 2013 9:14:51 GMT -8
Hi BB,
We use this feature her to bring our pages to life. If you hit a button to, say, turn on a light, we have an LED control turn green at the same time (which by the way is driven by the server, so there is feedback!). We have asked one of our customers to build a video showing this feature at work.
The feature works like this:
1) Hit the button on the page 2) The button is posted to the server 3) all the other controls tied to the control (through the customize feature in the button) are asked for a refresh also 4) All the refresh information comes back to the server and all the controls specified and the button is refreshed.
For the example you were asking for, here is a code snipped from a Local.py file.
# FB-12 - turn on GPIO 18 (fan) if (objectServerID == "FB-12"):
#check for validate request # validate allows RasPiConnect to verify this object is here if (validate == "YES"): outgoingXMLData += Validate.buildValidateResponse("YES") outgoingXMLData += BuildResponse.buildFooter() return outgoingXMLData
# not validate request, so execute
responseData = "XXX" if (objectName is None): objectName = "XXX"
lowername = objectName.lower()
GPIO.setmode(GPIO.BOARD)
if (lowername == "turn fan on"):
GPIO.setup(18, GPIO.OUT) GPIO.output(18, True) time.sleep(0.3) GPIO.output(18, False)
f = open("/home/pi/ProjectCuracao/main/state/fanstate.txt", "w") f.write("1") f.close()
responseData = "turn fan off" responseData = responseData.title()
elif (lowername == "turn fan off"):
GPIO.setup(15, GPIO.OUT) GPIO.output(15, True) time.sleep(0.3) GPIO.output(15, False) f = open("/home/pi/ProjectCuracao/main/state/fanstate.txt", "w") f.write("0") f.close()
responseData = "turn fan on" responseData = responseData.title()
# defaults to fan on (meaning fan is off) else: lowername = "turn fan on" GPIO.setup(18, GPIO.OUT) GPIO.output(18, False)
responseData = lowername.title()
outgoingXMLData += BuildResponse.buildResponse(responseData) outgoingXMLData += BuildResponse.buildFooter() return outgoingXMLData
Note how the state information of the fan is stored in a file for the rest of the program to read. To my knowledge there is no real way of reading the current state of an GPIO output.
BP
|
|