Bluetooth/BLE Protocol Handler (blth://)

A-Stack supports blth protocol Handler, that can be used to scan for Bluetooth, BLE devices or advertise a BLE packet.

BLTH Protocol Handler Flow:

BLTH Dependencies:

  1. Linux Operating system
  2. bluez library. 
    (sudo apt-get install bluez python-gobject python-dbus) 
    (sudo apt-get install libbluetooth-dev)

BLTH Protocol Handler Installation: Download the protocol handlers zip file from the link below

http://sandbox.atomiton.com:8080/fid-downloads/res/downloads/sff.bundle.ext.blth.jar.zip

once downloaded  copy sff.bundle.ext.blth.jar.zip to the sff.auto.launch folder which is present in your A-Stack folder and unzip it.

Run the Command bin/tql -protocol -install -bluetooth, before starting the A-Stack


BLTH Protocol Parameters:

The table below lists all the parameters of Blth protocol handler and their description

Parameter Name

Parameter Description

DeviceID


The Device entry for your Bluetooth device, the default value is hci0.

Operation


The Operation to be performed, either advertising or scanning.

ScanType


The scan type either, Bluetooth, BLE or iBeacon.

TimeInterval

The time Interval for scanning or advertising in ms.

UUID

This parameter is used in case of advertiser and is UUID to be used in the advertisement Packet

Major

This parameter is used in case of advertiser and is Major number to be used in the advertisement Packet

Minor

This parameter is used in case of advertiser and is Minor number to be used in the advertisement Packet.

AdvType

This parameter is used in case of advertiser and is Advertisement type to be used in the advertisement Packet.


Usage of Blth protocol handler:

  • Blth Scan:  the facet given below in for A-Stack Version 1.0.5 or greater.

    Blth Scan Facet
    <ThingFacet Name="BluetoothFacet">
        <String Format="$ObjectFormat(xml)" KnownBy="SerialProtocolAction" Name="BluetoothDevices" update="auto"/>
        <String Name="Operation" default="Scan"/>
        <String Name="ScanType" default="Bluetooth"/>
        <Integer Name="TimeInterval" default="5000"/>
        <Action Name="SerialProtocolAction">
            <Workflow Limit="1" Live="1" Timeout="-1">
                <Task While="true" name="Main">
                    <Event as="ActionArgument" name="Argument"/>
                    <Invoke get="blth://?Operation=[%:Event.Argument.Operation.Value:%]&amp;ScanType=[%:Event.Argument.ScanType.Value:%]&amp;
                                TimeInterval=[%:Event.Argument.TimeInterval.Value:%]&amp;" name="InvokeSerialMeta" scope="process waitFor="Argument"/>
                    <Output as="ActionResult" name="Result">
                        <Value>
                            <BluetoothDevices>
                                <Include>Invoke.InvokeSerialMeta.Message.Value
                                </Include>
                            </BluetoothDevices>
                        </Value>
                    </Output>
                </Task>
            </Workflow>
        </Action>
    </ThingFacet>    
    Bluetooth Scan Query
    <Query>
      <DeleteAll>
        <BluetoothModel>
          <blthID ne=""/>
        </BluetoothModel>
      </DeleteAll>
      <Create>
        <BluetoothModel>
          <BluetoothDevices>
            $Null()
          </BluetoothDevices>
          <Operation>
            Scan
          </Operation>
          <ScanType>
            Bluetooth
          </ScanType>
          <TimeInterval>
            2000
          </TimeInterval>
        </BluetoothModel>
      </Create>
    </Query>
    BLE Scan Query
    <Query>
      <DeleteAll>
        <BluetoothModel>
          <blthID ne=""/>
        </BluetoothModel>
      </DeleteAll>
      <Create>
        <BluetoothModel>
          <BluetoothDevices>
            $Null()
          </BluetoothDevices>
          <Operation>
            Scan
          </Operation>
          <ScanType>
            BLE
          </ScanType>
          <TimeInterval>
            2000
          </TimeInterval>
        </BluetoothModel>
      </Create>
    </Query>
    iBeacon Scan Query
    <Query>
      <DeleteAll>
        <BluetoothModel>
          <blthID ne=""/>
        </BluetoothModel>
      </DeleteAll>
      <Create>
        <BluetoothModel>
          <BluetoothDevices>
            $Null()
          </BluetoothDevices>
          <Operation>
            Scan
          </Operation>
          <ScanType>
            iBeacon
          </ScanType>
          <TimeInterval>
            2000
          </TimeInterval>
        </BluetoothModel>
      </Create>
    </Query>


BLTH Scan Output Format: The output message of blth scan is an xml structure as shown below


Bluetooth Scan Output
<BluetoothDevices Value="" Version="1">
        <Known>
          <Devices>
            <BluetoothDevices>
              <MAC>0C:60:76:93:B5:11</MAC>
              <Name>Dell Wireless 365 Bluetooth Module</Name>
              <dist>-1.0</dist>
            </BluetoothDevices>
          </Devices>
        </Known>
</BluetoothDevices>
BLE Scan Output
<BluetoothDevices Value="" Version="1">
        <Known>
          <Devices>
            <BleDevices>
              <MAC>74:9E:DC:72:C0:33</MAC>
              <Name>(unknown)</Name>
              <payload>0B02011A07FF4C0010020A</payload>
            </BleDevices>
            <BleDevices>
              <MAC>74:9E:DC:72:C0:33</MAC>
              <Name>(unknown)</Name>
              <payload>0</payload>
            </BleDevices>
            <BleDevices/>
          </Devices>
        </Known>
</BluetoothDevices>