You Are Here:

Community: Wiki

This page was last modified on 29 September 2009, at 02:14.

How to use MWS to provide local device functionality

From Forum Nokia Wiki

Reviewer Approved   

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..

As for now, according to the Web Developers' Library- messaging, media and location are available since WRT 1.1. An easy fix to obtain these functions in Widgets 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

AuthType Basic
AuthName 'Hello'
AuthBasicProvider file
AuthUserFile conf/passwords.txt
AuthGroupFile conf/groups.txt
 
# If you want to give access to all users
#Require valid-user
 
# If you want to give access to only yourself or some groups (add all needed groups delimited with space)
Require group admin
 
# If you want to give access to some users (add all needed users delimited with space)
#Require user quest
 
AddHandler mod_python .py
PythonHandler hello
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 and Python section.

* 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 Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fTalkE3aE4cargeE5fscreenE5fsaverX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqfntypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZtypeQUqfntypeZWikiContentQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqfntypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ
User Rating: qfnZuserE5FratingQNx3E2E0000X