in src/ble/ble_uart_controller.py [0:0]
def publish_to_ble(self, ble_mac, message_object, with_ble_response=True):
'''
Publishes a message to the BLE Device
Params:
ble-mac (string):
BLE MAC address of the device to publish the message too.
message_object (Python Object):
Python object to be JSON serialised and transmitted to the BLE device
with_ble_response (Boolean):
Wait BLE Protocol level confirmation that the write was successful from the device.
'''
try:
# Normalise ble_mac to all upper case.
ble_mac = ble_mac.upper()
# Check is a known / connected BLE Device
if ble_mac in self.ble_devices:
# Get the BLE Peripheral Device instance
ble_device = self.ble_devices[ble_mac]
# Publish to the BLE Peripheral Device.
ble_device.publish_to_ble(message_object, with_ble_response)
else:
raise Exception('Can\'t publish. BLE Device MAC unknown or not connected.')
except bluepy.btle.BTLEDisconnectError as btleErr:
raise bluepy.btle.BTLEDisconnectError('BTLEDisconnectError: Publishing to BLE Device Disconnected: {} - DEVICE MAC: {} - MESSAGE: {}'.format(btleErr, ble_mac, message_object))
except Exception as err:
raise Exception('ERROR publishing to BLE Device: {} - DEVICE MAC: {} - MESSAGE: {}'.format(err, ble_mac, message_object))