The attached web server offers some options to control the device or show information about it. The web server runs on the device and enables direct control or delivers information about the device.
The project enclosed default web page offers all implemented commands. The following is a list of what is currently implemented:
SystemInfo
: Get OS version info
BEEP
: Let the device beep
START
: Starts a process
KILL
: Kills a process
SETLED
: Light/unlight/blink a LED
VIBRATE
: Special LED case, this sets a LED which is a placeholder for the vibrate motor
SIP
: Show/hide the Software Keyboard
SHOW
: ShowWindow implementation (show normal, hide, minimize, etc.)
ENABLEWINDOW
: Enable or disable a window
The Default Web Page
If you click a function (command), the output is displayed at the bottom of the example default page:
You can also call the functions directly from any web browser that has access to the devices network and get only the answer back.
In example, calling “http://192.168.128.100:8088/ahah.html?SystemInfo” will give you “‘SystemInfo’ ”, ‘Microsoft Windows CE 5.2.29040′ = OK” or so.
Reflection Instead of switch() or If/ElseIf
These commands can be easily extended as the code uses reflection to look up the commands you send. This is a better approach than doing a If
/ElseIf
or Switch()
search for known commands:
public static bool execCmd(string sFunc, string sArg, ref string sResponse)
{
bool bRet = true;
try
{
myCommands cmbn = new myCommands(sFunc, sArg);
MethodInfo methodInfo = typeof(myCommands).GetMethod(sFunc);
methodInfo.Invoke(cmbn, null);
sResponse = cmbn.response;
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine
("Exception in execCmd for '" + sFunc + "' and '" + sArg + "' " + ex.Message);
bRet = false;
}
return bRet;
}
...
The myCommands
class looks like this and is easy to extend:
class myCommands
{
string name;
string arg="";
public string response="";
public myCommands(string name, string sArg)
{
this.name = name;
this.arg = sArg;
}
public void SystemInfo()
{
string sOS = System.Environment.OSVersion.ToString();
response = sOS;
}
public void BEEP()
{
beepType beep = (beepType)Enum.Parse(typeof(beepType), arg, false);
MessageBeep(beep);
}
...
So, if you need to add an command, simply add a new function inside myCommands
class using arg
and response to communicate with the web server.
Code and Binary
The Visual Studio 2008 source code is written against Compact Framework 2.0. There are two projects, one is the great CompactWeb
web server and the other is the webCommand
project. The webCommand
project includes a directory inetpub, which is deployed below the applications directory.
inetpub Directory
- default.html
This is the default web site containing examples for all commands. For example:
<html>
<script language="javascript"
type="text/javascript" src="ahah.js"></script>
<script language="javascript" type="text/javascript">
function load(filename) {
ahah(filename,"content");
}
</script>
<body>
<p>WebCommands TestPage</p>
<h2>Informations</h2>
<ul id="SystemInfo">
<li><a href="javascript:load
('ahah.html?SystemInfo');">OS Version</a></li>
</ul>
...
- javascript.js
Simply loads ahah.js and implements the load
function (asynchronously call (AJAX) technology).
- ahah.js
This JavaScript library does asynchronously call the ‘web commands’ (AJAX).
The rest of the files are included for testing. The same is valid for the server dir, which contains example files which will work on an external web server (i.e., XAMPP on windows), if cross-side scripting is allowed. The server files contain fixed IP address for the device and have to be changed if you would like to test cross-side scripting.
I insist on your fantasy, what else is possible. Some examples: get a screenshot, get extended device information, get a process list…….