Low Energy Bluetooth (BLE)
buildfire.services.bluetooth.ble
#
This is a service that allows your widget to link to the devices bluetooth signal and paired devices. This is very useful when developing for IoT (Internet of Things)
Info
This service works only on devices
#
Requirements#
WidgetInclude ble.js
file in widget header right after the buildfire.min.js
plugin.json
#
In plugin.json add Bluetooth
in your features array "features" : [{"name" : "Bluetooth"}]
#
Methodsconnect()
#
buildfire.services.bluetooth.ble.connect(deviceId, callback)
Use this method to connect to the device
deviceId
#
The device Id you received from the paired device list
callback(err, data)
#
Callback function after device is connected or failed to connect
Name | Type | Description |
---|---|---|
err | string | error string, null when operation is successful |
data | object | Device connected |
disconnect()
#
buildfire.services.bluetooth.ble.disconnect(callback)
Use this method to disconnect the device
callback(err, data)
#
Callback function after device is disconnected or failed to disconnect
Name | Type | Description |
---|---|---|
err | string | error string, null when operation is successful |
data | object | Device disconnected |
listPairedDevices()
#
buildfire.services.bluetooth.ble.listPairedDevices(callback)
Use this method to get a list of paired bluetooth devices
callback(err, pairedDevices)
#
Callback function after getting the list of paired devices
Name | Type | Description |
---|---|---|
err | string | error string, null when operation is successful |
pairedDevices | [object] | Array of objects containing deviceId |
write()
#
buildfire.services.bluetooth.ble.write(data, callback)
Use this method to send data to the device
callback(err, pairedDevices)
#
Callback function after writing data
Name | Type | Description |
---|---|---|
err | string | error string, null when operation is successful |
data | object |
available()
#
buildfire.services.bluetooth.ble.available(callback)
Use this method to check if device is available
callback(err, isAvailable)
#
Callback function after checking device availability
Name | Type | Description |
---|---|---|
err | string | error string, null when operation is successful |
isAvailable | boolean | Indicating if device is available |
read()
#
buildfire.services.bluetooth.ble.read(callback)
Use this method to read the buffer from bluetooth
callback(err, buffer)
#
Callback function after reading data
Name | Type | Description |
---|---|---|
err | string | error string, null when operation is successful |
buffer | string | Read data |
readUntil()
#
buildfire.services.bluetooth.ble.readUntil(terminator, callback)
Use this method to read from the buffer until the terminator is found. For example if the terminator equals ,
it will continue to read until it finds the next comma.
callback(err, buffer)
#
Callback function reading is done
Name | Type | Description |
---|---|---|
err | string | error string, null when operation is successful |
buffer | string | Read buffer |
subscribe()
#
buildfire.services.bluetooth.ble.subscribe(terminator, callback)
Will automatically send you the buffer when the terminator if found.
callback(err, buffer)
#
Callback function after reading data
Name | Type | Description |
---|---|---|
err | string | error string, null when operation is successful |
buffer | string | Read data |
unsubscribe()
#
buildfire.services.bluetooth.ble.unsubscribe(terminator, callback)
Will unsubscribe from device
callback(err, buffer)
#
Callback function after device is unsubscribed
Name | Type | Description |
---|---|---|
err | string | error string, null when operation is successful |
clear()
#
buildfire.services.bluetooth.ble.clear(callback)
Use this method to clear the buffer
callback(err, buffer)
#
Callback function after device is disconnected or failed to disconnect
Name | Type | Description |
---|---|---|
err | string | error string, null when operation is successful |
isConnected()
#
buildfire.services.bluetooth.ble.isConnected(callback)
Use this method to check if the connection is still alive
callback(err, isConnected)
#
Callback function after checking connection
Name | Type | Description |
---|---|---|
err | string | error string, null when operation is successful |
isConnected | boolean | Indicates if connection is still alive |
isEnabled()
#
buildfire.services.bluetooth.ble.isEnabled(callback)
Use this method to check if bluetooth is enabled
callback(err, isEnabled)
#
Callback function after checking if bluetooth is enabled
Name | Type | Description |
---|---|---|
err | string | error string, null when operation is successful |
isEnabled | boolean | Indicates if bluetooth is enabled |
#
EventsonConnect()
#
buildfire.services.bluetooth.ble.onConnect()
Gets called when connection is established. Override this method with your handler
onDisconnect()
#
buildfire.services.bluetooth.ble.onDisconnect()
Gets called when connection is severed. Override this method with your handler