This is not how web2py works. You cannot call a Python function from 
Javascript -- they are two different languages running in different 
environments. If you need an action in the browser to trigger some code to 
run on the server, you must make an Ajax request. Please read 
http://web2py.com/books/default/chapter/29/11/jquery-and-ajax.

Anthony

On Saturday, June 18, 2016 at 8:47:42 AM UTC-4, John Doe wrote:
>
> Hello, i am trying to remotely turn ON/OFF a LED that is connected to a 
> RaspberryPi.
> I have installed Web2Py on my PC (that is running Ubuntu). Additionaly i 
> have installed Paramiko for my SSH conection.
>
> I've put this code in a Controller called led.py:
>
> import paramiko
> def leds_set(state):
>   ssh = paramiko.SSHClient()
>   ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
>   ssh.connect('192.168.2.100', username='myuser', password='mypassword')
>   if state:
>     state = 'on'
>   else:
>     state = 'off'
>   stdin, stdout, stderr = ssh.exec_command('python /home/pi/led.py ' + state)
>   print(stdin, stdout, stderr)
>   return dict()
>
>
>
>
> I replaced index.html with this. It does not work.
>
> {{extend 'layout.html'}}
>
> <form>
> <input type="button" onclick="leds_set(True);" value="leds on"/>
> <input type="button" onclick="leds_set(False);" value="leds off"/>
> </form>
>
>
>
> The last piece of code (led.py) that is on my Raspberry Pi is for testing 
> purposes (i know that is completely broken, but i only need to know if it 
> works by turning the LED ON).
>
> import time
> import os
> import RPi.GPIO as GPIO
> GPIO.setmode(GPIO.BOARD)
> GPIO.setwarnings(False)
> GPIO.setup(11, GPIO.OUT)
>
> state = sys.argv[1]
>
> if state =='on':
>     print('Led ON')
>     GPIO.output(11,True)
>     time.sleep(2)
>     GPIO.output(11,False)
>     time.sleep(2)
> GPIO.cleanup()
>
>
> So, i think that the problem is the HTML part because i got this error (in 
> console): 
>
> Uncaught ReferenceError: leds_set is not defined.
>
> What can i do so i could run led.py ?
>
>
>
>
>
>
>
>
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to