def ble_message_callback()

in esp32-ble-device/main.py [0:0]


    def ble_message_callback(self):
        '''
            Main Callback for all received BLE Messages. Triggered by BLE IRQ. 
            Reads in the message, provides initial message validation and 
            forwards to the message routers.
            
            Expects message payload provided is JSON that can be Serialized and 
            Deserialized to a programmatic language specific object in the 
            prescribed message formats.
        '''

        try:

            # Read in BLE message from ble_peripheral
            payload = self.ble_peripheral.read().decode().strip()

            # Debug unprocessed message
            print('BLE RECEIVED MESSAGE: {}\n'.format(payload))

            # Json loads the message
             # Note: This example expects all messages to be valid JSON format
            message = json.loads(payload)
            self.ble_request_message_router(message)

        except ValueError as val_error: # includes JSON parsing errors
            err_msg = {'error-message' : 'VAL_ERROR: JSON Parsing Error / Unexpected PubSub message format received. ERROR MESSAGE {}'.format(val_error)}
            self.publish_exception(500, err_msg)

        except KeyError as key_error: # includes requests for fields that don't exist in the received object
            err_msg = {'error-message' : 'KEY_ERROR: Received PubSub message missing required fields. ERROR MESSAGE {}'.format(key_error)}
            self.publish_exception(500, err_msg)

        except Exception as err:
            err_msg = {'error-message' : 'EXCEPTION from BLE message callback. ERROR MESSAGE {}'.format(err)}
            self.publish_exception(500, err_msg)

        finally:
            gc.collect()