evothings.iotsensor. instance
Source: evothings-libraries/
Abstract IoTSensor instance object that defines a common interface.
Methods
Methods
accelerometerCallback(callbackFun)
RAW and SFL
Set the accelerometer notification callback. This function is called everytime new data is available.
Data is returned in g (x, y, z)
Example
iotsensor.accelerometerCallback(
function(data)
{
console.log('Accelerometer data: '
+ data.x + 'g '
+ data.y + 'g '
+ data.z + 'g');
}
);
Parameter
Name | Type | Optional | Description |
---|---|---|---|
callbackFun |
function() |
|
Callback called with accelerometer data: callbackFun(data). |
accelerometerOff()
RAW and SFL
Turn off accelerometer notification.
Example
iotsensor.accelerometerOff();
accelerometerOn()
RAW and SFL
Turn on accelerometer notification.
Make sure the callback function is set before turning on the sensor
Example
iotsensor.accelerometerOn();
barometerCallback(callbackFun)
RAW and SFL
Set the barometer notification callback. This function is called everytime new data is available.
Data is returned in Pascal (whole number)
Example
iotsensor.barometerCallback(
function(data)
{
console.log('Barometer data: ' + data + 'Pa');
}
);
Parameter
Name | Type | Optional | Description |
---|---|---|---|
callbackFun |
function() |
|
Callback called with barometer data: callbackFun(data). |
barometerOff()
RAW and SFL
Turn off barometer notification.
Example
iotsensor.barometerOff();
barometerOn()
RAW and SFL
Turn on barometer notification.
Make sure the callback function is set before turning on the sensor
Example
iotsensor.barometerOn();
disableAllSensors()
RAW and SFL
Turn off all sensors.
Example
iotsensor.disableAllSensors();
errorCallback(errorFun)
Set the error handler function.
If no errorCallback is set, the default handler will be called:
console.log(evothings.iotsensor.currentTime() + ' IoT Sensor error: ' + error);
Parameter
Name | Type | Optional | Description |
---|---|---|---|
errorFun |
function() |
|
Callback called with error: errorFun(error) |
getDeviceModel() → string
Return the device model
Example
var model = iotsensor.getDeviceModel();
console.log('Device model ' + model);
- Returns
-
string
getFirmwareString() → string
Return the firmware version on the device
Example
var version = iotsensor.getFirmwareString();
console.log('Firmware version: ' + version);
- Returns
-
string
gyroscopeCallback(callbackFun)
RAW and SFL
Set the gyroscope notification callback. This function is called everytime new data is available.
Data is returned in degrees per second (x, y, z)
Example
iotsensor.gyroscopeCallback(
function(data)
{
console.log('Gyroscope data: '
+ data.x + 'degrees per second '
+ data.y + 'degrees per second '
+ data.z + 'degrees per second');
}
);
Parameter
Name | Type | Optional | Description |
---|---|---|---|
callbackFun |
function() |
|
Callback called with gyroscope data: callbackFun(data). |
gyroscopeOff()
RAW and SFL
Turn off gyroscope notification.
Example
iotsensor.gyroscopeOff();
gyroscopeOn()
RAW and SFL
Turn on gyroscope notification.
Make sure the callback function is set before turning on the sensor
Example
iotsensor.gyroscopeOn();
humidityCallback(callbackFun)
RAW and SFL
Set the humidity notification callback. This function is called everytime new data is available.
Data is returned in % (whole number)
Example
iotsensor.humidityCallback(
function(data)
{
console.log('Humidity data: ' + data + '%');
}
);
Parameter
Name | Type | Optional | Description |
---|---|---|---|
callbackFun |
function() |
|
Callback called with humidity data: callbackFun(data). |
humidityOff()
RAW and SFL
Turn off humidity notification.
Example
iotsensor.humidityOff();
humidityOn()
RAW and SFL
Turn on humimdity notification.
Make sure the callback function is set before turning on the sensor
Example
iotsensor.humidityOn();
isAccelerometerAvailable() → boolean
Checks if the accelerometer is available.
Example
// Check if accelerometer is available
if(iotsensor.isAccelerometerAvailable())
{
iotsensor.accelerometerOn();
}
- Returns
-
boolean
isBarometerAvailable() → boolean
Checks if the barometer is available.
Example
// Check if barometer is available
if(iotsensor.isBarometerAvailable())
{
iotsensor.barometerOn();
}
- Returns
-
boolean
isGyroscopeAvailable() → boolean
Checks if the gyroscope is available.
Example
// Check if gyroscope is available
if(iotsensor.isGyroscopeAvailable())
{
iotsensor.gyroscopeOn();
}
- Returns
-
boolean
isHumidityAvailable() → boolean
Checks if the humidity sensor is available.
Example
// Check if humidity sensor is available
if(iotsensor.isHumidityAvailable())
{
iotsensor.humidityOn();
}
- Returns
-
boolean
isMagnetometerAvailable() → boolean
Checks if the magnetometer is available.
Example
// Check if magnetometer is available
if(iotsensor.isMagnetometerAvailable())
{
iotsensor.magnetometerOn();
}
- Returns
-
boolean
isSflAvailable() → boolean
Checks if Sensor Fusion is available.
Example
// Check if sensor fusion is available
if(iotsensor.isSflAvailable())
{
iotsensor.sflOn();
}
- Returns
-
boolean
isTemperatureAvailable() → boolean
Checks if the temperature sensor is available.
Example
// Check if temperature sensor is available
if(iotsensor.isTemperatureAvailable())
{
iotsensor.temperatureOn();
}
- Returns
-
boolean
magnetometerCallback(callbackFun)
RAW and SFL
Set the magnetometer notification callback. This function is called everytime new data is available.
Data is returned in micro Tesla (x, y, z)
Example
iotsensor.magnetometerCallback(
function(data)
{
console.log('Magnetometer data: '
+ data.x + 'µT '
+ data.y + 'µT '
+ data.z + 'µT');
}
);
Parameter
Name | Type | Optional | Description |
---|---|---|---|
callbackFun |
function() |
|
Callback called with magnetometer data: callbackFun(data). |
magnetometerOff()
RAW and SFL
Turn off magnetometer notification.
Example
iotsensor.magnetometerOff();
magnetometerOn()
RAW and SFL
Turn on magnetometer notification.
Make sure the callback function is set before turning on the sensor
Example
iotsensor.magnetometerOn();
sflCallback(callbackFun)
SFL only
Set the sensor fusion notification callback. This function is called everytime new data is available.
Data is returned in 4 axis (w, x, y, z)
Example
iotsensor.sflCallback(
function(data)
{
console.log('Sensor fusion data: '
+ data.w + ' '
+ data.x + ' '
+ data.y + ' '
+ data.z);
}
);
Parameter
Name | Type | Optional | Description |
---|---|---|---|
callbackFun |
function() |
|
Callback called with sensor fusion data: callbackFun(data). |
sflOff()
SFL only
Turn off sensor fusion notification.
Example
iotsensor.sflOff();
sflOn()
SFL only
Turn on sensor fusion notification.
Make sure the callback function is set before turning on sensor fusion
Example
iotsensor.sflOn();
statusCallback(statusFun)
Set the status handler function.
If no statusCallback is set, the default handler will be called:
console.log(evothings.iotsensor.currentTime() + ' IoT Sensor status: ' + status);
Parameter
Name | Type | Optional | Description |
---|---|---|---|
statusFun |
function() |
|
Callback called with status: statusFun(status); |
temperatureCallback(callbackFun)
RAW and SFL
Set the temperature notification callback. This function is called everytime new data is available.
Data is returned in degrees Celcius (2 decimals)
Example
iotsensor.temperatureCallback(
function(data)
{
console.log('Temperature data: ' + data + '°C');
}
);
Parameter
Name | Type | Optional | Description |
---|---|---|---|
callbackFun |
function() |
|
Callback called with temperature data: callbackFun(data). |
temperatureOff()
RAW and SFL
Turn off temperature notification.
Example
iotsensor.temperatureOff();
temperatureOn()
RAW and SFL
Turn on temperature notification.
Make sure the callback function is set before turning on the sensor
Example
iotsensor.temperatureOn();