This page was last modified 14:06, 19 June 2008.
How to use MWS to provide local device functionality
From Forum Nokia Wiki
Many Widset/Widget applications are limited by the fact that their APIs does not provide support for much of the functionality that is available to native applications. This could be functions like:
- Getting locations using the GPS module
- Taking photos with the camera
- Bluetooth connections
- Accessing Contacts, Inbox or External Applications
- Sending SMS
- and much more..
An easy fix is to use the Mobile Web Server to provide these functions. This can be achieved in a few steps:
Connecting to MWS from a Widset/Widget
The examples below shows how to get information from MWS
- Widget Example
function queryMWS()
{
// This code uses Prototype, but a standard javascript request will work just as well
new Ajax.Request("http://localhost/hello.py",
{
method: 'get',
asynchronous: 'false',
onSuccess: function(transport, json)
{
return true;
},
onFailure: function()
{
return false;
}
});
}
- Widset Example
void queryMWS()
{
// Prepare the URL.
String URL = "https://MWS_username:MWS_password@MWS_username.mymobilesite.net/hello.py";
// Fetch from the URL.
call(null, "httpLocalhost", "get", ["url" => URL], success, failure);
void success(Object state, Value ret)
{
setBubble(null, "The server successfully returned " + ret);
return;
}
void failure(Object state, String error)
{
setBubble(null, "Local server is not responding properly.");
return;
}
}
Using Python modules with MWS to provide local device functionality
Two files is necessary to get python executing on MWS:
- ht.acl
AddHandler mod_python .py PythonHandler cam PythonDebug On Options None Order Deny,Allow Allow from all <FilesMatch "\.(pyc)$"> Deny from all </FilesMatch>
- hello.py
def handler(req): from mod_python import apache import httplib try: # # Execute any python code here # req.write("Hello World") req.status = 200 return apache.OK except Exception, e: req.status = 404 return apache.OK
Good examples of how to use python modules can be found at the Mobile Python Book
- Example of using python to get the current location
def handler(req): from mod_python import apache import location import positioning req.content_type = 'text/xml' req.write("<?xml version='1.0' encoding='utf-8'?>") req.write("<twitnflick>") req.write("<modules count='" + str(len(positioning.modules())) + "' default='" + str(positioning.default_module()) + "'>") for n in range(0, len(positioning.modules())): req.write("<module id='" + str(positioning.modules()[n]['id']) + "'>") req.write("<name>" + positioning.modules()[n]['name'] + "</name>") req.write("<available>" + str(positioning.modules()[n]['available']) + "</available>") req.write("</module>") req.write("</modules>") positioning.set_requestors([{"type":"service","format":"application","data":"test"}]) gpspos = positioning.position() req.write("<position>") req.write("<latitude>" + str(gpspos['position']['latitude']) + "</latitude>") req.write("<longitude>" + str(gpspos['position']['longitude']) + "</longitude>") req.write("<altitude>" + str(gpspos['position']['altitude']) + "</altitude>") req.write("<horizontal_accuracy>" + str(gpspos['position']['horizontal_accuracy']) + "</horizontal_accuracy>") req.write("<vertical_accuracy>" + str(gpspos['position']['vertical_accuracy']) + "</vertical_accuracy>") req.write("</position>") req.write("</twitnflick>") return apache.OK
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Error installing MWS in N95 | canopus2 | Mobile Web Server | 1 | 2008-02-03 15:46 |
| How to write device driver | gpalvia | Symbian User Interface | 10 | 2005-04-20 20:37 |
| Extending Functionality of Noika PC suite | maan_navtej | Symbian Tools & SDKs | 1 | 2007-06-28 16:22 |
| PAMP install woes | eliotphillips | Mobile Web Server | 3 | 2008-08-14 09:02 |
| Some Queries | CooLTooL | Mobile Web Server | 6 | 2007-11-02 06:28 |
