Skip to content
Jack Lund edited this page Nov 28, 2013 · 4 revisions

btle

startAdvertising(options, callback)

Start advertising.

Parameters

  • options - ???
  • callback - parameters:
    • err - an error, or null if successful

stopAdvertising(callback)

Stop advertising.

Parameters

  • callback - parameters:
    • err - an error, or null if completed successfully

startScanning(options, callback)

Scan for advertising from another device. Once you start scanning, if you receive an advertisement, an advertisement event will be raised.

Parameters

  • options - ???
  • callback - parameters:
    • err - an error, or null if successful

Events

  • advertisement - raised if an advertisement is received. Callback parameters:
    • err - an error, or null if successful
    • advertisement - advertisement data

sendAdvertisingRequest(destination, request, callback)

Send a request using the advertising channel

Parameters

  • destination - the destination address for the request
  • request - an object containing the request data
  • callback - parameters:
    • err - an error, or null if successful
    • response - the response to the request, or null if there was an error

respondToAdvertisingRequest(destination, response, callback)

Respond to a request from the advertising channel

Parameters

  • destination - the destination address for the request
  • response - an object containing the response data
  • callback - parameters:
    • err - an error, or null if successful

stopScanning(callback)

Stop scanning for advertising from another device

Parameters

  • callback - parameters:
    • err - an error, or null if successful

createConnection(options, callback)

Initiate a connection to another device.

Parameters

  • options - connect options. May include:
    • ???
    • ???
  • callback - parameters:
    • err - error, or null if successful
    • conn - connection object (if successful)

Events

  • connect - emitted when connected, if no callback provided to createConnection. Parameters:
    • err - error, or null if successful
    • conn - connection object (if successful)

listen(options, callback)

Listen for connection requests.

Parameters

  • options - listen options. May include:
    • ???
    • ???
  • callback - parameters:
    • err - error, or null if successful
    • conn - connection object

Connection Object

Events

read

Emitted when data is read from the connection. Callback parameters:

  • err - read error, or null if read successful
  • buffer - a buffer containing the incoming data

error

Emitted when there is an error on the connection. Callback parameters:

  • err - the error. Should never be null.

close

Emitted when the connection is closed. Parameters:

  • err - the error, if the close is due to an error, otherwise null.

write(buffer, callback)

Write to the connection.

Parameters

  • buffer - the buffer containing the data to write
  • callback - the callback called when the write completes. Parameters:
    • err - the error, or null if successful

close([callback])

Close the connection.

Parameters

  • callback (optional) - Callback called when the connection is closed. If left off, the close event is emitted instead. Parameters:
    • err - the error, if there is one, otherwise null

createAtt()

Create and return an ATT protocol object using this connection

createGatt()

Create and return a GATT protocol object using this connection

ATT

Returned by conn.createAtt(), exposes the ATT-level API for use.

findInformation(startHandle, endHandle, callback)

Returns attribute information for the handles between startHandle and endHandle, inclusive.

Parameters

  • startHandle - beginning handle to return information for
  • endHandle - ending handle to return information for
  • callback - callback. Parameters:
    • err - the error, or null if successful
    • attrList - array of attribute objects describing the attributes between the requested handles

findByTypeValue(startHandle, endHandle, type, value, callback)

Return information about the attributes between startHandle and endHandle, inclusive, with the given type and value.

Parameters

  • startHandle - beginning handle to return information for
  • endHandle - ending handle to return information for
  • type - UUID for the attribute type
  • value - value for the attribute - either a String or Buffer
  • callback - callback. Parameters:
    • err - the error, or null if successful
    • attrList - array of attribute objects describing the attributes between the requested handles