I am using paho mqtt
written a class
class initializer():
def __init__(self):
self.client = mqtt.Client(mqtt_server+str(int(time.time())))
self.client.username_pw_set(
username=mqtt_username, password=mqtt_password)
self.client.on_connect = self.on_connect
self.client.on_subscribe = self.on_subscribe
self.client.connect(broker, mqtt_port)
self.client.loop_start()
def on_connect(self, client, userdata, flags, rc):
if rc == 0:
#app_logger.info("Device Connection Established")
print("Device Connection Established")
else:
#app_logger.info("Bad Connection")
print("Bad Connection")
def on_message(self, client, userdata, message):
# app_logger.info(message.topic)
print("message.topic", message.payload)
then I have inherited this class to another class.
class PublishData(initializer):
def __init__(self):
super(PublishData, self).__init__()
self.client.on_message = self.on_message
def on_message(self, client, userdata, message):
print("message.payloa", message.payload)
def begin(self, topic, data):
self.client.on_message = self.on_message
self.client.subscribe(
"topic")
self.client.publish(
topic, str(data))
publishData = PublishData()
publishData.begin(topic, data)
I am getting message in on_message function in initializer class but I am not getting that message in inherited class. How do I get the message.payload value in PublishData class?