def pubsub_control_router()

in src/main.py [0:0]


    def pubsub_control_router(self, topic, message):
        '''
        Route BLE Control messages such as Connect, Disconnect amd List BLE Devices
        Topic expected format 'aws-greengrass/things/THING_NAME/ble/control/CONTROL_COMMAND' as per pubsub_control_topic
        '''

        try:
            topic_split = topic.split('/')

            if not len(topic_split) == 6:
                raise Exception('Received BLE control command with unsupported topic structure')
            
            control_command = topic_split[5]

            log.debug('Received BLE Control Message Topic: {} -  Control Command: {}, Message: {}'.format(topic, control_command, message))

            if control_command == 'connect':
                # Get the expected BLE MAC address in a connect control message
                ble_mac = message['ble-mac']
                self.connect_ble_device(ble_mac)

            elif control_command == 'disconnect':
                # Get the expected BLE MAC address in a disconnect control message
                ble_mac = message['ble-mac']
                self.disconnect_ble_device(ble_mac)

            elif control_command == 'list':
                self.get_ble_device_list()
            
            elif control_command == 'scan':
                self.scan_ble_devices()
            
            else:
                raise Exception('Received message on unknown BLE Gateway Control Topic')

        except ValueError as val_error: # includes JSON parsing errors
            msg = 'BLE Control Routing VAL_ERROR: {} - Topic {} - Message: {}'.format(val_error, topic, message)
            log.error(msg)
            self.publish_error(500, msg)

        except KeyError as key_error: # includes requests for fields that don't exist
            msg = 'BLE Control Routing KEY_ERROR: {} - Topic {} - Message: {}'.format(key_error, topic, message)
            log.error(msg)
            self.publish_error(500, msg)

        except Exception as err:
            msg = 'BLE Control Routing EXCEPTION: {} - Topic {} - Message: {}'.format(err, topic, message)
            log.error(msg)
            self.publish_error(500, msg)