Friday, 21 September 2012 10:45

Lua sleep function in milliseconds

Lua Socekt must be use in order to call sleep function in milliseconds.

An example to install Lua Socket to OpenWRT

opkg update
opkg install luasocket


An example to sleep 10 milliseconds

require "socket"


Lua can only sleep/wait in seconds (not milliseconds) without install Lua Socket. Code below shows the sleep funciton.

function delay_s(delay)
   delay = delay or 1
   local time_to = os.time() + delay
   while os.time() < time_to do end


Example to sleep 5 seconds




This tutorial is intended to show you how to open ports (also call virtual server) on your router so that you can control/link your device over the internet. I would suggest to undestand what is IP address if you don't know what is Private IP and Public IP address.
In short Public IP is for outside organisation and Private IP is for inside organisation.
This guide is based on TP-LINK TL-WR1043ND wireless N router with original firmware. Assumed using the following settings. You might want to know what is Dynamic DNS on OpenWRT.
  • TL-WR1043 router IP address:
  • Device to be control (IP address) :
  • Device to be control (Port) : 455
Sunday, 29 July 2012 11:19

Control Serial via PHP

It is simple to control serial via PHP.

exec("mode com4: BAUD=9600 PARITY=n DATA=8 STOP=1 to=off dtr=off rts=off");
$fp =fopen("com4", "w");
//$fp = fopen('/dev/ttyUSB0','r+'); //use this for Linux
fwrite($fp, "string to send"); //write string to serial

Saturday, 28 July 2012 16:34

HTML Onclick Image Button with CSS

This is a tutorial to show image button on webpage, it use CSS.
See for more information.

Below is an example to show two image buttons. <div class="img"> is the CSS, it is not define in this example, but it is working without any CSS style.

<div >
<a target="_parent" href="/newWebPage.php"><img src="/images/light_on.png" alt="Light1" /></a>
<a href="javascript:runCmd(1,'a')"><img src="/images/fan_on.png" alt="Fan1" /></a>

<div >
<a target="_parent" href="/newWebPage.php"><img src="/images/light_off.png" alt="Light2" /></a>
<a href="javascript:runCmd(1,'a')"><img src="/images/fan_off.png" alt="Fan2" /></a>


Saturday, 28 July 2012 16:33

HTML Onclick Button Image

There is few ways to show image button on the webpage. Here I use <a.

<a target="_parent" href="/newWebPage.php"><img src="/images/light_on.png" alt="Light" /></a>

Above example shows an image with event. newWebPage.php will open if user click on the image.

  1. target="_parent" means open a new page when user click on the image. See for more information
  2. href= is the action. It will open newWebPage.php when user click on the image.
  3. img src= show the image on the page. It support many formats such as png, jpg, gif, bmp & others. I often use png & gif (animation) format since both support transparent.
  4. alt= will show the text if the associated image is not exist.


Note: IE8 and Google Chrome show output differently. There is a rectangular frame around the image if loaded with IE8, while Google Chrome did not show any frame.

Below example execute a javascript function called runCmd with two parameters:

<a href="javascript:runCmd(1,'a')"><img src="/images/fan_on.png" alt="Fan" /></a>

See for more information on how to use <a

Below example shows four images aligned in horizontally:

<a target="_parent" href="/newWebPage.php"><img src="/images/light_on.png" alt="Light" /></a>
<a href="javascript:runCmd(1,'a')"><img src="/images/fan_on.png" alt="Fan" /></a>
<a target="_parent" href="/newWebPage.php"><img src="/images/light_on.png" alt="Light" /></a>
<a href="javascript:runCmd(1,'a')"><img src="/images/fan_on.png" alt="Fan" /></a>

Back to Top