Warning Older Docs! - You are viewing documentation for a previous released version of RhoMobile Suite.

RawSensors Module

The RawSensors Module is used to retrieve the raw data values of the specified sensors.

Syntax

RawSensors (Module) <META> Syntax

<META HTTP-Equiv="RawSensors" content="[method / parameter]">

<META HTTP-Equiv="RawSensors" content="sensorEvent:url('[jsFunction | url]')">

RawSensors JavaScript Object Syntax:
By default the JavaScript Object 'RawSensors' will exist on the current page and can be used to interact directly with the RawSensors.
To Invoke RawSensors methods via JavaScript use the following syntax: rawsensors.method();

e.g. RawSensors.getSensorData();
To Set RawSensors parameters via JavaScript use the following syntax: rawsensors.parameter = 'value'; remembering to enclose your value in quotes where appropriate.

e.g. RawSensors.accelerometer = 'value';
To Set RawSensors return events via JavaScript use the following syntax: rawsensors.event = JavaScript Function;

e.g. RawSensors.sensorEvent = 'doFunction(%json)';

For more details on the event syntax and parameters see the Retrieval Events page.
To set multiple EMML parameters / events on a single line use the following syntax: rawsensors.setEMML("[Your EMML Tags]");

e.g. RawSensors.setEMML("accelerometer:value;sensorEvent:url('JavaScript:doFunction(%json)');getSensorData");
RawSensors Ruby Object Syntax:
By default the Ruby Object 'RawSensors' will exist on the current page and can be used to interact directly with the RawSensors. All Methods, Parameters and Events are the same as JavaScript, however, notice 'RawSensors' needs to start with an uppercase letter. Another difference in Ruby is that methods do not end in '()'
To Invoke RawSensors methods via Ruby use the following syntax: RawSensors.method()

e.g. RawSensors.getSensorData
To Set RawSensors parameters via Ruby use the following syntax: RawSensors.parameter = 'value' remembering to enclose your value in quotes where appropriate.

e.g. RawSensors.accelerometer = 'value'
To Set RawSensors return events via Ruby use the following syntax: RawSensors.event = url_for(:action => :event_callback)

e.g. RawSensors.sensorEvent = url_for(:action => :rawsensors_event_callback)

For more details on the event syntax and parameters see the Retrieval Events page.

To access the event parameters in a Ruby callback function, you reference the @params object within the callback function. This object is simply a ruby hash {"parameter1 name" => "parameter1 value", "parameter2 name" => "parameter2 value", ...}

Methods

Items listed in this section indicate methods or, in some cases, indicate parameters which will be retrieved.

Name Description Default Value
getSensorData This immediately returns the raw data of the specified sensors via the sensorEvent N/A

Parameters

Items listed in this section indicate parameters, or attributes which can be set.

Name Possible Values Description Default Value
accelerometer:[Value] Enabled, Disabled This enables/disables the accelerometer sensor data retrieval. Disabled
deviceOrientation:[Value] Enabled, Disabled This enables/disables the device orientation sensor data retrieval. Disabled
tiltangle:[Value] Enabled, Disabled This enables/disables the tiltangle sensor data retrieval. Disabled
motion:[Value] Enabled, Disabled This enables/disables the motion sensor data retrieval. Disabled
ecompass:[Value] Enabled, Disabled This enables/disables the ecompass sensor data retrieval. Disabled
magnetometer:[Value] Enabled, Disabled This enables/disables the magnetometer sensor data retrieval. Disabled
gyroscope:[Value] Enabled, Disabled This enables/disables the gyroscope sensor data retrieval. Disabled
ambientlight:[Value] Enabled, Disabled This enables/disables the ambientlight sensor data retrieval. Disabled
proximity:[Value] Enabled, Disabled This enables/disables the proximity sensor data retrieval. Disabled
proximitylongrange:[Value] Enabled, Disabled This enables/disables the proximitylongrange sensor data retrieval. Disabled
pressure:[Value] Enabled, Disabled This enables/disables the pressure sensor data retrieval. Disabled
temperature:[Value] Enabled, Disabled This enables/disables the temperature sensor data retrieval. Disabled
humidity:[Value] Enabled, Disabled This enables/disables the humidity sensor data retrieval. Disabled
gravity:[Value] Enabled, Disabled This enables/disables the gravity sensor data retrieval. Disabled
linearAcceleration:[Value] Enabled, Disabled This enables/disables the linear acceleration sensor data retrieval. Disabled
rotation:[Value] Enabled, Disabled This enables/disables the rotation sensor data retrieval. Disabled
orientation:[Value] Enabled, Disabled This enables/disables the orientation sensor data retrieval. Disabled
all:[Value] Enabled, Disabled This enables/disables all the available sensors data retrieval. Disabled
minimumInterval:[Value] Value in milli seconds The minimum amount of time gap between two sensor update events, specified in milliseconds. The interval cannot be set to less than 200 milliseconds, if a value of less than 200 milli seconds is specified, the interval will be defaulted to 200 milli seconds. 1000 milliseconds

Events

Values are returned to the caller in RhoElements via Events. Most modules contain events and those returned from this module are given below along with the event parameters. Events can cause a navigation to a new URL or a JavaScript function on the page to be invoked. Each event will in most cases have a number of parameters associated with it which will either be strings or JavaScript arrays. Event parameters can be accessed either directly or via JSON objects.


sensorEvent

The sensorEvent event is triggered when a parameter of the specfiied sensors is changed.

ID Name Description
1 accelerometerX X co-ordinate value of the Accelerometer sensor in SI units (m/s^2)
2 accelerometerY Y co-ordinate value of the Accelerometer sensor in SI units (m/s^2)
3 accelerometerZ Z co-ordinate value of the Accelerometer sensor in SI units (m/s^2)
4 deviceOrientation value of the orientation sensor
5 tiltangleX X co-ordinate value of the tiltangle sensor in degrees units
6 tiltangleY Y co-ordinate value of the tiltangle sensor in degrees units
7 tiltangleZ Z co-ordinate value of the tiltangle sensor in degrees units
8 motion value of the motion sensor
9 ecompass value of the ecompass sensor
10 magnetometerX X value of the magnetometer sensor in micro-Tesla (uT) units
11 magnetometerY Y value of the magnetometer sensor in micro-Tesla (uT) units
12 magnetometerZ Z value of the magnetometer sensor in micro-Tesla (uT) units
13 gyroscopeX X co-ordinate value of the gyroscope sensor in radians/second units
14 gyroscopeY Y co-ordinate value of the gyroscope sensor in radians/second units
15 gyroscopeZ Z co-ordinate value of the gyroscope sensor in radians/second units
16 ambientLight value of the ambient Light sensor in SI lux units
17 proximity value of the proximity sensor in centimeters units
18 proximitylongrange value of the proximitylongrange sensor
19 pressure value of the pressure sensor in hPa (millibar) units
20 temperature value of the temperature sensor in degree Celsius units
21 humidity value of the humidity sensor in percent units
22 gravityX X co-ordinate value of the gravity sensor in SI units (m/s^2)
23 gravityY Y co-ordinate value of the gravity sensor in SI units (m/s^2)
24 gravityZ Z co-ordinate value of the gravity sensor in SI units (m/s^2)
25 linearAccelerationX X co-ordinate value of the linear acceleration sensor in SI units (m/s^2)
26 linearAccelerationY Y co-ordinate value of the linear acceleration sensor in SI units (m/s^2)
27 linearAccelerationZ Z co-ordinate value of the linear acceleration sensor in SI units (m/s^2)
28 rotationX X co-ordinate value of the rotation sensor as a combination of an angle and an axis
29 rotationY Y co-ordinate value of the rotation sensor as a combination of an angle and an axis
30 rotationZ Z co-ordinate value of the rotation sensor as a combination of an angle and an axis
31 orientationX X co-ordinate value of the orientation sensor in degrees units
32 orientationY Y co-ordinate value of the orientation sensor in degrees units
33 orientationZ Z co-ordinate value of the orientation sensor in degrees units

Remarks

sensor data format

Since the json object returned by the event contains the data for all of the sensors if a sensor is not enabled or absent then that data is undefined (null) and should not be used.

minimum interval

As some of the sensor values change rapidly the minimum interval between two updates should be specified as a reasonable value, otherwise there can be a performance impact.

Cross platform consistency

As this plugin returns the raw sensor values reported by the operating system the values might differ between platforms. Which sensors are supported on which platform are dependant on the hardware available on the device.

JavaScript and Meta-Tag Support

On iOS devices and non Motorola Solutions Windows Mobile/CE devices, only the Ruby interface is currently available. On all Android and Motorola Solutions devices all language interfaces are supported.

Requirements

RhoElements Version 2.1 or above
Supported Devices All supported devices. On Windows this is only supported in MPA3.0 devices.
Minimum Requirements None.
Persistence Non Persistent - Changes to this module will not persist when navigating to a new page.

HTML/JavaScript Examples

The following example enables all the sensors and waits for the updates through the sensor event

<META HTTP-EQUIV="RawSensors" CONTENT="sensorEvent:url('JavaScript:onSensor(%json);');all:enabled; ">

<SCRIPT>
    function onSensor(jsonObject)
    {
        var theOutput = "<BR><BR><B>Accelerometer  </B>";        
        theOutput = theOutput + "X: " + jsonObject.accelerometerX + ", Y: " + jsonObject.accelerometerY + ", Z: " + jsonObject.accelerometerZ + "<BR>";
        theOutput = theOutput + "<B>Orientation  </B>";        
        theOutput = theOutput + "X: " + jsonObject.deviceOrientation  + "<BR>";
        theOutput = theOutput + "<B>Tilt  </B>";
        theOutput = theOutput + "X: " + jsonObject.tiltangleX  + ", Y: " + jsonObject.tiltangleY  + ", Z: " + jsonObject.tiltangleZ  + "<BR>";
        theOutput = theOutput + "<B>Motion  </B>";
        theOutput = theOutput + "X: " + jsonObject.motion  + "<BR>";
        theOutput = theOutput + "<B>Ecompass  </B>";
        theOutput = theOutput + "X: " + jsonObject.ecompass  + "<BR>";
        theOutput = theOutput + "<B>Magnetometer  </B>";
        theOutput = theOutput + "X: " + jsonObject.magnetometerX  + ", Y: " + jsonObject.magnetometerY  + ", Z: " + jsonObject.magnetometerZ  + "<BR>";
        theOutput = theOutput + "<B>Gyroscope  </B>";
        theOutput = theOutput + "X: " + jsonObject.gyroscopeX  + ", Y: " + jsonObject.gyroscopeY  + ", Z: " + jsonObject.gyroscopeZ  + "<BR>";
        theOutput = theOutput + "<B>AmbientLight  </B>";
        theOutput = theOutput + "X: " + jsonObject.ambientLight  + "<BR>";
        theOutput = theOutput + "<B>Proximity  </B>";
        theOutput = theOutput + "X: " + jsonObject.proximity  + "<BR>";
        theOutput = theOutput + "<B>Proximitylongrange  </B>";
        theOutput = theOutput + "X: " + jsonObject.proximitylongrange  + "<BR>";
        theOutput = theOutput + "<B>Pressure  </B>";
        theOutput = theOutput + "X: " + jsonObject.pressure  + "<BR>";
        theOutput = theOutput + "<B>Temperature  </B>";
        theOutput = theOutput + "X: " + jsonObject.temperature  + "<BR>";
        theOutput = theOutput + "<B>Humidity  </B>";
        theOutput = theOutput + "X: " + jsonObject.humidity  + "<BR>";
        theOutput = theOutput + "<B>Gravity  </B>";
        theOutput = theOutput + "X: " + jsonObject.gravityX  + ", Y: " + jsonObject.gravityY  + ", Z: " + jsonObject.gravityZ  + "<BR>";
        theOutput = theOutput + "<B>Linear Acceleration  </B>";
        theOutput = theOutput + "X: " + jsonObject.linearAccelerationX  + ", Y: " + jsonObject.linearAccelerationY  + ", Z: " + jsonObject.linearAccelerationZ  + "<BR>";
        theOutput = theOutput + "<B>Rotation  </B>";
        theOutput = theOutput + "X: " + jsonObject.rotationX  + ", Y: " + jsonObject.rotationY  + ", Z: " + jsonObject.rotationZ  + "<BR>";
        theOutput = theOutput + "<B>Orientation  </B>";
        theOutput = theOutput + "X: " + jsonObject.orientationX  + ", Y: " + jsonObject.orientationY  + ", Z: " + jsonObject.orientationZ  + "<BR>";
        outputDiv.innerHTML = theOutput;
    }
</SCRIPT>
<div id="outputDiv">Sensor Output Goes Here</div>
<P>
  <INPUT align="center" type="button" value="Retrieve Sensor Data" onclick="RawSensors.getSensorData();"><br>
Back to Top