def on_publish_received()

in tools/cloud/iot-topic-subscribe.py [0:0]


def on_publish_received(message):
    global received_data
    packet = message.publish_packet
    print(f"Received message on topic: {packet.topic}")
    try:
        # Parse the message payload and extract the relevant data
        data = json.loads(packet.payload)
        if received_data is None:
            print(f"Received data: {json.dumps(data, indent=2)}")
        else:
            received_data.append(data)
    except Exception as e:
        print(f"Error parsing message: {e}")