|
Post by Bist on Jul 30, 2013 1:45:18 GMT -8
Hi guys,
I have everything setup and working. Meaning I can connect the app to the server on an raspberry pi. What I don't get is how I can control some GPIOs on the raspberry. I should add a button for example. But how the hell do I make it execute a python script for example.
Let's say I have a script called ledcontrol.py How do I execute that script by pressing a button in the raspiconnect app?
Sorry for not seeing it..
Thanks a milion
|
|
|
Post by SDL on Jul 30, 2013 8:20:55 GMT -8
Hi Bist, No, not a stupid question. Take a look at the documentation www2.milocreek.com:8080/wiki/index.php/RasPiConnectServer#Constructing_Your_Own_RasPiConnect_Responses_.28The_Magic.21.29Copy over LocalExample.py to Local.py and then modify the file according to the documentation. You can place your code in Local.py or put it into a python library and import it. We are writing a separate tutorial for this and will have it done in August. The key piece of code in your copied verison of Local.py to change is: # not validate request, so execute # note that python is in the main directory for this call, not the local directory output = subprocess.call(["aplay", "sounds/match1.wav"]) Replace "output=...." with your own code for GPIO control. Best regards, BP
|
|
|
Post by Bist on Jul 31, 2013 22:55:05 GMT -8
Hi,
Thanks for the response. Sounds a bit complicated for me. Always eager to learn. Few more questions
Would the command be something like this? output = subprocess.call(["python", "pathtopythonscript"]) ..is this correct? It's just a script which I like to run behind the button.
Next question. In this example we configured what is behind button called B-2......what if I want to add another button called B-3 or B-4 ....would I just add another section in local.py adding the other button or do I need to create more files like local.py.
I really want to understand this since I have no programming background but am I system administrator ;-) So i can more or less read what is happening ;-)
Thanks
|
|
|
Post by SDL on Aug 1, 2013 8:25:53 GMT -8
Bist,
Yes, subprocess.call(["python", "pathtopythonscript"]) will run your script. Remember adding DEBUG = True to your config.py will give you a lot of debugging help.
Yes, you are correct. Yes, add another section in the Local.py (remember it's a capital "L") file for "B-2", "B-3", etc.
BP
|
|
|
Post by Bist on Aug 1, 2013 11:30:21 GMT -8
Alright...nice thanks..I will try this tonight
|
|
|
Post by Bist on Aug 1, 2013 11:41:51 GMT -8
OMG it works.....it's ALLLIIIVVEEEE mouhahaha
Thanks a milion BP
small question, if I wonna add another button in Local.py. I can see this is an IF statement. Can I just add the section with IF or should I do something with ELSE ?? or similar?
|
|
|
Post by SDL on Aug 1, 2013 11:59:53 GMT -8
Wooohoooooo!!!!!! Glad it is alive!
Just follow this model
# B-2 - play a beep on the Raspberry Pi if (objectServerID == "B-2"):
code code code
# B-3 - start motor on Pi if (objectServerID == "B-3"):
etc. etc.
Use the B-2 example as the model (cut and paste) so you can still validate your own controls.
Best regards, BP
|
|
|
Post by raspihawk on Feb 2, 2015 16:44:19 GMT -8
would someone please upload a working Local.py of this? I can't seem to find where to insert the full B-2 code.
thx
|
|
|
Post by SDL on Feb 10, 2015 10:20:43 GMT -8
ve7mkf,
Perfect response. Thank you!
Best regards,
BP
|
|