SensorLab: Sensor Libraries Explained
In my previous article, I introduced SensorLab and explained how to create a Samsung Smartwatch application in a mere 6 minutes. But I didn’t explain each sensor library files in detail to control the length of the article, which will be taken care of in this article.
Sensor Library
The sensor library is created using web APIs. It includes JavaScript files for all sensors with at most three functions, value variables, HTML variable for each sensor. They are described as:
- The functions are used to start/stop and get sensor hardware information.
- The value variable stores the values fetched from the sensor.
- The Html variable holds the value variable to display on the front-end/watch screen.
Functions and variables associated with each sensor/actuator are described in the following sections.
- Light Sensor
It is a photodetector which senses the ambient light falling on the smartwatch screen.
- getLight() function starts the light sensor and the fetched light value is assigned to the value variable ‘light’.
- getLightInfo() function displays the light sensor hardware information in the Tizen output console only during the emulator mode(refers to running the app on the Tizen watch emulator).
- stopLight() function stops the light sensor.
- ‘light’ is the value variable which gets initialized with values ranging from 0–100% when getLight() function is called.
- ‘lightRateEl’ is the HTML variable which is connected to the HTML element in the index.html file or front-end (What the user sees.)
2. Pressure Sensor/ Barometer
It is a sensor used to measure atmospheric pressure.
- getPressure() function starts the pressure sensor and the fetched pressure value is assigned to the value variable ‘pressure’.
- getPressureInfo() function displays the pressure sensor hardware information in the Tizen output console only during the emulator mode(refers to running the app on the Tizen watch emulator).
- stopPressure() function stops the pressure sensor.
- ‘pressure’ is the value variable which gets initialized with values ranging from 260–1260hPa when getPressure() function is called.
- ‘pressureRateEl’ is the HTML variable which is connected to the HTML element in the index.html file or front-end (What the user sees.)
3. Acceleration Sensor/Accelerometer
It is a sensor which measures the rate of change of velocity of a body
- getAccelerometer() function starts the Accelerometer sensor and the fetched Accelerometer values is assigned to the value variables ‘ax’, ‘ay’, ‘az’.
- getAccelerometerInfo() function displays the Accelerometer sensor hardware information in the Tizen output console only during the emulator mode(refers to running the app on the Tizen watch emulator).
- stopAccelerometer() function stops the Accelerometer sensor.
- ‘ax’, ‘ay’, ‘az’ are the value variables along the x-axis, y-axis, z-axis which gets initialized with values ranging from -19.6–19.6, when getAccelerometer() function is called.
- ‘accelerometerRateEl’ is the HTML variable which is connected to the HTML element in the index.html file or front-end (What the user sees.)
4. Gravity Sensor
An accelerometer at rest measures rate of change of velocity due to Earth’s gravity.
- getGravity() function starts the gravity sensor and the fetched gravity values are assigned to the value variable ‘grx’, ‘gry’, ‘grz’.
- getGravityInfo() function displays the gravity sensor hardware information in the Tizen output console only during the emulator mode(refers to running the app on the Tizen watch emulator).
- stopGravity() function stops the gravity sensor.
- ‘grx’, ‘gry’, ‘grz’ are the value variables along the x-axis, y-axis, z-axis which gets initialized with values ranging from -19.6–19.6, when getGravity() function is called.
- ‘garvityRateEl’ is the HTML variable which is connected to the HTML element in the index.html file or front-end (What the user sees.)
5. Gyroscope Sensor
It is a sensor which determines the object orientation to Earth’s gravity.
- getGyroscope() function starts the gyroscope sensor and the fetched gyroscope values are assigned to the value variable ‘grx’, ‘gry’, ‘grz’.
- getGyroscopeInfo() function displays the gyroscope sensor hardware information in the Tizen output console only during the emulator mode(refers to running the app on the Tizen watch emulator).
- stopGyroscope() function stops the gyroscope sensor.
- ‘gx’, ‘gy’, ‘gz’ are the value variables along the x-axis, y-axis, z-axis which gets initialized with values ranging from -32768–32768, when getGyroscope() function is called.
- ‘GyroscopeRateEl’ is the HTML variable which is connected to the HTML element in the index.html file or front-end (What the user sees.)
6. GPS Sensor
Get Geoff Thomas’s stories in your inbox
Join Medium for free to get updates from this writer.
It is a sensor which gets the device position, velocity information from satellites.
- getGps() function starts the GPS sensor and the fetched GPS values is assigned to the value variables ‘Latitude’, ‘Longitude’, ‘Altitude’, ‘Speed’.
- stopGps() function stops the GPS sensor.
- ‘Latitude’, ‘Longitude’ is the value variables which gets initialized with latitude and longitude when getGps() function is called.
- ‘Altitude is the value variable which gets initialized with altitude when getGps() function is called.
- ‘speed’ is the value variable which gets initialized with speed, when getGps() function is called.
- ‘gpsRateEl’ is the HTML variable containing latitude and longitude values, which is connected to the HTML element in the index.html file or front-end (What the user sees.)
- ‘altitudeRateEl’ is the HTML variable containing the altitude value, which is connected to the HTML element in the index.html file or front-end (What the user sees.)
- ‘speedRateEl’ is the HTML variable containing the speed value, which is connected to the HTML element in the index.html file or front-end (What the user sees.)
7. Heart Rate Sensor
It is a sensor which measures the heart rate in real-time.
- getHeartrate() function starts the heart rate sensor and the fetched light value is assigned to the value variable ‘light’.
- stopHeartrate() function stops the heart rate sensor.
- ‘heart_rate’ is the value variable which gets initialized with values ranging from 0–250Bpm when getHeartrate() function is called.
- ‘heartRateEl’ is the HTML variable which is connected to the HTML element in the index.html file or front-end (What the user sees.)
8. Pedometer
It is a sensor which measures the steps based on hand and hip movement.
- getPedometer() function starts the pedometer sensor and the fetched pedometer values are assigned to the value variables ‘step’ and ‘step_status’.
- stopPedometer() function stops the light sensor.
- ‘step’ is the value variable which gets initialized with step count when getPedometer() function is called.
- ‘step_status’ is the value variable which gets initialized with step status when getPedometer() function is called.
- ‘pedometerRateEl’ is the HTML variable which is connected to the HTML element in the index.html file or front-end (What the user sees.)
9. Vibrator
It is an actuator to give vibration feedback.
- vibrate(milliseconds) function starts the vibrator for the given time milli-seconds. It is used as a feedback mechanism.
10. Back Button
It is a button which performs the “go back” function.
- backButton() function initializes the back button of the smartwatch to close the application when pressed.
- backButtonCheck() function checks if the back button is pressed and return a Boolean.
11. RequestToWebapp
It is an extra set of the function used to communicate with SensorLab web application to visualize and store at most three sensor readings. The SensorLab web application is described in the next section.
- postWebapp(value 1, value 2, value 3) function can take three sensor readings and makes a POST HTTP request to the SensorLab web application for graphical visualization.
- getWebapp( ) function makes a GET HTTP request to the SensorLab web application to return all the sensor readings stored in the Web app database.
- putWebapp(color-code) function can take a hexadecimal colour code ranging from 0-FFFFFF and makes a PUT HTTP request to the SensorLab web application to change the colour picker colour.
Sensor Library Table
After understanding how to use the library to manipulate one sensor, then all you need is the table given below which has a summary of all the functions and sensors available. Don’t get overwhelmed by the table length, trust me all the information in each row is very similar. If you can manipulate one sensor that means that you can manipulate all the sensors.
Please let me know in the comments, whether you wish me to write a continuation article with more focus on RESTful App development.
Thank you for your patient reading. If you enjoyed this article, feel free to hit that clap button 👏 to help others find it. (Did you know? You can clap more than once. Try it and see for yourself!).Don’t hesitate to drop a comment, if you are stuck or have doubts. Happy Coding!







