How to interface two RaspberryPis over MQTT with Cayenne

try this code:-
You will need two devices on the cayenne dashboard.
Client_id_B is the subscribe device.
Client_id_A is the publish device.

import paho.mqtt.client as mqtt
import time
import sys

time.sleep(5)  # Sleep to allow wireless to connect before starting MQTT

username = "username"
password = "pass"
clientid = "client_id_B"

topics = "v1/username/things/client_id_A/data/21"


def on_message_msgs(mosq, obj, msg):
    # This callback will only be called for messages with topics that match
    # $SYS/broker/messages/#
    print("MESSAGES: " + msg.topic + " " +
          str(msg.qos) + " " + str(msg.payload))


mqttc = mqtt.Client(client_id=clientid)
mqttc.username_pw_set(username, password=password)
mqttc.connect("mqtt.mydevices.com", port=1883, keepalive=60)
# mqttc.loop_start()
mqttc.message_callback_add(topics, on_message_msgs)
mqttc.subscribe(topics, 0)

topic_dht11_temp = "v1/" + username + "/things/" + clientid + "/data/1"

while True:
    mqttc.loop_forever()
    temp11 = 22
    temp11 = "temp,c=" + str(temp11)
    mqttc.publish(topic_dht11_temp, payload=temp11, retain=True)