py-ble-manager


Namepy-ble-manager JSON
Version 1.0.0 PyPI version JSON
download
home_page
SummaryA python library for controlling Renesas BLE devices
upload_time2023-08-07 20:42:46
maintainer
docs_urlNone
author
requires_python>=3.10.5
licenseThe MIT License (MIT) Copyright (c) 2023 Renesas Electronics Corporation and/or its affiliates Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords ble bluetooth
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # py_ble_manager

A python library for controlling Renesas BLE devices.

## Purpose

The intent of this library is to provide a python interface similar to [SDK10](http://lpccs-docs.renesas.com/um-b-092-da1469x_software_platform_reference/User_guides/User_guides.html#the-ble-framework) for controlling BLE of DA14xxx devices. This is achieved by communicating with a development kit running Generic Transport Layer (GTL) supported firmware over a USB port on your PC:

![](https://lpccs-docs.renesas.com/py_ble_manager/_images/usb_to_pc.png)

The primary intent is for use as a central device for benchtop testing, continuous integration, or as an end-of-line tool. For additional information on the GTL please see the [GTL User Manual](https://www.renesas.com/us/en/document/mat/um-b-143-renesas-external-processor-interface-gtl-interface?language=en&r=1564826).

## Quick Start

1. Refer to the [hardware setup](https://github.com/dialog-semiconductor/py_ble_manager/blob/main/docs/source/hardware_setup.rst) to setup the jumpers on your development kit.

2. Call: `pip install py-ble-manager[dev]` to install the `py_ble_manager` package and its dependencies.

    > **_NOTE:_**
      Specifying [dev] will install optional dependency: [prompt_toolkit](https://pypi.org/project/prompt-toolkit/).
      `prompt_toolkit` is used in some of the examples to provide a command line interface.

    > **_NOTE:_**
      This library requires Python v3.10.5 or later.

    > **_NOTE:_**
       It is recommended to install the library using a virtual environment. To setup a virtual environment using [venv](https://docs.python.org/3/library/venv.html) call: `$ python -m venv ./<name_of_your_env>`. Note to create a virtual environment that uses Python 3.10.5, you must already have Python 3.10.5 downloaded on your computer. To use the above command to create a Python 3.10.5 environment, Python 3.10.5 must be configured in your PATH. You can download it from the [python website](https://www.python.org/downloads/release/python-3105/).

3. [Download](https://github.com/dialog-semiconductor/py_ble_manager/tree/main/src/py_ble_manager/util) the py_ble_manager compatible firmware binary to the development kit by calling the `py_ble_manager_programmer`
utility from the terminal.

4. The package is now installed and you are ready to run one of the [examples](https://github.com/dialog-semiconductor/py_ble_manager/tree/main/examples)!

## Basic Usage

### Create a BLE Central object and perform initialization

```Python
import py_ble_manager as ble

central = ble.BleCentral("COM54")

# Initialize the Python BLE Framework
central.init()

# Start operating as a BLE Central 
central.start()

# Set the IO capabilities
central.set_io_cap(ble.GAP_IO_CAPABILITIES.GAP_IO_CAP_KEYBOARD_DISP)
```

### Initiate a BLE Operation

Some examples include:

Scanning:

```Python
central.scan_start(type=ble.GAP_SCAN_TYPE.GAP_SCAN_ACTIVE,
                   mode=ble.GAP_SCAN_MODE.GAP_SCAN_GEN_DISC_MODE,
                   interval_ms=100,
                   window_ms=50,
                   filt_wlist=False,
                   filt_dupl=True)
```

Connecting:

```Python
peripheral_addr: ble.BdAddress = ble.BleUtils.str_to_bd_addr("48:23:35:00:1b:53,P") 
connection_params = ble.GapConnParams(interval_min_ms=50, interval_max_ms=70, slave_latency=0, sup_timeout_ms=420)
central.connect(peripheral_addr, connection_params)
```

Read a characteristic value

```Python
central.read(conn_idx=0, handle=24, offset=0) 
```

Write a characteristic value

```Python
central.write(conn_idx=0, handle=24, offset=0, value=1234) 
```

Disconnect

```Python
central.disconnect(conn_idx=0) 
```

### Handle asynchronous events

The framework returns asynchronous events to the application through an event queue. Calling `BleCentral.get_event()` will get an event from the queue. All of the events returned by `BleCentral.get_event()` are a subclass of `BleEventBase`.
A variety of different events occur throughout the life a BLE application. Some example events include `BleEventGapConnectionCompleted`, `BleEventGapDisconnected`, `BleEventGattcReadCompleted`, `BleEventGattcWriteCompleted`.
Each event has an `evt_code` to identify the type of event.  

For example, after you initiate a write you will receive a `BleEventGattcWriteCompleted` event which has an `evt_code` of `BLE_EVT_GATTC.BLE_EVT_GATTC_WRITE_COMPLETED`. Your application can
handle the event however it sees fit. If your application does not handle the event, call `BleCentral.handle_event_default()` to have the BLE framework process the event for you.

```Python
# This call will block until an event is available. Use the timeout parameter to block for a specified period of time
evt = central.get_event()
    
    # Determine which event occurred. It will be of type BLE_EVT_GAP, BLE_EVT_GATTC, or BLE_EVT_GATTS
    match evt.evt_code:

        # Handle the event
        case ble.BLE_EVT_GAP.BLE_EVT_GAP_ADV_REPORT:
            # Define your own handling function to process the event
            handle_evt_gap_adv_report(evt)
        case ble.BLE_EVT_GAP.BLE_EVT_GAP_SCAN_COMPLETED:
            handle_evt_gap_scan_completed(evt)
        case ble.BLE_EVT_GAP.BLE_EVT_GAP_CONNECTED:
            handle_evt_gap_connected(evt)
        case ble.BLE_EVT_GAP.BLE_EVT_GAP_CONNECTION_COMPLETED:
            handle_evt_gap_connection_completed(evt)
        case ble.BLE_EVT_GAP.BLE_EVT_GAP_DISCONNECTED:
            handle_evt_gap_disconnected(evt)
        case ble.BLE_EVT_GATTC.BLE_EVT_GATTC_BROWSE_SVC:
            handle_evt_gattc_browse_svc(evt)
        case ble.BLE_EVT_GATTC.BLE_EVT_GATTC_BROWSE_COMPLETED:
            handle_evt_gattc_browse_completed(evt)
        case ble.BLE_EVT_GATTC.BLE_EVT_GATTC_NOTIFICATION:
            handle_evt_gattc_notification(evt)
        case ble.BLE_EVT_GATTC.BLE_EVT_GATTC_WRITE_COMPLETED:
            handle_evt_gattc_write_completed(evt)
        case ble.BLE_EVT_GATTC.BLE_EVT_GATTC_READ_COMPLETED:
            handle_evt_gattc_read_completed(evt)

        case _:
            # For any events not handled by your application, call the BleCentral default handler to process the event
            central.handle_event_default(evt)
```

## Architecture

Refer to the [architecture](https://github.com/dialog-semiconductor/py_ble_manager/blob/main/docs/architecture.md) description.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "py-ble-manager",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10.5",
    "maintainer_email": "",
    "keywords": "ble,bluetooth",
    "author": "",
    "author_email": "Patrick Murphy <patrick.murphy.jy@renesas.com>",
    "download_url": "https://files.pythonhosted.org/packages/90/34/9272caca879464fdf0e5c09d0db3fd6b4733bd8b7d46dbdc54b6d3b467a9/py_ble_manager-1.0.0.tar.gz",
    "platform": null,
    "description": "# py_ble_manager\n\nA python library for controlling Renesas BLE devices.\n\n## Purpose\n\nThe intent of this library is to provide a python interface similar to [SDK10](http://lpccs-docs.renesas.com/um-b-092-da1469x_software_platform_reference/User_guides/User_guides.html#the-ble-framework) for controlling BLE of DA14xxx devices. This is achieved by communicating with a development kit running Generic Transport Layer (GTL) supported firmware over a USB port on your PC:\n\n![](https://lpccs-docs.renesas.com/py_ble_manager/_images/usb_to_pc.png)\n\nThe primary intent is for use as a central device for benchtop testing, continuous integration, or as an end-of-line tool. For additional information on the GTL please see the [GTL User Manual](https://www.renesas.com/us/en/document/mat/um-b-143-renesas-external-processor-interface-gtl-interface?language=en&r=1564826).\n\n## Quick Start\n\n1. Refer to the [hardware setup](https://github.com/dialog-semiconductor/py_ble_manager/blob/main/docs/source/hardware_setup.rst) to setup the jumpers on your development kit.\n\n2. Call: `pip install py-ble-manager[dev]` to install the `py_ble_manager` package and its dependencies.\n\n    > **_NOTE:_**\n      Specifying [dev] will install optional dependency: [prompt_toolkit](https://pypi.org/project/prompt-toolkit/).\n      `prompt_toolkit` is used in some of the examples to provide a command line interface.\n\n    > **_NOTE:_**\n      This library requires Python v3.10.5 or later.\n\n    > **_NOTE:_**\n       It is recommended to install the library using a virtual environment. To setup a virtual environment using [venv](https://docs.python.org/3/library/venv.html) call: `$ python -m venv ./<name_of_your_env>`. Note to create a virtual environment that uses Python 3.10.5, you must already have Python 3.10.5 downloaded on your computer. To use the above command to create a Python 3.10.5 environment, Python 3.10.5 must be configured in your PATH. You can download it from the [python website](https://www.python.org/downloads/release/python-3105/).\n\n3. [Download](https://github.com/dialog-semiconductor/py_ble_manager/tree/main/src/py_ble_manager/util) the py_ble_manager compatible firmware binary to the development kit by calling the `py_ble_manager_programmer`\nutility from the terminal.\n\n4. The package is now installed and you are ready to run one of the [examples](https://github.com/dialog-semiconductor/py_ble_manager/tree/main/examples)!\n\n## Basic Usage\n\n### Create a BLE Central object and perform initialization\n\n```Python\nimport py_ble_manager as ble\n\ncentral = ble.BleCentral(\"COM54\")\n\n# Initialize the Python BLE Framework\ncentral.init()\n\n# Start operating as a BLE Central \ncentral.start()\n\n# Set the IO capabilities\ncentral.set_io_cap(ble.GAP_IO_CAPABILITIES.GAP_IO_CAP_KEYBOARD_DISP)\n```\n\n### Initiate a BLE Operation\n\nSome examples include:\n\nScanning:\n\n```Python\ncentral.scan_start(type=ble.GAP_SCAN_TYPE.GAP_SCAN_ACTIVE,\n                   mode=ble.GAP_SCAN_MODE.GAP_SCAN_GEN_DISC_MODE,\n                   interval_ms=100,\n                   window_ms=50,\n                   filt_wlist=False,\n                   filt_dupl=True)\n```\n\nConnecting:\n\n```Python\nperipheral_addr: ble.BdAddress = ble.BleUtils.str_to_bd_addr(\"48:23:35:00:1b:53,P\") \nconnection_params = ble.GapConnParams(interval_min_ms=50, interval_max_ms=70, slave_latency=0, sup_timeout_ms=420)\ncentral.connect(peripheral_addr, connection_params)\n```\n\nRead a characteristic value\n\n```Python\ncentral.read(conn_idx=0, handle=24, offset=0) \n```\n\nWrite a characteristic value\n\n```Python\ncentral.write(conn_idx=0, handle=24, offset=0, value=1234) \n```\n\nDisconnect\n\n```Python\ncentral.disconnect(conn_idx=0) \n```\n\n### Handle asynchronous events\n\nThe framework returns asynchronous events to the application through an event queue. Calling `BleCentral.get_event()` will get an event from the queue. All of the events returned by `BleCentral.get_event()` are a subclass of `BleEventBase`.\nA variety of different events occur throughout the life a BLE application. Some example events include `BleEventGapConnectionCompleted`, `BleEventGapDisconnected`, `BleEventGattcReadCompleted`, `BleEventGattcWriteCompleted`.\nEach event has an `evt_code` to identify the type of event.  \n\nFor example, after you initiate a write you will receive a `BleEventGattcWriteCompleted` event which has an `evt_code` of `BLE_EVT_GATTC.BLE_EVT_GATTC_WRITE_COMPLETED`. Your application can\nhandle the event however it sees fit. If your application does not handle the event, call `BleCentral.handle_event_default()` to have the BLE framework process the event for you.\n\n```Python\n# This call will block until an event is available. Use the timeout parameter to block for a specified period of time\nevt = central.get_event()\n    \n    # Determine which event occurred. It will be of type BLE_EVT_GAP, BLE_EVT_GATTC, or BLE_EVT_GATTS\n    match evt.evt_code:\n\n        # Handle the event\n        case ble.BLE_EVT_GAP.BLE_EVT_GAP_ADV_REPORT:\n            # Define your own handling function to process the event\n            handle_evt_gap_adv_report(evt)\n        case ble.BLE_EVT_GAP.BLE_EVT_GAP_SCAN_COMPLETED:\n            handle_evt_gap_scan_completed(evt)\n        case ble.BLE_EVT_GAP.BLE_EVT_GAP_CONNECTED:\n            handle_evt_gap_connected(evt)\n        case ble.BLE_EVT_GAP.BLE_EVT_GAP_CONNECTION_COMPLETED:\n            handle_evt_gap_connection_completed(evt)\n        case ble.BLE_EVT_GAP.BLE_EVT_GAP_DISCONNECTED:\n            handle_evt_gap_disconnected(evt)\n        case ble.BLE_EVT_GATTC.BLE_EVT_GATTC_BROWSE_SVC:\n            handle_evt_gattc_browse_svc(evt)\n        case ble.BLE_EVT_GATTC.BLE_EVT_GATTC_BROWSE_COMPLETED:\n            handle_evt_gattc_browse_completed(evt)\n        case ble.BLE_EVT_GATTC.BLE_EVT_GATTC_NOTIFICATION:\n            handle_evt_gattc_notification(evt)\n        case ble.BLE_EVT_GATTC.BLE_EVT_GATTC_WRITE_COMPLETED:\n            handle_evt_gattc_write_completed(evt)\n        case ble.BLE_EVT_GATTC.BLE_EVT_GATTC_READ_COMPLETED:\n            handle_evt_gattc_read_completed(evt)\n\n        case _:\n            # For any events not handled by your application, call the BleCentral default handler to process the event\n            central.handle_event_default(evt)\n```\n\n## Architecture\n\nRefer to the [architecture](https://github.com/dialog-semiconductor/py_ble_manager/blob/main/docs/architecture.md) description.\n",
    "bugtrack_url": null,
    "license": "The MIT License (MIT)  Copyright (c) 2023 Renesas Electronics Corporation and/or its affiliates  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "A python library for controlling Renesas BLE devices",
    "version": "1.0.0",
    "project_urls": {
        "documentation": "https://lpccs-docs.renesas.com/py_ble_manager/index.html",
        "repository": "https://github.com/dialog-semiconductor/py_ble_manager"
    },
    "split_keywords": [
        "ble",
        "bluetooth"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "57489b0c2f8572360e8e2be3633df91c1371ebf5a101dd9f03dc4714c5a17e42",
                "md5": "ae4f3afe851c00e20dd795cb09d27b07",
                "sha256": "b173a42695e64a9f32ce2be1633a6e93e24e5e04f459d007de797dc5c407dc2e"
            },
            "downloads": -1,
            "filename": "py_ble_manager-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ae4f3afe851c00e20dd795cb09d27b07",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10.5",
            "size": 920991,
            "upload_time": "2023-08-07T20:42:43",
            "upload_time_iso_8601": "2023-08-07T20:42:43.412668Z",
            "url": "https://files.pythonhosted.org/packages/57/48/9b0c2f8572360e8e2be3633df91c1371ebf5a101dd9f03dc4714c5a17e42/py_ble_manager-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "90349272caca879464fdf0e5c09d0db3fd6b4733bd8b7d46dbdc54b6d3b467a9",
                "md5": "73b57e8adae519a1a0fdfee2e3a34993",
                "sha256": "e03905e155b500f3a50bce8acabd42ab16f96daa302f28fb9b9b41bfdabc037a"
            },
            "downloads": -1,
            "filename": "py_ble_manager-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "73b57e8adae519a1a0fdfee2e3a34993",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10.5",
            "size": 2523605,
            "upload_time": "2023-08-07T20:42:46",
            "upload_time_iso_8601": "2023-08-07T20:42:46.112178Z",
            "url": "https://files.pythonhosted.org/packages/90/34/9272caca879464fdf0e5c09d0db3fd6b4733bd8b7d46dbdc54b6d3b467a9/py_ble_manager-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-07 20:42:46",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "dialog-semiconductor",
    "github_project": "py_ble_manager",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "py-ble-manager"
}
        
Elapsed time: 0.72254s