Skip to main content
Version: v1.0

hmBle

The "Device App" communicates with the "Side Service" through the hmBle module using the device's Bluetooth communication capabilities.

tip

For a complete example of Bluetooth communication, please refer to Bluetooth Communication

Method

createConnect(callback)

Create connection

Type

(callback: (index: number, data: object, size: number) => void) => void

Parameters

Callback parameterDescriptionRequiredType
indexsubpackage numberNOnumber
datareceived dataNOobject
sizelength of data receivedNOnumber

disConnect()

Disconnects

Type

() => void

send(data, size)

Send a message

Type

(data: object, size: number) => void

Parameters

ParametersDescriptionRequiredType
datadata to be sentNOobject
sizelength of data to be sentNOnumber

connectStatus()

Query connection status

Type

() => Result

Result

DescriptionType
connection status true connected, false not connectedboolean

addListener(callback)

Register a connection status listener

type

(callback: (status: boolean) => void) => void

Parameters

Callback parameterDescriptionType
statusconnection statusboolean

removeListener

Cancel the connection status listener

type

() => void

Code example

// Create Connection
hmBle.createConnect(function (index, data, size) {
// Receive message callback, return the received message as it is
hmBle.send(data, size)
})

// Disconnection
hmBle.disConnect()

// Print Bluetooth connection status
console.log(hmBle.connectStatus())

// Register to listen for connection status
hmBle.addListener(function (status) {
// Print connection status
console.log(status)
})