A numerical identifier for the characteristic that we want notifications about.
The callback with signature (ArrayBuffer) => void
Asynchronously returns a function that takes no arguments and
removes this notification listener when called. The signature
of the function returned is () => Promise
The IOTileDevice object that we should connect to. This device should been returned from a previous call to IOTileAdapter.scan.
(optional) Configure what checks and and actions are performed automatically on connection without any required interaction. By default, the RPC interface is opened and streaming is started.
Connect to a device using the internal cordova BLE plugin
This function is a bit complicated because of the plugin's API. There are two callbacks provided to the plugin: onConnected and onDisconnected
onConnected is called with no arguments after we succesfully connect onDisconnected is called in two circumstances:
The slug of the device that we want to connect to
(optional) Configure what checks and and actions are performed automatically on connection without any required interaction. By default, the RPC interface is opened and streaming is started.
Create a channel object that can write and subscribe to characteristics over BLE. Channels are passed to the subinterfaces inside this IOTileAdapter in order to give them the ability to actually talk to the IOTile device without creating a public API for low level writes and notifications.
The BLEChannel interface is intended to be minimalist and only all the required operations.
Callback provided to ble plugin that is called whenever a device gets disconnected or if the connection attempt fails.
Internally in BLE central plugin, the possible responses are:
Open the tracing interface so that we can receive tracing data.
Whether or not BLE is enabled on the device
Ensure the Adapter is in an idle state before proceeding
The address of the tile that we want to send the RPC to
The 16 bit id of the RPC that we would like to call
A format code passed to packArrayBuffer to convert a list of numbers into an ArrayBuffer. Examples would be "LH" to pack an unsigned 32 bit integer followed by a 16 bit integer.
A format code passed to unpackArrayBuffer to convert the response Callback into a list of numbers that are returned.
An array of arguments that should match the format of callFormat and is used to construct the payload for this RPC. The first item (the error code) is shifted off and not returned.
The maximum amount of time that we would like to wait for this RPC to finish.
The decoded list of numbers that were returned from the RPC (excluding the error code).
{IOTileDevice} The currently connected device or null if no device is connected currently.
The function that should be called every time we connect to a device.
The function that should be called every time we connect to a device.
A numerical identifier for the characteristic that we want notifications about.
the ID of the callback that should be removed, which is returned from the call to addNotificationListener.
A promise that is fullfilled when the listener has been removed
Utility method to forcibly reset the streaming interface in case it has received corrupted data.
The address of the tile that we want to send the RPC to
The 16 bit id of the RPC that we would like to call
The payload that we would like to send
The maximum amount of time that we would like to wait for this RPC to finish.
The number of seconds to scan
A list of the IOTile devices seen during the scan
Wrapper around cordova ble plugin with a Promise based interface
The event that you want to subscribe to, must be an event in IOTileAdapterModule.AdapterEvent.
The function that will be called when the event happens. callback must have the signature callback(object) => void.
A function that will deregister this handler before the scope is destroyed if necessary.
The address of the tile that we want to send the RPC to
The 16 bit id of the RPC that we would like to call
A format code passed to packArrayBuffer to convert a list of numbers into an ArrayBuffer. Examples would be "LH" to pack an unsigned 32 bit integer followed by a 16 bit integer.
A format code passed to unpackArrayBuffer to convert the response Callback into a list of numbers that are returned.
An array of arguments that should match the format of callFormat and is used to construct the payload for this RPC.
The maximum amount of time that we would like to wait for this RPC to finish.
The decoded list of numbers that were returned from the RPC.
Wait for a given number of bytes to be received on the tracing interface.
If no data has been received in more than 1 second after calling this function, the promise returned will be rejected by the tracing interface watchdog timer, making sure that the interface cannot stall. The recommended way to use this function is to trigger some event that sends data via the tracing interface (after making sure the interface is open...) and then calling:
let data: ArrayBuffer = await adapter.waitForTracingData(numBytes);
That is all that is required to synchronously receive that number of bytes from the tracing interface.
The number of bytes to wait for. This exact number of bytes will be returned to you when the Promise is resolved.
The number of milliseconds to wait before receiving another chunk of tracing data before we give up and abort the wait (rejecting the promise). This defaults to 1000 ms if not passed.
Generated using TypeDoc
method
iotile.device.service:IOTileAdapter#addNotificationListener
iotile.device.service:IOTileAdapter
Listen for notifications on a specific BLE characteristic known to IOTileAdapter.
This is an async method!
If this is the first call to addNotificationListener on this characteristic, the BLE stack is called to enable notifications. However, if this is a subsequent call, it will complete immediately since nofications have already been enabled. The listener will just be added to an internal table of notification listeners for that characteristic