|
Post by jwmacc on Aug 1, 2014 2:37:18 GMT -8
Could you confirm that, when entering the code in Local.py to service a feedback button (eg FB-1), the text that is to appear in the two states of the button MUST be entered in lower case, even though when displayed on the button the first letter of each word is capitalised ? and is this documented anywhere ? I have spent a lot of time sorting this out - could it be that I should have rtfh (Read That Formidable Handbook) ?
Regards jwmacc
|
|
|
Post by SDL on Aug 1, 2014 9:01:20 GMT -8
jwmacc,
Well, yes. It was decided to do this to remove the lower case / upper case conundrum. And no, it isn't documented anywhere, but it will be shortly! I've got to go look through the Feedback button code in the App and figure out what it does so I can put it in the RTFH!
Here's an example of the code that we use. Note that we convert the Button name into lower case, do our comparisons and the convert back to "title" format with: responseData = responseData.title()
The state of the Fan is in a file so other processes can read the current fan state. The default section is there because there is a possibility in the case of an Internet hiccup the button can go blank.
This is a section of code that toggles a Fan on and off on GPIO18.
# 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(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 = lowername.title()
outgoingXMLData += BuildResponse.buildResponse(responseData) outgoingXMLData += BuildResponse.buildFooter() return outgoingXMLData
Hope this helps! And thanks for pointing out the RTFH deficiency.
Best Regards,
BP
|
|
|
Post by jwmacc on Aug 1, 2014 14:45:29 GMT -8
BP
Thanks for your very helpful reply. I had wondered what 'lowername' actually meant - all now clear. (I shall put a comment in my own code here to remind me in future). I have learnt a lot from your code example. What an excellent system this is !
Best wishes
jwmacc
|
|