0

I wrote a python code for a project and I would like to execute a couple of functions through web.

For example : The function turnOn() is turning on a L.E.D. (this is just an example, the function will execute a bunch of stuff)

I would like to press a button on a webpage, the RPi executes the function and turn on the light.

How is this possible?

Bobys
  • 677
  • 1
  • 14
  • 37
  • 1
    You can use php to access the script – el3ien Jun 11 '14 at 11:44
  • http://stackoverflow.com/questions/19735250/running-a-python-script-from-php – el3ien Jun 11 '14 at 11:46
  • 2
    Welcome to stack overflow, it looks like you've recieved a school assignment or want us to do all the work for you. Al tho we tend to help out in any way we can we would like you to show some form of effort yourself.. What have you tried thus far? Did you bump into any errors that we can help with? Show us what you've tried and we can bump you into the right direction, but coding everything for you or finding libraries for you is not what stackoverflow is ment for. – Torxed Jun 11 '14 at 11:47
  • But to give you a hint, PHP+CGI+Python-script and you're golden. – Torxed Jun 11 '14 at 11:48
  • Thanks for your reply, The truth is that Im not on a school assignment. I would like to build a Home Security device using the Raspberry Pi. I was able till now to type a password, using the Adafruit Keypad and disable the system. Now I would like to add a new function. To be able to disable and enable the system remotely from the web. – Bobys Jun 11 '14 at 11:50
  • 2
    Why in hell should he need to use PHP to do that!? Python can easily handle http requests (and does so in a much cleaner fashion than PHP). As the answers suggests, have a look at flask or bottle, you won't have much trouble adapting your code. – svvac Jun 11 '14 at 11:51
  • I'm not sure why another scripting language (php) should be involved to execute the python code? – Jordfräs Jun 11 '14 at 11:52
  • Because you have to access files on your system. Another option is to use flask, like suggested below. – el3ien Jun 11 '14 at 11:52
  • @EL3PHANTEN And python can't access files? – svvac Jun 11 '14 at 11:56
  • @swordofpain yes, but the button on the webpage. I did not say he had to use php – el3ien Jun 11 '14 at 11:57

1 Answers1

3

I'd suggest using flask, very easy to get up and running and you can just call the relevant methods from the page handlers...

You will need a working knowledge of apache/nginx/ to run it safely on a public facing box.

Chris Clarke
  • 2,103
  • 2
  • 14
  • 19