This is a read-only archive. Find the latest Linux articles, documentation, and answers at the new Linux.com!

Linux.com

Feature

Real world control from a Web page

By Rob Reilly on May 22, 2006 (8:00:00 AM)

Share    Print    Comments   

In "Acquiring data from the physical world" we examined how to use a microcontroller to turn physical events (such as reading a switch) into data and send that data to a Linux box via the serial line. With this capability you can do things like counting people passing through a gate or recording how the temperature changes over time in a factory process. You can then send the data to a Web page. In this article, we'll do it in reverse -- from a Web form, instruct a microcontroller to perform some actions.

You can create a Web form on an Apache/Linux server, process the data with a PHP script, then push the control instructions down to the microcontroller over the serial line. The microcontroller will run code that interprets the data from the serial line and instruct the I/O pins to perform some action. Basic applications might be to turn on lights, relays, or motors from a remote browser screen.

Build the Web form and PHP back end

The HTML code below presents a bare-bones Web form. It prints a label and then supplies a little fill-in box for data. The "Submit" button is the standard way of processing the form. I arbitrarily chose "2" to turn on the LED (attached to the microcontroller prototype board). Any other character turns the LED off.

<HTML>
<HEAD>
<TITLE>Microcontroller Data Input Form </TITLE>
</HEAD>

<BODY>
<B>Microcontroller Data Input Form</B>
<BR><BR>
<FORM METHOD="GET" ACTION="handleform.php">
    Operate LED (2=on, everything else=off) <INPUT TYPE=INTEGER NAME="switch_led1" SIZE=3>
    Put another control here
<BR><BR>
<INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE="Submit!">
</FORM>

</BODY>
</HTML>

The following PHP code grabs the data from the HTML form, opens the serial port on the Apache server machine, and then writes the data out. The fclose function finishes up the process.

&lt?php
/* handleform.php */
/* Pull variables from URL string into local variables */
$control_led1 = $_GET["switch_led1"];

/* Send results back to browser for display */
print "LED1 value = $control_led1 \n";

/* Write the LED control data out to the serial line*/
$FileName = "/dev/ttyS0";
$FilePointer = fopen($FileName, "w+");
    fwrite($FilePointer, "$control_led1");
fclose($FilePointer);
?&gt

At the business end

To test this scheme, I used a $60 ZX-24 microcontroller from Elba Corporation. The "Stamp-like" micro is more than double the speed of the Netmedia BX-24 I used for earlier tests, has more space for data, and is pin-compatible with BX-24. The sample microcontroller source code included with this article compiles and runs, without modification, on either the BX-24 or the ZX-24 module.

As with the Netmedia device, the ZX-24 uses a compiler that runs under Windows 98. I was unsuccessful at getting the Zbasic compiler working with Wine on my Athlon 64/SUSE laptop, so I had to again use a spare 200MHz Pentium desktop machine for programming. This ancient machine is more than fast enough to run the ZX-24 or BX-24 compiler.

I used a 2x6-inch white plastic prototype breadboard to secure the ZX-24, the other support parts (voltage regulator, resistor, and a switch), and the connection points for the external wires of the serial cables. I used the same pair of serial cables and the 5.5-volt, 950 ma. power supply from the previous project. (See diagram.)

As this was a simple educational project, all I wanted to do was turn on an LED. You could easily expand the circuits to turn on relays, motors, and lights.

I used the Zbasic editor/compiler to create a sample program that reads data from the serial port. The main Do loop first checks for data in the buffer, then uses an If/Else statement to determine if a "2" (binary 50) has been received. If it has, the pin (16 in this case) is turned on, lighting up the LED. Any other character turns the pin off, as the microcontroller cycles through its main loop.

Go exercise some control

This procedure represents a basic template that you can use to create your own Web-enabled system. My intention was to show how you could take off-the-shelf parts and build something quickly without a lot of fuss.

For more robust applications, you'll want to consider adding security features to the HTML/PHP code. Using a sensor on the microcontroller and sending an acknowledgment back to the Web page will verify that the action you wanted actually took place.

The Apache/PHP/Linux and microcontroller combination is a natural for test sets, data logging, and remote Web-enabled control systems. You could even use your new Wi-Fi and browser-enabled cell phone as an microcontroller user interface. Put your imagination to work and go control something.

Rob Reilly is a consultant, trend spotter, and writer. He can advise you on your data acquisition projects, along with, portable computing and presentation technology integration.

Share    Print    Comments   

Comments

on Real world control from a Web page

Note: Comments are owned by the poster. We are not responsible for their content.

voltage regulator

Posted by: Anonymous Coward on May 24, 2006 05:19 PM
Your diagram should show a 7805, not 7508. Keep up the good work!

#

Web-based Remote Control of a Webcam

Posted by: Anonymous Coward on May 24, 2006 07:25 PM
An Italian guy has developed an electronic card, which you can connect to the serial port of a PC and control the rotation of a webcam (or something else) through any network (LAN, internet) by a simple web browser.

This card is currently on sales on eBay: <a href="http://cgi.ebay.it/Controllo-Remoto-Rotazione-Webcam-da-Internet-Browser_W0QQitemZ8815564035QQcategoryZ4616QQssPageNameZWDVWQQrdZ1QQcmdZViewItem" title="cgi.ebay.it">http://cgi.ebay.it/Controllo-Remoto-Rotazione-Web<nobr>c<wbr></nobr> am-da-Internet-Browser_W0QQitemZ8815564035QQcateg<nobr>o<wbr></nobr> ryZ4616QQssPageNameZWDVWQQrdZ1QQcmdZViewItem</a cgi.ebay.it>

The email of the author is: pino_otto@yahoo.com

#

Re:Web-based Remote Control of a Webcam

Posted by: pino_otto on May 25, 2006 02:53 AM
I believe that in the near future there will be many applications, which allow to control the real world through the web, especially by mobile appliances (phones, PDAs, wearable PCs, etc.).

My current card developed so far is quite simple, but it's powerful enough to move some objects through a servo motor controlled by any web browser.

As a first application, I'm using this card to control the movement (rotation) of a remote webcam. This allows to implement a very cheap remote sorveillance system.

If somebody wants to know more details, please do not hesitate to contact me by email (pino_otto@yahoo.com).

#

This story has been archived. Comments can no longer be posted.



 
Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya