MojoScale Studio Docs
API Reference

ble

BLE native Berry module.

Studio Docs Networking

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.

API 13 available

ble.begin(name: str, mode: str = None) -> any

Initialize BLE services.

Parameters
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.
Returns

any Native initialization result.

ble.scan_start(duration_ms: int = None) -> any

Start BLE scanning.

Parameters
Name Type Pass as Required Description
duration_ms int positional or keyword No Optional scan duration in milliseconds.
Returns

any Native scan start result.

ble.scan_stop() -> any

Stop BLE scanning.

Returns

any Native scan stop result.

ble.advertise_start() -> any

Start BLE advertising.

Returns

any Native advertise start result.

ble.is_connected() -> bool

Return whether a BLE client is connected.

Returns

bool True when a client is connected.

ble.send_notification(data: any) -> any

Send a BLE notification payload.

Parameters
Name Type Pass as Required Description
data any positional or keyword Yes String or bytes payload to notify.
Returns

any Native send result.

ble.on_scan(callback: callback) -> str

Register a callback for each BLE scan result.

Parameters
Name Type Pass as Required Description
callback callback positional or keyword Yes Function name or callable accepted by firmware.
Returns

str Native registration result.

ble.on_scan_done(callback: callback) -> str

Register a callback when BLE scanning completes.

Parameters
Name Type Pass as Required Description
callback callback positional or keyword Yes Function name or callable accepted by firmware.
Returns

str Native registration result.

ble.on_ready(callback: callback) -> str

Register a callback when BLE is ready.

Parameters
Name Type Pass as Required Description
callback callback positional or keyword Yes Function name or callable accepted by firmware.
Returns

str Native registration result.

ble.on_client_connect(callback: callback) -> str

Register a callback for BLE client connection.

Parameters
Name Type Pass as Required Description
callback callback positional or keyword Yes Function name or callable accepted by firmware.
Returns

str Native registration result.

ble.on_client_disconnect(callback: callback) -> str

Register a callback for BLE client disconnection.

Parameters
Name Type Pass as Required Description
callback callback positional or keyword Yes Function name or callable accepted by firmware.
Returns

str Native registration result.

ble.on_message(callback: callback) -> str

Register a callback for inbound BLE messages.

Parameters
Name Type Pass as Required Description
callback callback positional or keyword Yes Function name or callable accepted by firmware.
Returns

str Native registration result.

ble.stop() -> any

Stop BLE activity.

Returns

any Native stop result.