in src/main.py [0:0]
def receive_message_router(self, topic, payload):
'''
Receive message handler / router for all (IPC and MQTT) PubSub and BLE messages.
Validates and routes messages based on topic. PubSub messages read in from
IPC and MQTT message bus with subscribed topic presented for routing and processing.
Internally, messages received from BLE devices are given the the topic: $aws/greengrass/ble/do-proxy/BLE_MAC
This uses the '$aws/' reserved topic format but is never exposed externally to the IPC or MQTT message bus.
Any BLE message received on this topic will be re-published / proxied on IPC and MQTT (depending on config settings)
message bus on the defined data topic (default: aws/things/THING_NAME/ble/data/) that is appended with /rx/BLE_MAC
address of the sending device: (i.e: aws/things/THING_NAME/ble/data/rx/XX:XX:XX:XX:XX)
Using this pattern for BLE received messages can be routed and processed in the same method as PubSub
and normalises the message flow across both protocols.
'''
try:
# Debug received message
log.debug('RECEIVED MESSAGE Topic: {} - Message: {}'.format(topic, payload))
# Note: Expects all ingress messages to be in JSON format
message_object = json.loads(payload)
# Route BLE Control messages (i.e: connect, list, disconnect)
if topic.startswith(self.pubsub_control_topic):
self.pubsub_control_router(topic, message_object)
# Process BLE messages on internal BLE proxy topic to PubSub.
elif topic.startswith(self.ble_proxy_topic):
self.proxy_ble_to_pubsub(topic, message_object)
# Process PubSub messages proxy to BLE
elif topic.startswith(self.pubsub_data_tx_topic):
self.proxy_pubsub_to_ble(topic, message_object)
else:
raise Exception('Received mesage on unknown / unsupported topic.')
except Exception as err:
msg = 'Message Callback Exception: {} - Topic {} - Payload: {}'.format(err, topic, payload)
log.error(msg)
self.publish_error(500, msg)