in esp32-ble-device/ble/ble_uart_peripheral.py [0:0]
def __init__(self, ble_name="BLE_Device", ble_specific_id='BLE_Device', rxbuf=1500, mtu=512):
try:
self._ble = bluetooth.BLE()
self._ble.active(True)
self._ble.irq(self._irq)
((self._tx_handle, self._rx_handle),) = self._ble.gatts_register_services((_UART_SERVICE,))
# Get the BLE MAC address for this device so can insert into publish messages
# to identify this BLE device to receiving functions.
# This is used by the main function
# TODO: Put a check that the MAC is PUBLIC (type 0) so can be sure
# it doesn't change.
ble_mac_bytes = self._ble.config('mac')[1]
ble_mac_hex = ubinascii.hexlify(ble_mac_bytes, ':')
self.ble_mac = str(ble_mac_hex, 'utf-8').upper()
# Increase the size of the rx buffer and enable append mode.
self._ble.config(mtu=mtu)
self._ble.gatts_set_buffer(self._rx_handle, rxbuf, True)
self._connections = set()
self._rx_buffer = bytearray()
self._handler = None
# Optionally add services=[_UART_UUID], but this is possible to make the payload too large.
self._payload = advertising_payload(name=ble_name, manufacturer_specific=ble_specific_id, appearance=_ADV_APPEARANCE_GENERIC_COMPUTER)
self._advertise()
except Exception as err:
raise Exception('EXCEPTION: Exception initialising ESP32 BleUartPeripheral. ERROR MESSAGE: {}'.format(err))