Month: March 2013

jQuery Keypad

Found an awesome keypad for my application here.

I have added the keypad to the sample web app successfully. Now that i need to use the keypad to Log in to the device by sending the log in information to the Raspberry Pi webserver and the server will send to the device through the serial port.

i find it hard to apply what i’ve just learnt. the examples and tutorials are too limited. or my understanding and capability are too limited. Too dependant. 😦


I just done going through the jQuery study materials at w3schools jQuery Class!

It’s generally quite simple to understand and apply. I love! More things to learn. Even though the information is quite basic but at least it gave me an inroduction on the scripting language and now i can roughly understand what is the program script about.

i’ve got 100% for the quiz πŸ˜‰


It’s Good Friday tomorrow. Thank you, Jesus Christ for loving us so much.

What a day.

I broke my 8Gb micro SD card into half while opening my handphone casing. That was last night.
Then this morning, another of my phone could not detect the SIM card. I transfered the SIM card to other phones but it has been declared dead.

I don’t remember what’s inside my SD card.
I don’t remember whose contact do i have in the SIM card.
ALL gone~

Better not to touch Raspberry Pi today. :/

Hello web2py

I have been lazying out on Raspberry Pi recently. Stuck at getting the web app on web2py to open the port at ttyAMA0. However it works fine on CherryPy.

Why. Why. Why.

Would it be better to just focus on CherryPy? :/ but i think Web2Py is newer and probably better and easier!
That is if and only if i am determined enough to finish reading (and digesting) through the 583 pages web2py manual. But it is so tiring to read it through the screen and time-wasting to study during working hours. If only i have an iPad or something.

Wait, did i just think of the Amazon Kindle or something? Haha, right. I should do something meaningful in the train while on my way to work, rather than sleeping. How about knitting? (That’s too outstanding. You probably wouldn’t want the whole pack of Sardine (we call the commuters that) to stare at you and start guessing your age.)

Not sure if it is a good idea to learn web2py and cherrypy concurrently. just hope that Mr Massimo can solve my problems soon.

Websites KIV:
Your first CherryPy application

CherryPy Tutorial

The CherryPy Documentation

Work related stuffs to do tomorrow:
– testing Z-wave responses (forgot to do it today!!!)

UnderstoodΒ  some Z-Wave problems today.

Other stuffs to do tonight:
– unofficial strategy planning with new team
– reply business emails

– revamp website too.


Thank God it’s Friday!!

Before I’m leaving my work for a weekend, let me note down a to-do list for next week:

1. Web2Py issue – different user mode disallow the web application to access and open the port
Refer hereΒ  and hereΒ  to learn how to change the user mode / add user.

2. Web App – design the web layout and user stories

3. jQuery – study it from

Get my project reports done, email some business partners-to-be, start a new Facebook page, tidy up my websites and Facebook page. Much things to do :/

And watch some AWESOME Korean Drama – Rooftop Prince. I rated it 5 stars. Yay! πŸ˜€ Everyone, watch it! I shall write about it some time πŸ˜‰

CherryPy Progress!

Good Day! i got stuck in testing the new Z-Wave firmware so here I am, back for more CherryPy!

Thanks to Mefarmer and ax25 who explained to me about what’s going on with the CherryPy and gave me clues on how to proceed! It is a nice of motivation. πŸ™‚

Let me restart my CherryPy journey and you can refer to my discussion with mefarmer in this forum thread. Do download the from there too as i could not upload the file here.

Before that, i forgot to mention about jQuery Mobile!! i think it is an awesome app. Check out the themeroller! Awesome awesome!! i’m so excited to make some web apps!!!! Wait. is web2py totally different from this? :O

The last time i edited the tutorial.conf file by changing the port number and tools.staticdir.root. But the web app wouldn’t show up when i type in the localhost:portnumber. Today, i changed the port number to 8020 which is not in used by any server. I think Web2py has taken up localhost:80 by default and :8080 seems to have some error… i did use it to display “Hello world” from the tutorial file included with the installation.

Anyway, moving on to
Adding #!/usr/bin/python will allow user to run the script automatically by typing python in the terminal., when run, will return a html file (webpage) which shows a sleek nice black layout with 3 buttons in the first row and a slider in the second row.

The jQuery Mobile framework is using a block style class convention called ui-grid.
There are four preset configurations layouts that can be used in any situation that requires columns:

  • two-column (using the ui-grid-a class)
  • three-column (using the ui-grid-b class)
  • four-column (using the ui-grid-c class)
  • five-column (using the ui-grid-d class)

Within the grid container, child elements are assigned ui-block-a/b/c/d/e in a sequential manner which makes each “block” element float side-by-side, forming the grid. The ui-block-a class essentially clears the floats which will start a new line (see multiple row grids, below).

To display the 3 buttons, here is the code (for one of the buttons):

<div class ="ui-grid-b">// 3 columns
block (refer below)

<button type="button" id="new_1" data-role="button" data-transition="fade" >
new_1 //word on the button

Read more here.

As for the slider, the data-role will be “slider” and it has more things to set (e.g option) (refer

Inside the html file shown in the example, we can add “scripts” in the form of “script src” (which direct to a script file) or “script type” which we can directly add in the script below it. in this case, a javascript was included. this will get the clicks and send them to the server using ajax:

$("#unique_id").click(function () {$.post('/request',{key_pressed:"unique_id"})});

$(“#slider_id”).change(function () {$.post(‘/request’, {key_pressed:”slider_id”+$(this).val()})});

Every button has an unique ID. Then the javascript sets up an event handler that looks for a “click” event with that unique ID. When there is a “click” event, it will do an ajax “post” to “http://localhost/request&#8221; which will send JSON data {key_pressed:”unique_id”}

Server will get the “post” and route it to the “request” function (in the itself). The JSON will be passed in as a dictionary. Inside the “request” function, we get the dictionary as “data” and look for the key “key_pressed”. The value we get from that, is the unique ID we passed in from the javascript ( {key_pressed:”unique_id”} ). in the example, we simply just send ID and use an if statement to look for matching values and print it out.
if key == “new_1”:
# you can do anything you want right here
print “new_1”

Now, to test my own application, this is what i do:
1. Login test
– import serial and time
– in the “request” function, i added

serialport = serial.Serial("/dev/ttyAMA0/", 9600, timeout=0.5)
response = serialport.readlines(1)
print response

– somehow i need to use a new port number. then i run the python script.
– it’s a success! i got the reply from the device connected to its serial port.

2. other buttons test
– here comes the challenge. serialport belongs to the if key ==”start” only. Does that mean i have to open the serial port everytime i press on any button? well that’s definitely not the best way. I can’t seem to find anywhere to insert that line (serialport =serial.Serial(….))
outside the function? global name “serialport” is not defined
inside the function, outside the “if”? local name “serialport” is not defined.

so in the end, i insert

serialport = serial.Serial("/dev/ttyAMA0/", 9600, timeout=0.5)

in every “if” and “elif” and it works~ whenever i slide the bar to “on”, the testlight turns on, and when i slide to “off”, the testlight turns off. Happy! πŸ˜€ Arming and disarming works too!! lovely milestone today! πŸ™‚

IMPORTANT! while i edit the python file, i did not shutdown the server. After i saved my changes, the server will “re-spawn”? i take that as a restart. haha, CherryPy coming back to life huh?

Z-Wave series: Aeon Labs Z-Stick Series 2

Z-Wave Evaluation Report

Product Name: Aeon Labs Z-Stick Series 2

Features and Functions:

USB adapter
Able to remotely include/remove Z-Wave devices

Operational Procedure:

3 mode of operations
1. Inclusion-Mode

  • Adding/including Z-Wave devices into Z-wave network
  • Has to be unplugged from USB connector
  • Tap the button once ( Blue LED blinks slowly)
  • Go to the device and press its z-wave button
  • Indication of successful inclusion -Blue LED will blink fast before it stays solid for 3 seconds.
  • LED return to blink slowly and is ready for inclusion of another device.
  • Tap again to turn it off.

2. Removal-Mode

  • Delete / remove / exclude a device from network
  • Has to be unplugged from USB connector
  • Press and hold down the button until the LED blinks fast
  • Go to the z-wave device and press the button
  • LED will stay solid for 3 seconds to indicate successful removal of device
  • LER return to blink fast and is ready for another exclusion

3. SerialAPI Mode

  • Plug Z-Stick into USB connector
  • Pressing on the button has no effect
  • Works with PC interface such as HomeSeer and InControl

4. Factory Reset

  • Done through host software ( HomeSeer and InControl) in SerialAPI mode (plug into USB connector)

Back to Z-Wave

Since i am stuck at the port 80, i’m taking a break and back to my old love, Z-Wave!!

While packing up my Raspberry Pi aside, i found a broken wire at the RxD pin of R-Pi. Perhaps that is why the port /dev/ttyAMA0 cannot be opened! 😦

Well, till next time!

I have forgotten most things about Z-Wave, now that i have to revise my old notes.