Namespace: instance_ble

.iotsensor. instance_ble

Abstract IoT Sensor instance object. This object specifies the interface common to BLE IoT Sensors

Methods


connectToClosestSensor(scanTime, callbackFun, disconnectFun)

Connect to nearest IoT Sensor device.
Parameters:
Name Type Description
scanTime integer Time (in ms) to scan for nearby IoT Sensors (optional, default 2 seconds)
callbackFun function Callback called when connected and device is initalized
disconnectFun function Callback called when connection is lost (optional)
Example
iotsensor.connectToClosestSensor(
	3000, // Scan for 3000 ms
	function()
	{
		// Connected and device is ready
	},
	function(error)
	{
		console.log('Disconnect error ' + error);
	}
);

connectToDevice(device, callbackFun, disconnectFun)

Connect to an IoT Sensor device
Parameters:
Name Type Description
device evothings.easyble.EasyBLEDevice A evothings.easyble.device object
callbackFun function Callback called when connected and device is initialized
disconnectFun function Callback called when connection is lost (optional)
Example
iotsensor.connectToDevice(
	device,
	function()
	{
		// Connected and device is ready
	},
	function(error)
	{
		console.log('Disconnect error ' + error);
	}
);

disableAllSensors()

RAW and SFL. Implementation of evothings.iotsensor.instance#disableAllSensors
Example
iotsensor.disableAllSensors();

disconnectDevice()

Disconnect from the connect device
Example
iotsensor.disconnectDevice();

isIoTSensor(device)

Determine if a BLE device is a IoT Sensor.
Checks the general case using the advertised name.
Specific implementation is added for SFL and RAW.
Parameters:
Name Type Description
device evothings.easyble.EasyBLEDevice easyble device object
Returns:
Type
boolean
Example
if(iotsensor.isIoTSensor(device))
{
	// connect to device
}

startScanningForDevices(callbackFun)

Start a manual scan for physical devices.
This process can be automated by using connectToClosestSensor(scanTime, callbackFun, disconnectFun)
The device (evothings.easyble.EasyBLEDevice) that is found is passed to callbackFun and can be used to inspect device fields to determine properties such as RSSI, name etc.
You can call isIoTSensor(device) to determine if this is an IoT sensor. To connect, call connectToDevice(device, callbackFun, disconnectFun).
Parameters:
Name Type Description
callbackFun function Callback called with found device: callbackFun(device).
Example
iotsensor.startScanningForDevices(
	function(device)
	{
		console.log('Device found: ' + device.name + ' RSSI: ' + device.rssi);
		if(iotsensor.isIoTSensor(device))
		{
			// We have an IoT Sensor, let's connect!
			iotsensor.connectToDevice(
				device,
				function()
				{
					// Connected and device is ready
				},
				function(error)
				{
					console.log('Disconnect error ' + error);
				}
			);
		}
	}
);

stopScanningForDevices()

Stop scanning for physical devices and call statusCallback with IOTSENSOR_NOT_FOUND message.
Example
iotsensor.stopScanningForDevices();