Tutorial: How to create a new Sensing-on-the-Go Sensor
This guide will go throught the basic setup and development process for creating a new Sensor Plugin for Sensing-on-the-Go app.
OrganiCity provides a set of common Sensor Plugins to be used. You can find and install all provided Sensors from the Sensors tab or when installing an experiment.
- Location Sensor
- Wifi Sensor
- Noise Sensor
- Ble Reader Sensor
- Temperature Sensor
Development Environement Setup
To setup a new Sensor Plugin you will need to follow these steps:
- Download and install Android Studio
- Clone the Sensing-on-the-Go repository and especially the ExampleSensor located in the sensors directroy
- Open the ExampleSensor project with Android Studio and install any missing packages
Setting up your own Sensor
When you open the Example Plugin project, navigate and open ExampleSensorService.
As you can see there are multiple TODO comments through out the code. Below are listed the key methods you need to pay attention during the development:
onCreate is called when your background service is first created (first call of startService()). Initialize your variables and request permissions here. An example is shown below in comments
onDestroy is called when your background service is going to be destroyed (call of stopService()). This is the place to unregister receivers, disconnect from services, stop and destroy threads and callbacks. If any object that is references elsewere is not destroyed the services may become a zombie service.
handleMessage is called whenever Sensing-on-the-Go app requested info from your Sensor Plugin. This is the place to add your data to the dataJson and as shown in the example. For example the Gps Plugin adds lontitude and latutide values:
dataJson.put(CONTEXT_TYPE + ".Latitude", location.getLatitude()); dataJson.put(CONTEXT_TYPE + ".Longitude", location.getLongitude());
CONTEXT_TYPE = eu.organicity.set.sensors.location.