Python Bluetooth Link

The Link is a representation of the connection between two bluetooth devices. The Link's interface provides the user the ability to send commands and access Link attributes.

Send Command

Send a command to the Link.

Declaration

def sendcommand(self, msg):

Parameters

msg

The command bytes that will be sent to the link.

Discussion

Before sending the command, the link has to be authenticated. Commands can only be sent to synchronously.

Example

# Example: Send GetCapabilities command to vehicle through Bluetooth

# get the command binary for GetCapabilities
constructed_bytes = get_capabilities.GetCapabilities().get_bytearray()

if constructed_bytes is not None:
    if self.hmkit.bluetooth.broadcaster.is_connected() == False:
    print("---- PY: Device is not connected through Bluetooth. Cannot send commands ----")
    return False
    else:
    # send the constructed binary to the connected vehicle
    self.hmkit.bluetooth.link.sendcommand(constructed_bytes)

Command Incoming callback.

Declaration

def cb_command_incoming(self, cmd):

Parameters

cmd

The command bytes received from the link.

Discussion

Command Incoming Callback is used to notify the user about the incoming command.

Command Response callback.

Declaration

def cb_command_response(self, cmd):

Parameters

cmd

Bytes: Response/Ack for the command send

Discussion

Response for the command sent