Start the SensorDomo android app and enter the url of a web page you’ve written to be run on the phone.

The Javascript in your web page should subscribe to sensor events following the model described below and then implement the callbacks so that it can receive notification of the data available from the phone’s sensors.

Additionally, your Javascript can make some special calls that will cause the phone to send sensor data out to an external OSC server, and you can configure where this data is sent and the osc addressing for each sensor type. You can even send arbitrary OSC messages directly from within your Javascript code.

We plan to add the ability to configure sending the phone’s sensor data out to an external entity via WebSockets.

In order to write javascript that gets notified of sensor events, programmers should use the following model:

Inside your document ready javascript function, subscribe to one or many of the sensor events available. Currently the available options for <sensorName> are:

Then implement the function named <callbackName> in your Javascript code. The function will be called with a set of parameters that is pre-determined by the android application code and is based on the sensor data values that are available. The parameters required for each sensor type callback are as follows:

"SENSOR_TOUCH" - The callback function name you provide will be called with two parameters in the following order:

1) x location of the touch event in pixels
2) y location of the touch event in pixels

A warning about subscribing to touch events. If you want your web page to respond to html button clicks and text entry, you can’t subscribe to touch events. Once you subscribe for touch events, those touch events are no longer propagated to the web view where your buttons and other html widgets live. You can always subscribe for touch events, then unsubscribe later, as long as you can trigger the unsubscribe call without needing the user to interact with HTML widgets. For example, you could register for accelerometer events, and then register for touch events, and use the touch screen functionality for awhile. You would write some Javascript which would watch the accelerometer data and unsubscribe from the touch events when it sees the phone turned upside down.

"SENSOR_ORIENTATION" - The callback function name you provide will be called with three parameters in the following order:

1) azimuth in degrees
2) pitch in degrees
3) roll in degrees

“SENSOR_ACCELEROMETER” - The callback function name you provide will be called with three parameters in the following order:

“SENSOR_LIGHT” - The callback function name you provide will be called with the following parameter:

1) light value

“SENSOR_PROXIMITY” - The callback function name you provide will be called with the following parameter:

1) proximity value

“SENSOR_GPS” - The callback function name you provide will be called with two parameters in the following order:

1) latitude
2) longitude

If you want to unsubscribe from certain sensor events when you don’t need them anymore, you can save some battery by doing so. The way to unsubscribe is by using the following function call:

unsubscribeSensor(<sensorName>)

Where <sensorName> is one of the sensor names described above.

As mentioned above, all sensor data can be forwarded to a list of remote servers via OSC messages. To achieve this behavior, call the following function from within your Javascript code:

addOscServer(<ip-address>, <port>, <sensorId>, <oscAddress>);

Where the sensorId strings are the same as for subscribing to events for your Javascript code. Also, you should specify an OSC address in this function call so that the android application will know where to address your sensor data on the remote machine. Example: