IGNORE ``Device`` and all its documentation. It is being replaced by `Peripheral` and other classes.
Provides access a to BLE device, either in a Peripheral or Central role.
When a device is created without any parameter passed to the constructor,
it will be set to the Peripheral role. If a address is passed, the device
will be a Central. For a Peripheral you can set the
name, add services
add_service and then start and stop advertising via
bleio.Device.stop_advertising. For the Central, you can
to the device, once a connection is established, the device’s services can
be accessed using
import bleio # Peripheral periph = bleio.Device() serv = bleio.Service(bleio.UUID(0x180f)) p.add_service(serv) chara = bleio.Characteristic(bleio.UUID(0x2919)) chara.read = True chara.notify = True serv.add_characteristic(chara) periph.start_advertising() # Central scanner = bleio.Scanner() entries = scanner.scan(2500) my_entry = None for entry in entries: if entry.name is not None and entry.name == 'MyDevice': my_entry = entry break central = bleio.Device(my_entry.address) central.connect()
For the Peripheral role, this property can be used to read and write the device’s name. For the Central role, this property will equal the name of the remote device, if one was advertised by the device. In the Central role this property is read-only.
bleio.Servicethat are offered by this device. (read-only) For a Peripheral device, this list will contain services added using
add_service, for a Central, this list will be empty until a connection is established, at which point it will be filled with the remote device’s services.
serviceto the list of this devices’s services. This method can only be called for Peripheral devices.
Parameters: service (bleio.Service) – the service to append
Attempts a connection to the remote device. If the connection is successful, the device’s services are available via
services. This method can only be called for Central devices.
Disconnects from the remote device. This method can only be called for Central devices.
Starts advertising the device. The device’s name and services are put into the advertisement packets. If
Truethen other devices are allowed to conncet to this device. This method can only be called for Peripheral devices.
Disconnects from the remote device. This method can only be called for Peripheral devices.