| ||||||||||||||
| ||||||||||||||
|
||||||||||||||
|
This article describes how to use ASP and WML to enable you to access your HomeSeer devices from your mobile phone. If you are not familiar with ASP or Visual Basic then you might find it hard to follow the code. If you just want to download and use the files, jump to the installation instructions below. Here is an example of what the Home Control system looks like:
Figure 1: Turning on the bedside light.
How It WorksThe system uses a series of ASP files to dynamically generate WML (Wireless Markup Language) pages that are displayed on your mobile phone. The home page (mobile.wml) is a static WML page that links to the ASP pages. Since the pages are run from the HomeSeer webserver, you have access to all HomeSeer's scripting functions by using the HomeSeer server object (hs).We won't cover all the pages, since they all operate in the same fashion. Instead we will look at three of the file: operate.asp, info.asp and execx10.asp. operate.aspOperate.asp simply lists all the devices in HomeSeer and provides links to their control pages. It also provides a "All Units Off" message, by directly linking to execx10.asp.
<% Response.ContentType = "text/vnd.wap.wml" %>
<% Dim Devices
Set Devices = hs.GetDeviceList %>
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card id="Operate" title="Operate Device">
<p>
<anchor>All: Units Off
<go href="execx10.asp?dev=a1&action=all%20units%20off"/>
</anchor><br/>
<% For Each dv in Devices
Response.Write("<anchor>" & dv.hc & dv.dc & ": " & dv.name &
"<go href=""device.asp?ref=" & dv.ref & """/>
</anchor><br/>")
Next %>
<br/>
<anchor><prev/>Back</anchor><br/>
</p>
</card>
</wml>
You can see we must set the Content-Type to a WAP page, otherwise your WAP gateway will
likely not recognize the page. Next we retrieve the device list from HomeSeer (using the
server object mentioned earlier). We then generate a list of devices using the house and
unit codes of the device followed by the device name. This creates a link to
device.asp. Device.asp takes the device reference - a reference
is a unique internal number used by HomeSeer for each device.
info.aspInfo.asp displays information on a particular device. Note: The code here may change with different releases of the system to support additional information, but the basics will remain the same.
<% Response.ContentType = "text/vnd.wap.wml" %>
<% Dim dv, code
Set dv = hs.GetDeviceByRef(Request.QueryString("ref"))
code = dv.hc & dv.dc %>
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card id="Info" title="<%=dv.name%>">
<p>
<%=code%>: <%=dv.dev_type_string%><br/>
Status:
<%
st = hs.DeviceStatus(code)
If st = 2 Then Response.Write("On")
If st = 3 Then Response.Write("Off")
If st = 4 Then Response.Write("Dimmed")
%><br/>
</p>
<p>
<anchor>More<go href="#Page2"/></anchor><br/>
<anchor>Operate<go href="device.asp?ref=<%=dv.ref%>"/></anchor><br/>
<anchor><prev/>Back</anchor><br/>
</p>
</card>
<card id="Page2" title="Last Modified">
<p>
<%=hs.DeviceLastChange(code)%>.<br/>
</p>
<p>
<anchor>Operate<go href="device.asp?ref=<%=dv.ref%>"/></anchor><br/>
<anchor><prev/>Back</anchor><br/>
</p>
</card>
</wml>
info.asp is a bit more complicated, since it spreads the information across two cards to keep screen
clutter to a minumum. The information is kept to the basics: Code, name, brief status and the date
and time the device was last modified. The script could be expanded to include information such as
temperature for HVAC systems, as well as more general system information.
execx10.aspexecx10.asp executes X10 commands. Again, this code will no doubt change in future releases, but the idea remains:
<% Response.ContentType = "text/vnd.wap.wml" %>
<% hs.ExecX10 Request.QueryString("dev"), Request.QueryString("action"), 0, 0 %>
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card id="ExecX10" title="X10 Command">
<p>
<%=Request.QueryString("dev") & " " & Request.QueryString("action")%> executed.<br/><br/>
</p>
<p>
<anchor><prev/>Back</anchor><br/>
</p>
</card>
</wml>
The main magic of the page occurs before the page is even generated. hs.ExecX10 will cause HomeSeer to
execute an X10 command. This is done by passing the device code and action to the script function direct
from the query string. To turn on device B3, simply call execx10.asp?dev=b3&action=on.
InstallationInstallation couldn't be easier, simply download the zip file below, and unzip it to your HomeSeer's HTML directory (probably, C:\Program Files\HomeSeer\html\). Ensure your preserve the directory structure when unzipping, since the main page is located in the html directory, while the ASP files are put in a "mobile" subdirectory. After that, start up HomeSeer, ensure your webserver is enabled (in View, Options). Next, use your WAP-enabled phone and point it to:http://38.107.179.210:8080/mobile.wml * * This is your current IP address, it might not be constant especially if you are using a dial-up connection. Also, port 8080 is the default HomeSeer webserver port, but you might need to change it - see your HomeSeer options.
Submitted: 17/11/2002 Article content copyright © James Matthews, 2002.
|
|
|||||||||||||
All content copyright © 1998-2007, Generation5 unless otherwise noted.
- Privacy Policy - Legal - Terms of Use -