diff --git a/lib-doc/cordova-ble_ble.js.html b/lib-doc/cordova-ble_ble.js.html new file mode 100644 index 0000000..e2f134c --- /dev/null +++ b/lib-doc/cordova-ble_ble.js.html @@ -0,0 +1,757 @@ + + + + + + + Source: cordova-ble/ble.js + + + + + + + + +
+
+
+ +
+ +
+
// API definition for EvoThings BLE plugin.
+//
+// Use jsdoc to generate documentation.
+
+// The following line causes a jsdoc error.
+// Use the jsdoc option -l to ignore the error.
+var exec = cordova.require('cordova/exec');
+
+/**
+ * @module cordova-plugin-ble
+ * @description Functions and properties in this module are available
+ * under the global name <code>evothings.ble</code>
+ */
+
+/** Starts scanning for devices.
+* <p>Found devices and errors will be reported to the supplied callbacks.</p>
+* <p>Will keep scanning indefinitely until you call stopScan().</p>
+* To conserve energy, call stopScan() as soon as you've found the device you're looking for.
+* <p>Calling this function while scanning is in progress has no effect?</p>
+*
+* @param {scanCallback} win
+* @param {failCallback} fail
+*
+* @example
+evothings.ble.startScan(
+	function(device)
+	{
+		console.log('BLE startScan found device named: ' + device.name);
+	},
+	function(errorCode)
+	{
+		console.log('BLE startScan error: ' + errorCode);
+	}
+);
+*/
+exports.startScan = function(win, fail) {
+	exec(win, fail, 'BLE', 'startScan', []);
+};
+
+/** This function is a parameter to startScan() and is called when a new device is discovered.
+* @callback scanCallback
+* @param {DeviceInfo} device
+*/
+
+/** Info about a BLE device.
+* @typedef {Object} DeviceInfo
+//* @property {string} address - Has the form xx:xx:xx:xx:xx:xx, where x are hexadecimal characters.
+* @property {string} address - Uniquely identifies the device. Pass this to connect().
+* The form of the address depends on the host platform.
+* @property {number} rssi - A negative integer, the signal strength in decibels.
+* @property {string} name - The device's name, or nil.
+* @property {string} scanRecord - Base64-encoded binary data. Its meaning is device-specific. Not available on iOS.
+* @property {AdvertisementData} advertisementData - Object containing some of the data from the scanRecord. Available natively on iOS. Available on Android by parsing the scanRecord, which is implemented in the library {@link https://github.com/evothings/evothings-examples/tree/master/resources/libs/evothings/easyble|easyble.js}.
+*/
+
+/** Information extracted from a scanRecord. Some or all of the fields may be undefined. This varies between BLE devices.
+ * Depending on OS version and BLE device, additional fields, not documented here, may be present.
+ * @typedef {Object} AdvertisementData
+ * @property {string} kCBAdvDataLocalName - The device's name. Equal to DeviceInfo.name.
+ * @property {number} kCBAdvDataTxPowerLevel - Transmission power level as advertised by the device.
+ * @property {number} kCBAdvDataChannel - A positive integer, the BLE channel on which the device listens for connections. Ignore this number.
+ * @property {boolean} kCBAdvDataIsConnectable - True if the device accepts connections. False if it doesn't.
+ * @property {array} kCBAdvDataServiceUUIDs - Array of strings, the UUIDs of services advertised by the device. Formatted according to RFC 4122, all lowercase.
+ * @property {object} kCBAdvDataServiceData - Dictionary of strings to strings. The keys are service UUIDs. The values are base-64-encoded binary data.
+ * @property {string} kCBAdvDataManufacturerData - Base-64-encoded binary data. This field is used by BLE devices to advertise custom data that don't fit into any of the other fields.
+ */
+
+/** This function is called when an operation fails.
+* @callback failCallback
+* @param {string} errorString - A human-readable string that describes the error that occurred.
+*/
+
+/** Stops scanning for devices.
+*
+* @example
+evothings.ble.stopScan();
+*/
+exports.stopScan = function() {
+	exec(null, null, 'BLE', 'stopScan', []);
+};
+
+/** Connect to a remote device.
+* @param {string} address - From scanCallback.
+* @param {connectCallback} win
+* @param {failCallback} fail
+* @example
+evothings.ble.connect(
+	address,
+	function(info)
+	{
+		console.log('BLE connect status for device: '
+			+ info.deviceHandle
+			+ ' state: '
+			+ info.state);
+	},
+	function(errorCode)
+	{
+		console.log('BLE connect error: ' + errorCode);
+	}
+);
+*/
+exports.connect = function(address, win, fail) {
+	exec(win, fail, 'BLE', 'connect', [address]);
+};
+
+/** Will be called whenever the device's connection state changes.
+* @callback connectCallback
+* @param {ConnectInfo} info
+*/
+
+/** Info about connection events and state.
+* @typedef {Object} ConnectInfo
+* @property {number} deviceHandle - Handle to the device. Save it for other function calls.
+* @property {number} state - One of the {@link module:cordova-plugin-ble.connectionState} keys.
+*/
+
+/** A map describing possible connection states.
+* @alias module:cordova-plugin-ble.connectionState
+* @readonly
+* @enum
+*/
+exports.connectionState = {
+	/** STATE_DISCONNECTED */
+	0: 'STATE_DISCONNECTED',
+	/** STATE_CONNECTING */
+	1: 'STATE_CONNECTING',
+	/** STATE_CONNECTED */
+	2: 'STATE_CONNECTED',
+	/** STATE_DISCONNECTING */
+	3: 'STATE_DISCONNECTING',
+
+	// TODO: Add these in the next release of the BLE plugin.
+	// /** 0 */
+	// 'STATE_DISCONNECTED': 0,
+	// /** 1 */
+	// 'STATE_CONNECTING': 1,
+	// /** 2 */
+	// 'STATE_CONNECTED': 2,
+	// /** 3 */
+	// 'STATE_DISCONNECTING': 3,
+};
+
+/** Close the connection to a remote device.
+* <p>Frees any native resources associated with the device.
+* <p>Does not cause any callbacks to the function passed to connect().
+
+* @param {number} deviceHandle - A handle from {@link connectCallback}.
+* @example
+evothings.ble.close(deviceHandle);
+*/
+exports.close = function(deviceHandle) {
+	exec(null, null, 'BLE', 'close', [deviceHandle]);
+};
+
+/** Fetch the remote device's RSSI (signal strength).
+* @param {number} deviceHandle - A handle from {@link connectCallback}.
+* @param {rssiCallback} win
+* @param {failCallback} fail
+* @example
+evothings.ble.rssi(
+	deviceHandle,
+	function(rssi)
+	{
+		console.log('BLE rssi: ' + rssi);
+	},
+	function(errorCode)
+	{
+		console.log('BLE rssi error: ' + errorCode);
+	}
+);
+*/
+exports.rssi = function(deviceHandle, win, fail) {
+	exec(win, fail, 'BLE', 'rssi', [deviceHandle]);
+};
+
+/** This function is called with an RSSI value.
+* @callback rssiCallback
+* @param {number} rssi - A negative integer, the signal strength in decibels.
+*/
+
+/** Fetch information about a remote device's services.
+* @param {number} deviceHandle - A handle from {@link connectCallback}.
+* @param {serviceCallback} win - Called with array of {@link Service} objects.
+* @param {failCallback} fail
+* @example
+evothings.ble.services(
+	deviceHandle,
+	function(services)
+	{
+		for (var i = 0; i < services.length; i++)
+		{
+			var service = services[i];
+			console.log('BLE service: ');
+			console.log('  ' + service.handle);
+			console.log('  ' + service.uuid);
+			console.log('  ' + service.serviceType);
+		}
+	},
+	function(errorCode)
+	{
+		console.log('BLE services error: ' + errorCode);
+	});
+*/
+exports.services = function(deviceHandle, win, fail) {
+	exec(win, fail, 'BLE', 'services', [deviceHandle]);
+};
+
+/**
+* @callback serviceCallback
+* @param {Array} services - Array of {@link Service} objects.
+*/
+
+/** Describes a GATT service.
+* @typedef {Object} Service
+* @property {number} handle
+* @property {string} uuid - Formatted according to RFC 4122, all lowercase.
+* @property {module:cordova-plugin-ble.serviceType} type
+*/
+
+/** A map describing possible service types.
+* @readonly
+* @alias module:cordova-plugin-ble.serviceType
+* @enum
+*/
+exports.serviceType = {
+	/** SERVICE_TYPE_PRIMARY */
+	0: 'SERVICE_TYPE_PRIMARY',
+	/** SERVICE_TYPE_SECONDARY */
+	1: 'SERVICE_TYPE_SECONDARY',
+
+	// TODO: Add these in the next release of the BLE plugin.
+	// /** 0 */
+	// 'SERVICE_TYPE_PRIMARY': 0,
+	// /** 1 */
+	// 'SERVICE_TYPE_SECONDARY': 1,
+};
+
+/** Fetch information about a service's characteristics.
+* @param {number} deviceHandle - A handle from {@link connectCallback}.
+* @param {number} serviceHandle - A handle from {@link serviceCallback}.
+* @param {characteristicCallback} win - Called with array of {@link Characteristic} objects.
+* @param {failCallback} fail
+* @example
+evothings.ble.characteristics(
+	deviceHandle,
+	service.handle,
+	function(characteristics)
+	{
+		for (var i = 0; i < characteristics.length; i++)
+		{
+			var characteristic = characteristics[i];
+			console.log('BLE characteristic: ' + characteristic.uuid);
+		}
+	},
+	function(errorCode)
+	{
+		console.log('BLE characteristics error: ' + errorCode);
+	});
+*/
+exports.characteristics = function(deviceHandle, serviceHandle, win, fail) {
+	exec(win, fail, 'BLE', 'characteristics', [deviceHandle, serviceHandle]);
+};
+
+/**
+* @callback characteristicCallback
+* @param {Array} characteristics - Array of {@link Characteristic} objects.
+*/
+
+/** Describes a GATT characteristic.
+* @typedef {Object} Characteristic
+* @property {number} handle
+* @property {string} uuid - Formatted according to RFC 4122, all lowercase.
+* @property {module:cordova-plugin-ble.permission} permissions - Bitmask of zero or more permission flags.
+* @property {module:cordova-plugin-ble.property} properties - Bitmask of zero or more property flags.
+* @property {module:cordova-plugin-ble.writeType} writeType
+*/
+
+/** A map describing possible permission flags.
+* @alias module:cordova-plugin-ble.permission
+* @readonly
+* @enum
+*/
+exports.permission = {
+	/** PERMISSION_READ */
+	1: 'PERMISSION_READ',
+	/** PERMISSION_READ_ENCRYPTED */
+	2: 'PERMISSION_READ_ENCRYPTED',
+	/** PERMISSION_READ_ENCRYPTED_MITM */
+	4: 'PERMISSION_READ_ENCRYPTED_MITM',
+	/** PERMISSION_WRITE */
+	16: 'PERMISSION_WRITE',
+	/** PERMISSION_WRITE_ENCRYPTED */
+	32: 'PERMISSION_WRITE_ENCRYPTED',
+	/** PERMISSION_WRITE_ENCRYPTED_MITM */
+	64: 'PERMISSION_WRITE_ENCRYPTED_MITM',
+	/** PERMISSION_WRITE_SIGNED */
+	128: 'PERMISSION_WRITE_SIGNED',
+	/** PERMISSION_WRITE_SIGNED_MITM */
+	256: 'PERMISSION_WRITE_SIGNED_MITM',
+
+	// TODO: Add these in the next release of the BLE plugin.
+	// /** 1 */
+	// 'PERMISSION_READ': 1,
+	// /** 2 */
+	// 'PERMISSION_READ_ENCRYPTED': 2,
+	// /** 4 */
+	// 'PERMISSION_READ_ENCRYPTED_MITM': 4,
+	// /** 16 */
+	// 'PERMISSION_WRITE': 16,
+	// /** 32 */
+	// 'PERMISSION_WRITE_ENCRYPTED': 32,
+	// /** 64 */
+	// 'PERMISSION_WRITE_ENCRYPTED_MITM': 64,
+	// /** 128 */
+	// 'PERMISSION_WRITE_SIGNED': 128,
+	// /** 256 */
+	// 'PERMISSION_WRITE_SIGNED_MITM': 256,
+};
+
+/** A map describing possible property flags.
+* @alias module:cordova-plugin-ble.property
+* @readonly
+* @enum
+*/
+exports.property = {
+	/** PROPERTY_BROADCAST */
+	1: 'PROPERTY_BROADCAST',
+	/** PROPERTY_READ */
+	2: 'PROPERTY_READ',
+	/** PROPERTY_WRITE_NO_RESPONSE */
+	4: 'PROPERTY_WRITE_NO_RESPONSE',
+	/** PROPERTY_WRITE */
+	8: 'PROPERTY_WRITE',
+	/** PROPERTY_NOTIFY */
+	16: 'PROPERTY_NOTIFY',
+	/** PROPERTY_INDICATE */
+	32: 'PROPERTY_INDICATE',
+	/** PROPERTY_SIGNED_WRITE */
+	64: 'PROPERTY_SIGNED_WRITE',
+	/** PROPERTY_EXTENDED_PROPS */
+	128: 'PROPERTY_EXTENDED_PROPS',
+
+	// TODO: Add these in the next release of the BLE plugin.
+	// /** 1 */
+	// 'PROPERTY_BROADCAST': 1,
+	// /** 2 */
+	// 'PROPERTY_READ': 2,
+	// /** 4 */
+	// 'PROPERTY_WRITE_NO_RESPONSE': 4,
+	// /** 8 */
+	// 'PROPERTY_WRITE': 8,
+	// /** 16 */
+	// 'PROPERTY_NOTIFY': 16,
+	// /** 32 */
+	// 'PROPERTY_INDICATE': 32,
+	// /** 64 */
+	// 'PROPERTY_SIGNED_WRITE': 4,
+	// /** 128 */
+	// 'PROPERTY_EXTENDED_PROPS': 128,
+};
+
+/** A map describing possible write types.
+* @alias module:cordova-plugin-ble.writeType
+* @readonly
+* @enum
+*/
+exports.writeType = {
+	/** WRITE_TYPE_NO_RESPONSE */
+	1: 'WRITE_TYPE_NO_RESPONSE',
+	/** WRITE_TYPE_DEFAULT */
+	2: 'WRITE_TYPE_DEFAULT',
+	/** WRITE_TYPE_SIGNED */
+	4: 'WRITE_TYPE_SIGNED',
+
+	// TODO: Add these in the next release of the BLE plugin.
+	// /** 1 */
+	// 'WRITE_TYPE_NO_RESPONSE': 1,
+	// /** 2 */
+	// 'WRITE_TYPE_DEFAULT': 2,
+	// /** 4 */
+	// 'WRITE_TYPE_SIGNED': 4,
+};
+
+/** Fetch information about a characteristic's descriptors.
+* @param {number} deviceHandle - A handle from {@link connectCallback}.
+* @param {number} characteristicHandle - A handle from {@link characteristicCallback}.
+* @param {descriptorCallback} win - Called with array of {@link Descriptor} objects.
+* @param {failCallback} fail
+* @example
+evothings.ble.descriptors(
+	deviceHandle,
+	characteristic.handle,
+	function(descriptors)
+	{
+		for (var i = 0; i < descriptors.length; i++)
+		{
+			var descriptor = descriptors[i];
+			console.log('BLE descriptor: ' + descriptor.uuid);
+		}
+	},
+	function(errorCode)
+	{
+		console.log('BLE descriptors error: ' + errorCode);
+	});
+*/
+exports.descriptors = function(deviceHandle, characteristicHandle, win, fail) {
+	exec(win, fail, 'BLE', 'descriptors', [deviceHandle, characteristicHandle]);
+};
+
+/**
+* @callback descriptorCallback
+* @param {Array} descriptors - Array of {@link Descriptor} objects.
+*/
+
+/** Describes a GATT descriptor.
+* @typedef {Object} Descriptor
+* @property {number} handle
+* @property {string} uuid - Formatted according to RFC 4122, all lowercase.
+* @property {module:cordova-plugin-ble.permission} permissions - Bitmask of zero or more permission flags.
+*/
+
+// TODO: What is read* ?
+// read*: fetch and return value in one op.
+// values should be cached on the JS side, if at all.
+
+/**
+* @callback dataCallback
+* @param {ArrayBuffer} data
+*/
+
+/** Reads a characteristic's value from a remote device.
+* @param {number} deviceHandle - A handle from {@link connectCallback}.
+* @param {number} characteristicHandle - A handle from {@link characteristicCallback}.
+* @param {dataCallback} win
+* @param {failCallback} fail
+* @example
+evothings.ble.readCharacteristic(
+	deviceHandle,
+	characteristic.handle,
+	function(data)
+	{
+		console.log('BLE characteristic data: ' + evothings.ble.fromUtf8(data));
+	},
+	function(errorCode)
+	{
+		console.log('BLE readCharacteristic error: ' + errorCode);
+	});
+*/
+exports.readCharacteristic = function(deviceHandle, characteristicHandle, win, fail) {
+	exec(win, fail, 'BLE', 'readCharacteristic', [deviceHandle, characteristicHandle]);
+};
+
+/** Reads a descriptor's value from a remote device.
+* @param {number} deviceHandle - A handle from {@link connectCallback}.
+* @param {number} descriptorHandle - A handle from {@link descriptorCallback}.
+* @param {dataCallback} win
+* @param {failCallback} fail
+* @example
+evothings.ble.readDescriptor(
+	deviceHandle,
+	descriptor.handle,
+	function(data)
+	{
+		console.log('BLE descriptor data: ' + evothings.ble.fromUtf8(data));
+	},
+	function(errorCode)
+	{
+		console.log('BLE readDescriptor error: ' + errorCode);
+	});
+*/
+exports.readDescriptor = function(deviceHandle, descriptorHandle, win, fail) {
+	exec(win, fail, 'BLE', 'readDescriptor', [deviceHandle, descriptorHandle]);
+};
+
+/**
+* @callback emptyCallback - Callback that takes no parameters.
+This callback indicates that an operation was successful,
+without specifying and additional information.
+*/
+
+/** Write a characteristic's value to the remote device.
+* @param {number} deviceHandle - A handle from {@link connectCallback}.
+* @param {number} characteristicHandle - A handle from {@link characteristicCallback}.
+* @param {ArrayBufferView} data - The value to be written.
+* @param {emptyCallback} win
+* @param {failCallback} fail
+* @example TODO: Add example.
+*/
+exports.writeCharacteristic = function(deviceHandle, characteristicHandle, data, win, fail) {
+	exec(win, fail, 'BLE', 'writeCharacteristic', [deviceHandle, characteristicHandle, data.buffer]);
+};
+
+/** Write a descriptor's value to a remote device.
+* @param {number} deviceHandle - A handle from {@link connectCallback}.
+* @param {number} descriptorHandle - A handle from {@link descriptorCallback}.
+* @param {ArrayBufferView} data - The value to be written.
+* @param {emptyCallback} win
+* @param {failCallback} fail
+* @example TODO: Add example.
+*/
+exports.writeDescriptor = function(deviceHandle, descriptorHandle, data, win, fail) {
+	exec(win, fail, 'BLE', 'writeDescriptor', [deviceHandle, descriptorHandle, data.buffer]);
+};
+
+/** Request notification on changes to a characteristic's value.
+* This is more efficient than polling the value using readCharacteristic().
+*
+* <p>To activate notifications,
+* some (all?) devices require you to write a special value to a separate configuration characteristic,
+* in addition to calling this function.
+* Refer to your device's documentation.
+*
+* @param {number} deviceHandle - A handle from {@link connectCallback}.
+* @param {number} characteristicHandle - A handle from {@link characteristicCallback}.
+* @param {dataCallback} win - Called every time the value changes.
+* @param {failCallback} fail
+* @example
+evothings.ble.enableNotification(
+	deviceHandle,
+	characteristic.handle,
+	function(data)
+	{
+		console.log('BLE characteristic data: ' + evothings.ble.fromUtf8(data));
+	},
+	function(errorCode)
+	{
+		console.log('BLE enableNotification error: ' + errorCode);
+	});
+*/
+exports.enableNotification = function(deviceHandle, characteristicHandle, win, fail) {
+	exec(win, fail, 'BLE', 'enableNotification', [deviceHandle, characteristicHandle]);
+};
+
+/** Disable notification of changes to a characteristic's value.
+* @param {number} deviceHandle - A handle from {@link connectCallback}.
+* @param {number} characteristicHandle - A handle from {@link characteristicCallback}.
+* @param {emptyCallback} win
+* @param {failCallback} fail
+* @example
+evothings.ble.disableNotification(
+	deviceHandle,
+	characteristic.handle,
+	function()
+	{
+		console.log('BLE characteristic notification disabled');
+	},
+	function(errorCode)
+	{
+		console.log('BLE disableNotification error: ' + errorCode);
+	});
+*/
+exports.disableNotification = function(deviceHandle, characteristicHandle, win, fail) {
+	exec(win, fail, 'BLE', 'disableNotification', [deviceHandle, characteristicHandle]);
+};
+
+/** i is an integer. It is converted to byte and put in an array[1].
+* The array is returned.
+* <p>assert(string.charCodeAt(0) == i).
+*
+* @param {number} i
+* @param {dataCallback} win - Called every time the value changes.
+*/
+exports.testCharConversion = function(i, win) {
+	exec(win, null, 'BLE', 'testCharConversion', [i]);
+};
+
+/** Resets the device's Bluetooth system.
+* This is useful on some buggy devices where BLE functions stops responding until reset.
+* Available on Android 4.3+. This function takes 3-5 seconds to reset BLE.
+* On iOS this function stops any ongoing scan operation and disconnects
+* all connected devices.
+*
+* @param {emptyCallback} win
+* @param {failCallback} fail
+*/
+exports.reset = function(win, fail) {
+	exec(win, fail, 'BLE', 'reset', []);
+};
+
+/** Converts an ArrayBuffer containing UTF-8 data to a JavaScript String.
+* @param {ArrayBuffer} a
+* @returns string
+*/
+exports.fromUtf8 = function(a) {
+	return decodeURIComponent(escape(String.fromCharCode.apply(null, new Uint8Array(a))));
+};
+
+/** Converts a JavaScript String to an Uint8Array containing UTF-8 data.
+* @param {string} s
+* @returns Uint8Array
+*/
+exports.toUtf8 = function(s) {
+	var strUtf8 = unescape(encodeURIComponent(s));
+	var ab = new Uint8Array(strUtf8.length);
+	for (var i = 0; i < strUtf8.length; i++) {
+		ab[i] = strUtf8.charCodeAt(i);
+	}
+	return ab;
+};
+
+
+/** Fetch information about a remote device's services,
+* as well as its associated characteristics and descriptors.
+*
+* This function is an easy-to-use wrapper of the low-level functions
+* ble.services(), ble.characteristics() and ble.descriptors().
+*
+* @param {number} deviceHandle - A handle from {@link connectCallback}.
+* @param {serviceCallback} win - Called with array of {@link Service} objects.
+* Those Service objects each have an additional field "characteristics", which is an array of {@link Characteristic} objects.
+* Those Characteristic objects each have an additional field "descriptors", which is an array of {@link Descriptor} objects.
+* @param {failCallback} fail
+*/
+exports.readAllServiceData = function(deviceHandle, win, fail)
+{
+	// Array of populated services.
+	var serviceArray = [];
+
+	// Counter that tracks the number of info items read.
+	// This value is incremented and decremented when reading.
+	// When value is back to zero, all items are read.
+	var readCounter = 0;
+
+	var servicesCallbackFun = function()
+	{
+		return function(services)
+		{
+			readCounter += services.length;
+			for (var i = 0; i < services.length; ++i)
+			{
+				var service = services[i];
+				serviceArray.push(service);
+				service.characteristics = [];
+
+				// Read characteristics for service.
+        exports.characteristics(
+					deviceHandle,
+					service.handle,
+					characteristicsCallbackFun(service),
+					function(errorCode)
+					{
+						console.log('characteristics error: ' + errorCode);
+						fail(errorCode);
+					});
+			}
+		};
+	};
+
+	var characteristicsCallbackFun = function(service)
+	{
+		return function(characteristics)
+		{
+			--readCounter;
+			readCounter += characteristics.length;
+			for (var i = 0; i < characteristics.length; ++i)
+			{
+				var characteristic = characteristics[i];
+				service.characteristics.push(characteristic);
+				characteristic.descriptors = [];
+
+				// Read descriptors for characteristic.
+        exports.descriptors(
+					deviceHandle,
+					characteristic.handle,
+					descriptorsCallbackFun(characteristic),
+					function(errorCode)
+					{
+						console.log('descriptors error: ' + errorCode);
+						fail(errorCode);
+					});
+			}
+		};
+	};
+
+	var descriptorsCallbackFun = function(characteristic)
+	{
+		return function(descriptors)
+		{
+			--readCounter;
+			for (var i = 0; i < descriptors.length; ++i)
+			{
+				var descriptor = descriptors[i];
+				characteristic.descriptors.push(descriptor);
+			}
+			if (0 == readCounter)
+			{
+				// Everything is read.
+				win(serviceArray);
+			}
+		};
+	};
+
+	// Read services for device.
+	exports.services(
+		deviceHandle,
+		servicesCallbackFun(),
+		function(errorCode)
+		{
+			console.log('services error: ' + errorCode);
+			fail(errorCode);
+		});
+};
+
+
+
+
+ +
+
+ + + + + + + + + + + \ No newline at end of file diff --git a/lib-doc/arduinoble_arduinoble.js.html b/lib-doc/evothings-libraries_libs_evothings_arduinoble_arduinoble.js.html similarity index 96% rename from lib-doc/arduinoble_arduinoble.js.html rename to lib-doc/evothings-libraries_libs_evothings_arduinoble_arduinoble.js.html index 8d50971..856d3e5 100644 --- a/lib-doc/arduinoble_arduinoble.js.html +++ b/lib-doc/evothings-libraries_libs_evothings_arduinoble_arduinoble.js.html @@ -4,7 +4,7 @@ - Source: arduinoble/arduinoble.js + Source: evothings-libraries/libs/evothings/arduinoble/arduinoble.js @@ -26,7 +26,7 @@
// File: arduinoble.js
@@ -193,7 +193,7 @@ 

Source: arduinoble/arduinoble.js

diff --git a/lib-doc/arduinotcp_arduinotcp.js.html b/lib-doc/evothings-libraries_libs_evothings_arduinotcp_arduinotcp.js.html similarity index 98% rename from lib-doc/arduinotcp_arduinotcp.js.html rename to lib-doc/evothings-libraries_libs_evothings_arduinotcp_arduinotcp.js.html index 8628cbd..9592fab 100644 --- a/lib-doc/arduinotcp_arduinotcp.js.html +++ b/lib-doc/evothings-libraries_libs_evothings_arduinotcp_arduinotcp.js.html @@ -4,7 +4,7 @@ - Source: arduinotcp/arduinotcp.js + Source: evothings-libraries/libs/evothings/arduinotcp/arduinotcp.js @@ -26,7 +26,7 @@
// File: arduinotcp.js
@@ -462,7 +462,7 @@ 

Source: arduinotcp/arduinotcp.js

diff --git a/lib-doc/easyble_easyble.js.html b/lib-doc/evothings-libraries_libs_evothings_easyble_easyble.js.html similarity index 94% rename from lib-doc/easyble_easyble.js.html rename to lib-doc/evothings-libraries_libs_evothings_easyble_easyble.js.html index 5f26373..6082a34 100644 --- a/lib-doc/easyble_easyble.js.html +++ b/lib-doc/evothings-libraries_libs_evothings_easyble_easyble.js.html @@ -4,7 +4,7 @@ - Source: easyble/easyble.js + Source: evothings-libraries/libs/evothings/easyble/easyble.js @@ -26,7 +26,7 @@
// File: easyble.js
@@ -443,13 +443,14 @@ 

Source: easyble/easyble.js

var advertisementData = device.advertisementData; if (advertisementData) { - if (advertisementData.kCBAdvDataServiceUUIDs) + var serviceUUIDs = advertisementData.kCBAdvDataServiceUUIDs; + if (serviceUUIDs) { - for (var i in advertisementData) + for (var i in serviceUUIDs) { for (var j in serviceFilter) { - if (advertisementData[i].toLowerCase() == + if (serviceUUIDs[i].toLowerCase() == serviceFilter[j].toLowerCase()) { return true; @@ -469,16 +470,44 @@

Source: easyble/easyble.js

internal.addMethodsToDeviceObject = function(deviceObject) { /** - * This is the BLE DeviceInfo object obtained by calling - * evothings.ble.startScan, with additional properties and - * functions added. Internal properties are prefixed with two - * underscores. Properties are also added to the Characteristic - * and Descriptor objects. * @namespace * @alias evothings.easyble.EasyBLEDevice + * @description This is the BLE DeviceInfo object obtained from the + * underlying Cordova plugin. + * @property {string} address - Uniquely identifies the device. + * The form of the address depends on the host platform. + * @property {number} rssi - A negative integer, the signal strength in decibels. + * @property {string} name - The device's name, or nil. + * @property {string} scanRecord - Base64-encoded binary data. Its meaning is + * device-specific. Not available on iOS. + * @property {evothings.easyble.AdvertisementData} advertisementData - + * Object containing some of the data from the scanRecord. */ var device = deviceObject; + /** + * @typedef {Object} evothings.easyble.AdvertisementData + * @description Information extracted from a scanRecord. Some or all of the fields may be + * undefined. This varies between BLE devices. + * Depending on OS version and BLE device, additional fields, not documented + * here, may be present. + * @property {string} kCBAdvDataLocalName - The device's name. Use this field + * rather than device.name, since on iOS the device name is cached and changes + * are not reflected in device.name. + * @property {number} kCBAdvDataTxPowerLevel - Transmission power level as + * advertised by the device. + * @property {boolean} kCBAdvDataIsConnectable - True if the device accepts + * connections. False if it doesn't. + * @property {array} kCBAdvDataServiceUUIDs - Array of strings, the UUIDs of + * services advertised by the device. Formatted according to RFC 4122, + * all lowercase. + * @property {object} kCBAdvDataServiceData - Dictionary of strings to strings. + * The keys are service UUIDs. The values are base-64-encoded binary data. + * @property {string} kCBAdvDataManufacturerData - Base-64-encoded binary data. + * This field is used by BLE devices to advertise custom data that don't fit + * into any of the other fields. + */ + /** * Match device name. * @param name The name to match. @@ -1190,15 +1219,8 @@

Source: easyble/easyble.js

evothings.ble.readDescriptor( device.deviceHandle, descriptor.handle, - value, - function() - { - success(); - }, - function(errorCode) - { - fail(errorCode); - }); + success, + fail); }; /** @@ -1457,7 +1479,7 @@

Source: easyble/easyble.js

diff --git a/lib-doc/eddystone_eddystone.js.html b/lib-doc/evothings-libraries_libs_evothings_eddystone_eddystone.js.html similarity index 79% rename from lib-doc/eddystone_eddystone.js.html rename to lib-doc/evothings-libraries_libs_evothings_eddystone_eddystone.js.html index 98ba901..1359540 100644 --- a/lib-doc/eddystone_eddystone.js.html +++ b/lib-doc/evothings-libraries_libs_evothings_eddystone_eddystone.js.html @@ -4,7 +4,7 @@ - Source: eddystone/eddystone.js + Source: evothings-libraries/libs/evothings/eddystone/eddystone.js @@ -26,7 +26,7 @@
// File: eddystone.js
@@ -62,9 +62,9 @@ 

Source: eddystone/eddystone.js

* @description Starts scanning for Eddystone devices. * <p>Found devices and errors will be reported to the supplied callbacks.</p> * <p>Will keep scanning indefinitely until you call stopScan().</p> - * To conserve energy, call stopScan() as soon as you've found the device - * you're looking for. - * <p>Calling this function while scanning is in progress will fail.</p> + * <p>To conserve energy, call stopScan() as soon as you've found the device + * you're looking for.</p> + * <p>Calling startScan() while scanning is in progress will produce an error.</p> * * @param {evothings.eddystone.scanCallback} - Success function called * when a beacon is found. @@ -148,7 +148,6 @@

Source: eddystone/eddystone.js

* Which properties are available depends on which packets types broadcasted * by the beacon. Properties may be undefined. Typically properties are populated * as scanning processes. - * @alias evothings.eddystone.EddystoneDevice * @typedef {Object} evothings.eddystone.EddystoneDevice * @property {string} url - An Internet URL. * @property {number} txPower - A signed integer, the signal strength in decibels, @@ -176,6 +175,56 @@

Source: eddystone/eddystone.js

isScanning = false; } +/** + * @description Calculate the accuracy (distance in meters) of the beacon. + * <p>The beacon distance calculation uses txPower at 1 meters, but the + * Eddystone protocol reports the value at 0 meters. 41dBm is the signal + * loss that occurs over 1 meter, this value is subtracted by default + * from the reported txPower. You can tune the calculation by adding + * or subtracting to param txPower.<p> + * <p>Note that the returned distance value is not accurate, and that + * it fluctuates over time. Sampling/filtering over time is recommended + * to obtain a stable value.<p> + * @public + * @param txPower The txPower of the beacon. + * @param rssi The RSSI of the beacon, subtract or add to this value to + * tune the dBm strength. 41dBm is subtracted from this value in the + * distance algorithm used by calculateAccuracy. + * @return Distance in meters, or null if unable to compute distance + * (occurs for example when txPower or rssi is undefined). + * @example + * // Note that beacon.txPower and beacon.rssi many be undefined, + * // in which case calculateAccuracy returns null. This happens + * // before txPower and rssi have been reported by the beacon. + * var distance = evothings.eddystone.calculateAccuracy( + * beacon.txPower, beacon.rssi); + */ +evothings.eddystone.calculateAccuracy = function(txPower, rssi) +{ + if (!rssi || rssi >= 0 || !txPower) + { + return null + } + + // Algorithm + // http://developer.radiusnetworks.com/2014/12/04/fundamentals-of-beacon-ranging.html + // http://stackoverflow.com/questions/21338031/radius-networks-ibeacon-ranging-fluctuation + + // The beacon distance formula uses txPower at 1 meters, but the Eddystone + // protocol reports the value at 0 meters. 41dBm is the signal loss that + // occurs over 1 meter, so we subtract that from the reported txPower. + var ratio = rssi * 1.0 / (txPower - 41) + if (ratio < 1.0) + { + return Math.pow(ratio, 10) + } + else + { + var accuracy = (0.89976) * Math.pow(ratio, 7.7095) + 0.111 + return accuracy + } +} + // Return true on frame type recognition, false otherwise. function parseFrameUID(device, data, win, fail) { @@ -318,7 +367,7 @@

Source: eddystone/eddystone.js

diff --git a/lib-doc/evothings.js.html b/lib-doc/evothings-libraries_libs_evothings_evothings.js.html similarity index 97% rename from lib-doc/evothings.js.html rename to lib-doc/evothings-libraries_libs_evothings_evothings.js.html index 00c4863..07eadb6 100644 --- a/lib-doc/evothings.js.html +++ b/lib-doc/evothings-libraries_libs_evothings_evothings.js.html @@ -4,7 +4,7 @@ - Source: evothings.js + Source: evothings-libraries/libs/evothings/evothings.js @@ -26,7 +26,7 @@
// File: evothings.js
@@ -290,7 +290,7 @@ 

Source: evothings.js

diff --git a/lib-doc/nordic-nRF51-ble_nordic-nRF51-ble.js.html b/lib-doc/evothings-libraries_libs_evothings_nordic-nRF51-ble_nordic-nRF51-ble.js.html similarity index 95% rename from lib-doc/nordic-nRF51-ble_nordic-nRF51-ble.js.html rename to lib-doc/evothings-libraries_libs_evothings_nordic-nRF51-ble_nordic-nRF51-ble.js.html index 4859b67..06abf3b 100644 --- a/lib-doc/nordic-nRF51-ble_nordic-nRF51-ble.js.html +++ b/lib-doc/evothings-libraries_libs_evothings_nordic-nRF51-ble_nordic-nRF51-ble.js.html @@ -4,7 +4,7 @@ - Source: nordic-nRF51-ble/nordic-nRF51-ble.js + Source: evothings-libraries/libs/evothings/nordic-nRF51-ble/nordic-nRF51-ble.js @@ -26,7 +26,7 @@
// File: nordic-nRF51-ble.js
@@ -171,7 +171,7 @@ 

Source: nordic-nRF51-ble/nordic-nRF51-ble.js

diff --git a/lib-doc/nordic-nRF51822-ble_nordic-nRF51822-ble.js.html b/lib-doc/evothings-libraries_libs_evothings_nordic-nRF51822-ble_nordic-nRF51822-ble.js.html similarity index 96% rename from lib-doc/nordic-nRF51822-ble_nordic-nRF51822-ble.js.html rename to lib-doc/evothings-libraries_libs_evothings_nordic-nRF51822-ble_nordic-nRF51822-ble.js.html index 017edfa..85c5140 100644 --- a/lib-doc/nordic-nRF51822-ble_nordic-nRF51822-ble.js.html +++ b/lib-doc/evothings-libraries_libs_evothings_nordic-nRF51822-ble_nordic-nRF51822-ble.js.html @@ -4,7 +4,7 @@ - Source: nordic-nRF51822-ble/nordic-nRF51822-ble.js + Source: evothings-libraries/libs/evothings/nordic-nRF51822-ble/nordic-nRF51822-ble.js @@ -26,7 +26,7 @@
// File: nordic-ble.js
@@ -219,7 +219,7 @@ 

Source: nordic-nRF51822-ble/nordic-nRF51822-ble.js

diff --git a/lib-doc/rfduinoble_rfduinoble.js.html b/lib-doc/evothings-libraries_libs_evothings_rfduinoble_rfduinoble.js.html similarity index 95% rename from lib-doc/rfduinoble_rfduinoble.js.html rename to lib-doc/evothings-libraries_libs_evothings_rfduinoble_rfduinoble.js.html index 02ff0b6..42aa4d4 100644 --- a/lib-doc/rfduinoble_rfduinoble.js.html +++ b/lib-doc/evothings-libraries_libs_evothings_rfduinoble_rfduinoble.js.html @@ -4,7 +4,7 @@ - Source: rfduinoble/rfduinoble.js + Source: evothings-libraries/libs/evothings/rfduinoble/rfduinoble.js @@ -26,7 +26,7 @@
// File: rfduinoble.js
@@ -174,7 +174,7 @@ 

Source: rfduinoble/rfduinoble.js

diff --git a/lib-doc/tisensortag_tisensortag-ble-cc2541.js.html b/lib-doc/evothings-libraries_libs_evothings_tisensortag_tisensortag-ble-cc2541.js.html similarity index 98% rename from lib-doc/tisensortag_tisensortag-ble-cc2541.js.html rename to lib-doc/evothings-libraries_libs_evothings_tisensortag_tisensortag-ble-cc2541.js.html index 00340bf..0bf9ed1 100644 --- a/lib-doc/tisensortag_tisensortag-ble-cc2541.js.html +++ b/lib-doc/evothings-libraries_libs_evothings_tisensortag_tisensortag-ble-cc2541.js.html @@ -4,7 +4,7 @@ - Source: tisensortag/tisensortag-ble-cc2541.js + Source: evothings-libraries/libs/evothings/tisensortag/tisensortag-ble-cc2541.js @@ -26,7 +26,7 @@
// Documentation for TI SensorTag CC2541:
@@ -525,7 +525,7 @@ 

Source: tisensortag/tisensortag-ble-cc2541.js

diff --git a/lib-doc/tisensortag_tisensortag-ble-cc2650.js.html b/lib-doc/evothings-libraries_libs_evothings_tisensortag_tisensortag-ble-cc2650.js.html similarity index 98% rename from lib-doc/tisensortag_tisensortag-ble-cc2650.js.html rename to lib-doc/evothings-libraries_libs_evothings_tisensortag_tisensortag-ble-cc2650.js.html index 16d2671..149da7e 100644 --- a/lib-doc/tisensortag_tisensortag-ble-cc2650.js.html +++ b/lib-doc/evothings-libraries_libs_evothings_tisensortag_tisensortag-ble-cc2650.js.html @@ -4,7 +4,7 @@ - Source: tisensortag/tisensortag-ble-cc2650.js + Source: evothings-libraries/libs/evothings/tisensortag/tisensortag-ble-cc2650.js @@ -26,7 +26,7 @@

@@ -561,7 +561,7 @@ 

Source: tisensortag/tisensortag-ble-cc2650.js

diff --git a/lib-doc/tisensortag_tisensortag-ble.js.html b/lib-doc/evothings-libraries_libs_evothings_tisensortag_tisensortag-ble.js.html similarity index 99% rename from lib-doc/tisensortag_tisensortag-ble.js.html rename to lib-doc/evothings-libraries_libs_evothings_tisensortag_tisensortag-ble.js.html index 13bb9d4..a497487 100644 --- a/lib-doc/tisensortag_tisensortag-ble.js.html +++ b/lib-doc/evothings-libraries_libs_evothings_tisensortag_tisensortag-ble.js.html @@ -4,7 +4,7 @@ - Source: tisensortag/tisensortag-ble.js + Source: evothings-libraries/libs/evothings/tisensortag/tisensortag-ble.js @@ -26,7 +26,7 @@
// Shared functions for BLE TI SensorTags.
@@ -923,7 +923,7 @@ 

Source: tisensortag/tisensortag-ble.js

diff --git a/lib-doc/tisensortag_tisensortag.js.html b/lib-doc/evothings-libraries_libs_evothings_tisensortag_tisensortag.js.html similarity index 98% rename from lib-doc/tisensortag_tisensortag.js.html rename to lib-doc/evothings-libraries_libs_evothings_tisensortag_tisensortag.js.html index 14666fd..72a4fad 100644 --- a/lib-doc/tisensortag_tisensortag.js.html +++ b/lib-doc/evothings-libraries_libs_evothings_tisensortag_tisensortag.js.html @@ -4,7 +4,7 @@ - Source: tisensortag/tisensortag.js + Source: evothings-libraries/libs/evothings/tisensortag/tisensortag.js @@ -26,7 +26,7 @@
// File: tisensortag.js
@@ -574,7 +574,7 @@ 

Source: tisensortag/tisensortag.js

diff --git a/lib-doc/util_util.js.html b/lib-doc/evothings-libraries_libs_evothings_util_util.js.html similarity index 97% rename from lib-doc/util_util.js.html rename to lib-doc/evothings-libraries_libs_evothings_util_util.js.html index 5d46e4d..234452e 100644 --- a/lib-doc/util_util.js.html +++ b/lib-doc/evothings-libraries_libs_evothings_util_util.js.html @@ -4,7 +4,7 @@ - Source: util/util.js + Source: evothings-libraries/libs/evothings/util/util.js @@ -26,7 +26,7 @@
// File: util.js
@@ -258,7 +258,7 @@ 

Source: util/util.js

diff --git a/lib-doc/evothings.arduinoble.ArduinoBLEDevice.html b/lib-doc/evothings.arduinoble.ArduinoBLEDevice.html index 72262dd..81351ce 100644 --- a/lib-doc/evothings.arduinoble.ArduinoBLEDevice.html +++ b/lib-doc/evothings.arduinoble.ArduinoBLEDevice.html @@ -26,7 +26,7 @@