Skip to content

Latest commit

 

History

History
241 lines (165 loc) · 10.2 KB

setup.wiki

File metadata and controls

241 lines (165 loc) · 10.2 KB

PageOutline

Table of Contents

How to setup Sensibility Testbed

To setup and do experiments on the Sensibility Testbed, we need the following steps:

1. Building an installer (to install on your device); 2. Installing the installer you just created; 3. Setting up the environment to run an experiment (we call this environment demo kit in the following), and 4. Running your experiment!

To complete these steps, you will need (1) a desktop or laptop, and (2) an Android phone. It is also recommended that you create a working directory on your desktop or laptop, for storing downloaded files (your user keys, demo kit, etc). The following is a step-by-step guide to complete the steps.

Building an installer

Go to the ​Custom Installer Builder (CIB) Fastlane site. It will look similar to Figure 1 below.

||Image(cib_fastlane.png, align=center)|| Figure 1: Custom Installer Builder (CIB) screenshot

The builder creates a pair of cryptographic keys for you. Download both the public and private keys before continuing. Then, proceed to open the CIB page on your Android device, either by typing the URL highlighted in yellow, or by scanning the QR code. Follow the page's instructions to complete the setup of Sensibility Testbed on your Android device.

Make sure to use the full URL, including the long hex string at the end! Only the full URL identifies your install and ensures that the cryptographic keys can be used on it!

Setting up demo kit

  • On you laptop, download the Demokit and unzip it using . This will create a folder named .
  • Unzip both of the key archives ( and ) downloaded previously, and you will get two key directories, and . Copy the key files from these two directories (Note: key files, not key directories) into the directory. Then, into this directory and run:
  • Now, needs your key pair to contact your devices, so you will first load user keys for the username you selected on the CIB site (here, "user") with . Next, tells to look for devices installed with these keys.

 If you installed the installer with the same keys on your device, then you will see something similar to the above. This tells you that ''seash'' has discovered the device.

 '''Important:''' If {{{browse}}} returned fewer devices than expected, or certain devices timed out, wait and re-execute the command. Or, you could exit ''seash'', reload keys, and browse again.

Running an experiment

Start running code. First, make yourself the device (notice the change of user@):

If you have more than one devices, then `browse` will return more than one targets. To control all of the devices, run `on browsegood` instead of `on %1` above.

Next, upload the required sensor access libraries to your target. (The demokit includes them in a folder named `sensorlib` for your convenience.)

This will print out the uploaded files' names as it proceeds. Finally, the code you would like to run, and use to verify they are correctly uploaded. We'll test the accelerometer in the following example (can be downloaded here), but the other sensor examples work the same:

 Start the code as follows, and use {{{show log}}} to see the output from your code:

These are accelerations along the x/y/z axes. The z value will be close to 9.8 if the phone is stationary, due to gravity.

Once the experiment is finished, use to stop the code.

How to write an experiment on Sensibility Testbed

Repy API

The experiment code in Sensibility Testbed is written in Repy (Restricted Python). The Repy API can be found here. The examples of using the API can be found on this page.

Sensor library

Writing an experiment on Sensibility Testbed is straight-forward. All the library API can be found on this page.

Examples

Accelerometer Example

We first need to start sensing on your phone by calling



Such that your phone will start recording sensor data. sensor_number is any of the following integer: 1 = All, 2 = Accelerometer, 3 = Magnetometer and 4 = Light; delay_time: minimum time between readings in ms, also in integer. Then call



This will return the most recently received accelerometer value in a list, e.g., [0.3830723,] as the acceleration on the X, Y, and Z axis. To stop recording sensor data, call


Here is a complete example of getting 100 sample of accelerometer data. The `log` statement prints the data to the console.

Location Example

Location on Android devices depends on external services (GPS, !WiFi or cellular networks). We highly recommend that you include some error handling in your code, such as

The call `get_location()` (details in the next section) returns real-time location data from the device. However, when this call cannot get any location data from those external services, or `location == None`, we can try to get the previously cached location on the device, using `get_lastknown_location()`:

The returned data can look like this:

}

Note that the location data returned comes from three different providers: network, GPS, and passive. The complete example can be found here.

Input arguments

You can have input arguments to your experiment code. For example,

`1`, `2` and `3` will be the input arguments for `accelerometer.r2py`. Use the `callargs` list variable to access them in your code: This snippet

will print out this list of strings of arguments:

Saving data to a file

Instead of printing data to the log console, you can save the data to a file on the device. Here is how to do this:

`filename` is a string that specifies the name of your data file. `myfileobject` is the file handler for the data file. In `openfile()`, `True` is a Boolean flag that specifies if the file should be created if it does not exist. If the file exists, this flag has no effect. `writeat()` seeks to an offset in the file (0 in this case) and then write the data to the file.

If you like to check if a file exists in the current directory, and if so, delete this file. This is how to do it:

The Repy file API can be found here.

Please tell us how you think!

Please take a moment to fill out our feedback form. Your comments and feedback will be tremendously helpful to us!