You Are Here:

Community: Wiki

This page was last modified on 30 September 2009, at 02:26.

Sensors Service in WRT

From Forum Nokia Wiki

Reviewer Approved   

Note that the Platform Services extensions were introduced for S60 5th edition, thus they do not work with older devices.

As with other Service APIs the interface for Sensors is retrieved using the device entry point. The service object is Service.Sensor and the interface is ISensor. Thus to retrieve the interface for the API you need to call following code in your application:

so = device.getServiceObject("Service.Sensor","ISensor");

Contents

Functions provided by the API

  1. FindSensorChannel
  2. RegisterForNotification
  3. Cancel
  4. GetChannelProperty
  5. SetChannelProperty

Finding sensors

As different devices do provide different sets of sensors, you need to find out which sensors the device you are running on has. To do this, you could define the criteria to find all possible sensors as follows:

var SensorParams = {
SearchCriterion : "All"
};
var result = so.ISensor.FindSensorChannel(SensorParams);

The SearchCriterion could also be defined to find some specific sensor, with 5th edition following sensor identifiers has been defined:

  • All
  • AccelerometerAxis
  • AccelerometerDoubleTapping
  • Orientation
  • Rotation

The result.ErrorCode provides error codes where the 0 means no error, the result.ErrorMessage would have the human readable error description.

The result.ReturnValue would then include the list of found channel maps, which you could iterate through to find out the sensors that are available in that particular device.

The map includes following 32 bit integer values:

  • ChannelId: Unique ID representing the channel.
  • ContextType: Defines the context in which the channel is available.
  • Quantity: Defines the quantity being sensed.
  • ChannelType: Defines a unique type id for each channel.
  • DataItemSize: Data item size delivered in the channel.
  • ChannelDataTypeId: Unique data type identifier for the data being sensed.

And following string values:

  • Location: Location of the sensor related to channel.
  • VendorId: Vendor Id of the sensor related to channel.


The ContextType values are defined as follows:

0: Not defined

1: Ambient sensor eg. To measure pressure

2: Gives info on device itself

3: Measures user initiated stimulus.


And the Quantity values are defined as follows:

0: Not defined

10: Acceleration

11: Tapping

12: Orientation

13: Rotation

14: Magnetic

15: Tilt

Starting Sensor data retrieval

To start data retrieval, you need to first find the sensor so you can utilize the map for the sensor to start the data retrieval. You also need to define callback function that is called when there is data available for the sensor.


You can also have multiple sensors active at any given time. To start them all, you could use the full map list gotten from previous step, and just loop the result and start data retrieval for each sensor separately with following code:

for (var i = 0; i < result.ReturnValue.length; i++) 	
{
var SensorParams = {
ListeningType: "ChannelData",
ChannelInfoMap: result.ReturnValue[i]
};
 
var result2 = so.ISensor.RegisterForNotification ( SensorParams, SenssCallback);
}

You could also define the ListeningType as “ChannelPropertyChange”, which would then mean that you are not listening the actual data, but the changes on sensor properties.

Retrieving the sensor Data

After calling the RegisterForNotification, the callback defined will be called when ever there is data available for the requested sensor. The callback function could be defined for example as follows:

function SenssCallback(id1, id2, result){
 
var returnvalue = result.ReturnValue;
var datatype = returnvalue.DataType;
if (datatype == "AxisData")
{
var xaxisdata = returnvalue.XAxisData;
var yaxisdata = returnvalue.YAxisData;
var zaxisdata = returnvalue.ZAxisData;
// do something with the data.
}
}

The result variable has the results for the selected sensor, the id1 identifies the transaction id that could be used for canceling original request, so no more dat would be supplied for the request.

With all results there is ReturnValue.TimeStamp that tells the time when the data was obtained, there is also always a datatype string identified ReturnValue.DataType, which can be used to determine the datatype for the sensor data, following types are defined:

  • “AxisData” for AccelerometerAxis sensor
  • “DoubleTappingData” for AccelerometerDoubleTapping sensor
  • “OrientationData” for Orientation sensor
  • “RotationData” for Rotation sensor
  • “ChannelPropertyChange” for ChannelPropertyChange events.

Type specific additional data for AxisData for which all are 32 bit integer values include:

  • XAxisData
  • YAxisData
  • ZAxisData

Type specific additional data for DoubleTappingData includes only one 32 bit integer value:

  • DeviceDirection.

Type specific additional data for OrientationData includes only one string value: DeviceOrientation. This string can have following values:

  • Undefined
  • DisplayUp
  • DisplayDown
  • DisplayLeftUp
  • DisplayRightUp
  • DisplayUpwards
  • DisplayDownwards

Type specific additional data for RotationData for which all are 32 bit integer values include:

  • XRotation
  • YRotation
  • ZRotation

Type specific additional data for ChannelPropertyChange includes following 32 bit integer values:

  • ItemIndex
  • PropertyDataType

, and following values that can either be 32 bit integers, doubles or strings:

  • PropertyMinValue
  • PropertyMaxValue
  • PropertyValue

, and following Strings:

  • DataType
  • PropertyId

, as well as boolen value called: ReadOnly, that identified whether the property is read only or not.


The datatype defines the types for the property values, this identified can have following values:

0: For Integer datatype

1: For Double datatype

2: For String datatype


The PropertyId can have following values:

  • DataRate
  • Availability
  • MeasureRange
  • ChannelDataFormat
  • ChannelAccuracy
  • ChannelScale
  • ScaledRange
  • ChannelUnit
  • SensorModel
  • ConnectionType
  • Description

Simple Example

Hello Sensor ZIP archive

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: qdcZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fNFCX qdcZpublisherQUxhttpE3aE2fE2fswE2enokiaE2ecomE2fidE2fc764fd1cE2d8b06E2d499aE2d9a6aE2d17c3903d5a65E2fforumE5fnokiaE5fcrawlerE5fagentX qdcZtitleQSxNFCE20E2dE20ForumE20NokiaE20WikiX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqfntypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qrssZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qfnZdistributionQUxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2fX qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZtypeQUqfntypeZWikiContentQ qfnZupdatedQDx2008E2d10E2d03X qfnZuserE5ftagQSx62121X qfnZuserE5ftagQSxnfcX qfnZuserE5ftagQSxpushregistryX qmarsZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqfntypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ