Uble Save

Lightweight Bluetooth Low Energy driver written in pure python for micropython

Project README

uble

Lightweight Bluetooth Low Energy driver written in pure python for micropython.

WARNING: this project is in beta stage and is subject to changes of the code-base, including project-wide name changes and API changes.

Features

  • Parsing and Building of HCI packets
  • Allows PyBoard to control BLE chips using HCI packets

Usage

  • Parsing of HCI packets:
        MicroPython v1.8.7-79-g221f88d-dirty on 2017-01-26; PYBv1.1 with STM32F405RG
        Type "help()" for more information.
        >>> from bluetooth_low_energy.protocols.hci import (cmd, uart)
        >>> buf = b'\x01\x03\x0c\x00'
        >>> hci_uart = uart.HCI_UART.from_buffer(buf)
        >>> print(hci_uart)
        <HCI_UART pkt_type=COMMAND(0x01) data=030c00>
        >>> hci_cmd = cmd.HCI_COMMAND.from_buffer(hci_uart.data)
        >>> print(hci_cmd)
        <HCI_COMMAND opcode=0x0c03 ogf=HOST_CTL(0x03) ocf=RESET(0x03) request_data= response_data=>
        >>> hci_cmd.to_buffer()
        b'\x03\x0c\x00'        
        >>>
  • Building of HCI Packets:
        MicroPython v1.8.7-79-g221f88d-dirty on 2017-01-26; PYBv1.1 with STM32F405RG
        Type "help()" for more information.
        >>> from bluetooth_low_energy.protocols.hci import cmd
        >>> hci_cmd = cmd.HCI_COMMAND(ogf=cmd.OGF_LE_CTL, ocf=cmd.OCF_LE_RAND)
        >>> print(hci_cmd)
        <HCI_COMMAND opcode=0x2018 ogf=LE_CTL(0x08) ocf=LE_RAND(0x18) request_data= response_data=>
        >>> hci_cmd.to_buffer()
        b'\x18 \x00'
        >>>
  • Control BLE chips examples

    With low level api:

    With high level api:

    • api_eddystone.py: implement an Eddystone Beacon device

    • api_sensor_demo.py: usable for test with 'BlueNRG' app

    • api_scan.py: implement a Scanner object used to scan for LE devices which are broadcasting advertising data

    • api_hid_over_gatt.py: implement a HID over GATT keyboard (tested with iOS and Windows 10)

    • api_repl.py: implement a Bluetooth LE REPL (need _thread enabled and external dependency collections.deque already available into folder 'micropython-lib' of this repository. If found ucollections.deque use it internally) Usable terminal available at Micropython WebBluetooth REPL

      MicroPython_WebBluetooth_REPL

Software

Currently implemented full HCI commands from STSW-BLUENRG-DK 2.0.2

User manual BlueNRG-MS Bluetooth® LE stack application command interface

Programming manual BlueNRG, BlueNRG-MS stacks programming guidelines

Hardware

Currently supported module STMicroelectronics SPBTLE-RF

From STMicroelectronics X-NUCLEO-IDB05A1:

X_Nucleo_IDB05A1_mbed_pinout_v1

PyBoard breakout board: MicroPython_SPBTLERF_Breakout_v03_mod_TOP_and_BOTTOM

Fritzing for breakout: MicroPython_SPBTLERF_Breakout_v03_mod.fzz

Gerber for breakout: MicroPython_SPBTLERF_Breakout_v03_mod.zip

If have interest into preassembled breakout board contact me at [email protected]

External dependencies

Only for examples: 'logging' already available into folder 'micropython-lib' of this repository

Install 'bluetooth_low_energy' into the pyboard

To enable the functionality you need to freeze the package 'bluetooth_low_energy', to do this, copy the package 'bluetooth_low_energy' into 'micropython-lib'.

Navigate to the folder containing the repository micropython:

        $ cd ports/stm32
        $ make FROZEN_MPY_DIR="~/uble/micropython-lib"
Open Source Agenda is not affiliated with "Uble" Project. README Source: dmazzella/uble
Stars
82
Open Issues
0
Last Commit
5 years ago
Repository
License
MIT

Open Source Agenda Badge

Open Source Agenda Rating