import ble
The ble module controls Bluetooth Low Energy behavior exposed by firmware. Use it for scanning, advertising, client connection callbacks, and notifications.
Quick example
import ble
ble.begin("mojo-sensor")
ble.on_client_connect("handle_client")
ble.send_notification("ready")
importble
BLE native Berry module.
The ble module controls Bluetooth Low Energy behavior exposed by firmware. Use it for scanning, advertising, client connection callbacks, and notifications.
ble.begin(name: str, mode: str = None) -> any
ble.begin(name: str, mode: str = None) -> anyInitialize BLE services.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
name |
str |
positional or keyword | Yes | Device name used for advertising. |
mode |
str |
positional or keyword | No | Optional native BLE mode. |
any Native initialization result.
ble.scan_start(duration_ms: int = None) -> any
ble.scan_start(duration_ms: int = None) -> anyStart BLE scanning.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
duration_ms |
int |
positional or keyword | No | Optional scan duration in milliseconds. |
any Native scan start result.
ble.scan_stop() -> any
ble.scan_stop() -> anyStop BLE scanning.
any Native scan stop result.
ble.advertise_start() -> any
ble.advertise_start() -> anyStart BLE advertising.
any Native advertise start result.
ble.is_connected() -> bool
ble.is_connected() -> boolReturn whether a BLE client is connected.
bool True when a client is connected.
ble.send_notification(data: any) -> any
ble.send_notification(data: any) -> anySend a BLE notification payload.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
data |
any |
positional or keyword | Yes | String or bytes payload to notify. |
any Native send result.
ble.on_scan(callback: callback) -> str
ble.on_scan(callback: callback) -> strRegister a callback for each BLE scan result.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
callback |
callback |
positional or keyword | Yes | Function name or callable accepted by firmware. |
str Native registration result.
ble.on_scan_done(callback: callback) -> str
ble.on_scan_done(callback: callback) -> strRegister a callback when BLE scanning completes.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
callback |
callback |
positional or keyword | Yes | Function name or callable accepted by firmware. |
str Native registration result.
ble.on_ready(callback: callback) -> str
ble.on_ready(callback: callback) -> strRegister a callback when BLE is ready.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
callback |
callback |
positional or keyword | Yes | Function name or callable accepted by firmware. |
str Native registration result.
ble.on_client_connect(callback: callback) -> str
ble.on_client_connect(callback: callback) -> strRegister a callback for BLE client connection.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
callback |
callback |
positional or keyword | Yes | Function name or callable accepted by firmware. |
str Native registration result.
ble.on_client_disconnect(callback: callback) -> str
ble.on_client_disconnect(callback: callback) -> strRegister a callback for BLE client disconnection.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
callback |
callback |
positional or keyword | Yes | Function name or callable accepted by firmware. |
str Native registration result.
ble.on_message(callback: callback) -> str
ble.on_message(callback: callback) -> strRegister a callback for inbound BLE messages.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
callback |
callback |
positional or keyword | Yes | Function name or callable accepted by firmware. |
str Native registration result.
ble.stop() -> any
ble.stop() -> anyStop BLE activity.
any Native stop result.