Hi guys! Sorry but I still do not quite understand after reading the chapters about "Dispatching" and "URL". i guess my programming foundation isn't that strong... and i have problem understanding without referring to examples.
Here is my situation and i would like to get a general idea on how to solve the problem. May be my idea was wrong so please correct me :)
I have just successfully connect a device to my Raspberry Pi, with web2py as the webserver on Raspberry pi. Currently, i have created a home page using the template, and there is a "Login" button on it. When i click on the image (button), it directs me to default/test.html. the device gets the login information and turns on and off the testlight.
in default/index.html:
<a href = "{{=URL(c='default', f='test')}}"><img src ="/Comfort2/static/images/login.jpg" width ="128" height="69"></a>
in default.py:
def test():
import serial
import time
response.flash=T("welcome home!")
time.sleep(1)
serialport= serial.Serial("/dev/ttyAMA0", 9600, timeout=0.5) #opening the port
serialport.write("\x03LI1234\x0D") #write a serial command to log into the device
reply=serialport.readlines(1)
print reply
time.sleep(1)
serialport.write("\x03O!0101\x0D") #turn on a testlight
time.sleep(2)
serialport.write("\x03O!0100\x0D") #turn off a testlight
return dict()
However, i would like to separate it into a few tasks. So, after pressing the "login" button, it will only login and direct me to test.html with 2 buttons (Turn on light and turn off light). if i press on the turn on light button, the testlight will turn on and same for the other one. I would like all these to be under one function because the commands can only be sent when it is logged into the device. (if it is under another function, i will need to login again.) So do i need to use args and vars at this point?
I do not really understand what is args and vars and how are they used. the information in the chapters taught me that
request.args = ['x', 'y', 'z']
request.vars={'p':1, 'q':2}
but what are x,y,z,p, q, 1 and 2? under what conditions are they declared and where do they appear?
Another question: can i display a jQuery keypad using web2py?
My progress using cherrypy is slightly more ahead than web2py. i am sure i can transfer my work in cherrypy over to web2py... but i must get the whole concept clear... please help me.
sorry that i sound very noob.... but much thanks to everyone for your patience and guidance! :)