Skip to content

Low Energy Bluetooth Service

o5faruk edited this page May 2, 2021 · 4 revisions

⚠️⚠️⚠️

This sdk documentation is deprecated and will not be updated. Check out our new docs at https://sdk.buildfire.com/docs/low-energy-bluetooth/

⚠️⚠️⚠️

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)

Note: this will not work on the control side of your plugin

buildfire.services.bluetooth.ble (bluetooth low energy)

Used on the Widget side communicate with paired bluetooth devices

Requirements

  • From the Widget
<script src="../../../scripts/buildfire/services/bluetooth/ble.js"></script>
  • in plugin.json add bluetooth in your feature array "features" : [{"name" : "Bluetooth"}]

Example

https://github.com/BuildFire/bluetoothExamplePlugin

Constructor

none. ble is a singleton

Methods

  • 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 called when connected or failed to connect.
  • disconnect function (callback) : used to disconnect from the previously connected device
    • callback (err,data): callback function called when the disconnect occurs or fails.
  • listPairedDevices function(callback): Get a list of paired bluetooth devices
    • callback(err,devices): a callback function the is called an array of devices.
      • devices: an array of devices with two properties
        • deviceId: string
        • name: string
  • write function (data, callback): Used to send string data to the device
  • available function (callback): check if device is available
  • read function (callback):reads the buffer from the bluetooth
  • readUntil function (terminator,callback): reads 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
  • subscribe function (delimiter,callback): will automatically send you the buffer when the terminator if found
  • unsubscribe function (callback): stop subscribing
  • clear function (callback) clears the buffer
  • isConnected function (callback) : checks to see if the connection is still alive
  • isEnabled function (callback):checks if bluetooth is enabled

Handlers

  • onConnect function(): gets called when connection is established
  • onDisconnect function(): get called when the connection is severed
Clone this wiki locally