Python Forum
How to clean session mqtt - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: How to clean session mqtt (/thread-23054.html)



How to clean session mqtt - SayHiii - Dec-09-2019

import paho.mqtt.client as mqtt
import subprocess
import os
import time

def on_connect(client, userdata, flags, rc):
    print ("Connected with Code :" +str(rc))
    print ("Connected IP: " + Ip_connect)
        #Subscribe topic
    client.subscribe("test", qos=1)

def on_message( client, userdata, msg):
    global mybuffer
    mybuffer = str(msg.payload)
    print('on_message: '+ mybuffer)
    if mybuffer == "b'Open'":
        print("Program is Opening")
        subprocess.call(r'C:\Qt\5.13.1\mingw73_32\bin\designer.exe')
        #subprocess.call(r'python py_exe.py')

    if mybuffer == "b'Close'":
        print("Program is Closing")



client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
Ip_connect = "172.30.102.56"
client.connect(Ip_connect, 1883, 60)

client.loop_forever()
From my code when I publish msg "Open" My program(Qt Designer) will open but after I closed the program and I published the msg "Open"
again It's not thing happened.

So my Question is after I closed My program(Qt Designer) I want to make my code to clean session for make it's ready to receive the new topic.

sorry for my English.