Skip to main content

A small BLE GATT transport for framed JSON and binary messages between Python desktops and Android devices.

Project description

BLE Message Bridge

BLE Message Bridge is a small transport layer for sending framed JSON and binary payloads over Bluetooth Low Energy GATT.

It is useful when you want a desktop Python app to talk to an Android device over BLE without rewriting the same plumbing every time:

  • split large payloads into BLE-sized packets;
  • reassemble packets on the other side;
  • gzip larger JSON/text payloads;
  • send compact binary ping/pong heartbeats;
  • reconnect with jittered backoff;
  • use one write characteristic and one notify characteristic for duplex messages.

This library started as the reusable BLE transport extracted from a desktop-to-Android app. The public package is intentionally app-agnostic: it does not know about chat, AI models, prompts, screenshots, or any product-specific message schema.

Install

pip install ble-message-bridge

Quick Start

import asyncio

from ble_message_bridge import BleBridgeClient


def on_event(event: dict) -> None:
    print(event)


async def main() -> None:
    async with BleBridgeClient(event_sink=on_event) as client:
        devices = await client.scan()
        if not devices:
            raise SystemExit("No bridge devices found")

        await client.connect(devices[0].address)
        await client.send_json({"type": "hello", "text": "ciao"})
        await asyncio.sleep(3)


asyncio.run(main())

Custom UUIDs

The defaults are stable UUIDs from the reference Android bridge. For your own app, create your own service and characteristic UUIDs:

from ble_message_bridge import BleBridgeClient, BleBridgeConfig

config = BleBridgeConfig(
    service_uuid="00000000-0000-0000-0000-000000000001",
    write_char_uuid="00000000-0000-0000-0000-000000000002",
    notify_char_uuid="00000000-0000-0000-0000-000000000003",
)

client = BleBridgeClient(config=config)

Events

BleBridgeClient reports everything through an optional event sink:

def on_event(event: dict) -> None:
    match event["type"]:
        case "json":
            print("message", event["message"])
        case "payload":
            print("bytes", event["payload"])
        case "link_quality":
            print("rtt", event.get("rtt_ms"))

Common event types:

  • scan_result
  • connected
  • disconnected
  • sent
  • transfer_progress
  • json
  • payload
  • bundle
  • link_quality
  • link_status
  • error

Android

This repo includes reference Kotlin sources in android/ for an Android BLE peripheral/server that speaks the same framing protocol.

The Android side is not published to Maven yet. For now, copy the small reference classes into your app module, or use them as the basis for your own BLE service.

See docs/android.md.

Protocol

The packet format is intentionally small:

[version:1][transport_id:2][chunk_index:2][chunk_total:2][payload:n]

All integers are big-endian. Payloads larger than one BLE write/notification are split into multiple frames with the same transport_id.

See docs/protocol.md.

Status

0.1.x is alpha. The framing format is simple and tested, but the public API may still evolve while real projects try it.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ble_message_bridge-0.1.1.tar.gz (18.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ble_message_bridge-0.1.1-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file ble_message_bridge-0.1.1.tar.gz.

File metadata

  • Download URL: ble_message_bridge-0.1.1.tar.gz
  • Upload date:
  • Size: 18.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ble_message_bridge-0.1.1.tar.gz
Algorithm Hash digest
SHA256 66d84c44061264a7f48599becd32b91295d25724ca4b3ef3bfd2dc5997aaeb43
MD5 f8c43a15b053af13b800610a3302070b
BLAKE2b-256 d166a4a5d34a11e2e49f68a0fd6ca0a30a9537b30ceb951a370ab72a42fcd351

See more details on using hashes here.

Provenance

The following attestation bundles were made for ble_message_bridge-0.1.1.tar.gz:

Publisher: publish.yml on MN-company/ble-message-bridge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ble_message_bridge-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for ble_message_bridge-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9d5415188f13910a8890f8f9c213eec254e975d0c90ce7ca5dced39c9a8d3967
MD5 c7bcf7d3e7bfe29e4501532244defd0f
BLAKE2b-256 799975ecdf4b2f0e51d94464a5b49e7c3109f3ab5341036f64a50c619c0fd456

See more details on using hashes here.

Provenance

The following attestation bundles were made for ble_message_bridge-0.1.1-py3-none-any.whl:

Publisher: publish.yml on MN-company/ble-message-bridge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page