-
Notifications
You must be signed in to change notification settings - Fork 0
bt_classic
This module presents a collection of functionalities specifically designed to manage and regulate the behaviour of Classic Bluetooth between Android and Windows devices.
Unlike Bluetooth Low Energy, Classic Bluetooth, often referred to as just Bluetooth, is intended for more data-intensive applications, making it suitable for activities that require higher data rates such as streaming audio or transferring files. This module is, therefore, particularly useful when dealing with these more demanding Bluetooth operations in an Android|Windows environment.
This module offers a collection of functions designed to address specific tasks and provide utilities for various purposes. Explore the available functions to make the most of the functionalities provided by this module.
- bt_classic_is_supported
- bt_classic_scan_start
- bt_classic_scan_is_active
- bt_classic_scan_stop
- bt_classic_discoverability_enable
- bt_classic_discoverability_is_active
- bt_classic_server_start
- bt_classic_server_stop
- bt_classic_socket_receive
- bt_classic_socket_send
- bt_classic_socket_open
- bt_classic_socket_close
- bt_classic_socket_close_all
This function returns true
if the device has the necessary Bluetooth features, false
otherwise.
Syntax:
bt_classic_is_supported()
Returns:
This function starts the remote device discovery process.
This function operates asynchronously, which means that it does not immediately return the requested result. Instead, upon completion of the task, it will trigger the Social Async Event.
Syntax:
bt_classic_scan_start()
Returns:
Triggers:
Key | Type | Description |
---|---|---|
type | String | The value "bt_classic_scan_start"
|
async_id | Real | The unique identifier of this async task. |
success | Boolean | The value true if the scan operation started successfully. |
error_code | Real | The error code if the operation didn't succeed. |
Key | Type | Description |
---|---|---|
type | String | The value "bt_classic_scan_result"
|
success | Boolean | The value true if the scan operation started successfully. |
name | Real | The identifying name of the scanned device. |
address | Real | The unique address of the scanned device. |
connected | Real | Whether or not the device is currently connected. |
authenticated | Real | Whether or not the device is currently authenticated (paired). |
remembered | Real | Whether or not the device is currently remembered (paired). |
This function returns true
if the local Bluetooth adapter is currently in the device scanning process.
Syntax:
bt_classic_scan_is_active()
Returns:
This function cancels the current device discovery process.
This function operates asynchronously, which means that it does not immediately return the requested result. Instead, upon completion of the task, it will trigger the Social Async Event.
Syntax:
bt_classic_scan_stop()
Returns:
Triggers:
Key | Type | Description |
---|---|---|
type | String | The value "bt_classic_scan_stop"
|
async_id | Real | The unique identifier of this async task. |
success | Boolean | The value true if the scan operation started successfully. |
error_code | Real | The error code (if the operation didn't succeed). |
This function requests the OS to enable the visibility of the device for a given amount of time.
Syntax:
bt_classic_discoverability_enable(seconds)
Argument | Type | Description |
---|---|---|
seconds | Real | The number of seconds to enable discoverability for. |
Returns:
N/A
This function checks if the device is correctly discoverable to others.
Syntax:
bt_classic_discoverability_is_active()
Returns:
This function creates a listening, secure|insecure RFCOMM Bluetooth socket with Service Record.
This function operates asynchronously, which means that it does not immediately return the requested result. Instead, upon completion of the task, it will trigger the Social Async Event.
Syntax:
bt_classic_server_start(name, uuid, insecure)
Argument | Type | Description |
---|---|---|
name | String | The service name for the SDP record |
uuid | String | The UUID for the SDP record |
insecure | String | Whether the socket should be insecure (this option needs to match the one in connecting devices) |
Returns:
Triggers:
Key | Type | Description |
---|---|---|
type | String | The value "bt_classic_server_start"
|
async_id | Real | The unique identifier of this async task. |
success | Boolean |
true if the operation completed successfully, false otherwise |
This event is triggered when a new connection is accepted.
Key | Type | Description |
---|---|---|
type | String | The value "bt_classic_server_accept"
|
success | Boolean |
true if the operation completed successfully, false otherwise |
socket_id | Real | The unique identifier of the connected socket (used for sending and receiving data). |
This function immediately closes this socket, and releases all associated resources.
This function operates asynchronously, which means that it does not immediately return the requested result. Instead, upon completion of the task, it will trigger the Social Async Event.
Syntax:
bt_classic_server_stop()
Returns:
Triggers:
Key | Type | Description |
---|---|---|
type | String | The value "bt_classic_server_stop"
|
async_id | Real | The unique identifier of this async task. |
success | Boolean |
true if the operation completed successfully, false otherwise |
This function reads incoming data sent by a given open socket.
Syntax:
bt_classic_socket_receive(socketId, bufferId, offset)
Argument | Type | Description |
---|---|---|
socketId | Real | The unique identifier of the socket you want to read the data from. |
bufferId | Buffer | The buffer where the incoming data will be written. Data is written in chuncks, make sure that your buffer is at least the size of a chunck. No resizing will occur. |
offset | Real | The byte offset to be used when writting to the buffer. |
Returns:
N/A
This function sends data to a given remotely connected device.
Syntax:
bt_classic_socket_send(socketId, bufferId, offset, length)
Argument | Type | Description |
---|---|---|
socketId | Real | The unique identifier of the socket you want to send data to. |
bufferId | Buffer | The buffer where the outgoing data is stored. |
offset | Real | The byte offset to be used when reading from the buffer. |
length | Real | The length of the buffer data to be sent. |
Returns:
N/A
This function creates an RFCOMM BluetoothSocket socket ready to start an insecure outgoing connection to this remote device using SDP lookup of the UUID.
This function operates asynchronously, which means that it does not immediately return the requested result. Instead, upon completion of the task, it will trigger the Social Async Event.
Syntax:
bt_classic_socket_open(address, uuid, insecure)
Argument | Type | Description |
---|---|---|
address | String | The address of the device to attempt to connect to. |
uuid | String | The service record UUID to lookup RFCOMM channel. |
insecure | Boolean | Whether the Bluetooth connection should be insecure (this option needs to match the one in the server). |
Returns:
N/A
Triggers:
Key | Type | Description |
---|---|---|
type | String | The value "bt_classic_socket_open"
|
success | Boolean |
true if the connection completed successfully, false otherwise. |
address | String | The address of the device. |
uuid | String | The service record UUID connected to. |
socket_id | String | (if success it's true ) The index of the created socket. |
error_message | String | (if success it's false ) The error message. |
This function allows the user to close a previously opened connection to a Bluetooth server.
Syntax:
bt_classic_socket_close(socketId)
Argument | Type | Description |
---|---|---|
socketId | Real | The socket ID acquired upon successfully opening a connection (using bt_classic_socket_open). |
Returns:
N/A
This function allows the user to close ALL previously opened connections to Bluetooth servers.
Syntax:
bt_classic_socket_close_all()
Returns:
N/A
YoYoGames 2023