Skip to main content

Crate bluetooth_core

Crate bluetooth_core 

Source
Expand description

C ABI for bluetooth_core.

Modules§

permission
Cross-platform Bluetooth permission status and request.

Structs§

BleCharacteristic
A GATT characteristic.
BleDevice
A discovered BLE peripheral.
BleService
A GATT service with its characteristics.
BleSession
A live BLE session. Created by bt_session_new; freed by bt_session_free.

Enums§

BleEvent
An event from the central’s event stream.
Error
Errors that can occur during BLE session operations.

Functions§

bt_connect
Connects to a peripheral by id. Returns 0 on success, -1 on error.
bt_disconnect
Disconnects from a peripheral by id. Returns 0 on success, -1 on error.
bt_discover_services
Discovers services on a peripheral and writes them as a JSON array into buf. Returns bytes written (> 0), or -1 on error.
bt_last_error
Returns the most recent error message on the calling thread (empty if none). The pointer is valid until the next bt_* call on this thread.
bt_permission_status
Returns the current Bluetooth authorization status: 0 not-determined, 1 granted, 2 denied, 3 restricted, 4 unsupported (no app-level permission on this platform; treat as granted).
bt_read
Reads a characteristic’s value into buf. Returns bytes written (>= 0), or -1 on error.
bt_request_permission
Requests Bluetooth authorization (prompting if not yet determined) and returns the resulting status, using the same codes as bt_permission_status.
bt_session_free
Frees a session created by bt_session_new, stopping its background tasks.
bt_session_new
Opens a BLE session on the first available adapter. Returns null on failure; see bt_last_error.
bt_session_poll_event
Drains the next queued BLE event as a JSON string into buf.
bt_start_scan
Starts scanning. filter_json is an optional JSON array of service-UUID strings (pass null to scan for everything). Returns 0 on success, -1 on error.
bt_stop_scan
Stops scanning. Returns 0 on success, -1 on error.
bt_subscribe
Subscribes to a characteristic; notifications arrive via bt_session_poll_event. Returns 0 or -1.
bt_unsubscribe
Unsubscribes from a characteristic. Returns 0 or -1.
bt_write
Writes len bytes from data to a characteristic. with_response selects a with-response (nonzero) vs without-response (0) write. Returns 0 or -1.