Peripheral – A BLE peripheral device

Implement a BLE peripheral which runs locally. Set up using the supplied services, and then allow advertising to be started and stopped.

Usage:

import bleio

# Create a Characteristic.
chara = bleio.Characteristic(bleio.UUID(0x2919), read=True, notify=True)

# Create a Service providing that one Characteristic.
serv = bleio.Service(bleio.UUID(0x180f), [chara])

# Create a peripheral and start it up.
periph = bleio.Peripheral([service])
periph.start_advertising()

while not periph.connected:
    # Wait for connection.
    pass
class bleio.Peripheral(services, *, name='CIRCUITPY')

Create a new Peripheral object. :param iterable services: the Service objects representing services available from this peripheral. :param str name: The name used when advertising this peripheral

connected

True if connected to a BLE Central device.

services

A tuple of bleio.Service that are offered by this peripheral. (read-only)

name

The peripheral’s name, included when advertising. (read-only)

start_advertising(*, connectable=True, data=None)

Starts advertising the peripheral. The peripheral’s name and services are included in the advertisement packets.

Parameters:
  • connectable (bool) – If True then other devices are allowed to connect to this peripheral.
  • data (buf) – If None, advertise the services passed to this Peripheral when it was created. If not None, then send the bytes in data as the advertising packet.
stop_advertising()

Stop sending advertising packets.