Web2Py controlling the lights!

Finally, i could control the test LED using my simple Web2py web app. All thanks to Niphlod, Cliff, Anthony, who has replied to my forum threads , and others who have replied to my other forum threads.

I did some slight modification after having a better understanding on URL and arguments. in test.html, there will be 2 buttons, On and Off.

web2py comfort on off
I will issue a URL request upon clicking on the “button” image, so this is how i should write:

<a href = "{{=URL('test', args =['bulb','1', 'on'])}}"><img src ="/Comfort2/static/images/on.jpg" width ="75" height="75"></a>
<a href = "{{=URL('test', args =['bulb','1', 'off'])}}"><img src ="/Comfort2/static/images/off.jpg" width ="75" height="75"></a>

‘test’ – what i want is in the “test” function
args = [‘bulbs’, ‘1’, ‘on’] – starting from index 0 storing ‘bulbs’, index 1 storing ‘1’ and so on.

In default.py, this is the crucial part that i kept on failing:

check for the conditions, remember the double equal sign “==” used for comparison.
because it is in the same function as the open port and login, i do not have to reopen and relogin to the system.

if request.args(1)== '1' and request.args(2)=='on':
elif request.args(1)== '1' and request.args(2)=='off':

Compared to my previous pathetic noob state here.

Another useful thing i learnt is the troubleshoot tool.
Adding this code


at the top of the view (test.html), will display a set of useful toolbar. From the request tab, i could easily see the args that i pass in when i clicked on the button image.

web2py toolbar

or simply just


which will display just the args.
web2py request args

Note that I have just changed the layout :p Got this from web2py layoutsKeep it Simple.
Much things can be done from here! But it’s time for CherryPy! 😀


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s