Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to clean session mqtt
#1
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Can i clean this code ? BSDevo 8 933 Oct-28-2023, 05:50 PM
Last Post: BSDevo
  add mqtt feature to existing code Positron79 0 587 Jan-31-2023, 05:56 PM
Last Post: Positron79
  Clean Up Script rotw121 2 1,005 May-25-2022, 03:24 PM
Last Post: rotw121
  Mqtt Shiri 0 1,279 Dec-07-2021, 02:01 PM
Last Post: Shiri
  How to clean UART string Joni_Engr 4 2,471 Dec-03-2021, 05:58 PM
Last Post: deanhystad
  Paho-mqtt fully supports MQTT 5.0 protocol? nitinkothari17 0 1,549 Jan-12-2021, 11:14 AM
Last Post: nitinkothari17
  how to clean up unstarted processes? Skaperen 2 2,227 Aug-27-2019, 05:37 AM
Last Post: Skaperen
  sched.scheduler -> clean denisit 1 2,867 Nov-28-2018, 09:52 AM
Last Post: Gribouillis
  Arduino Uno connected to PI 0 W - Sensor Data MQTT runboy 4 3,064 Nov-07-2018, 03:55 AM
Last Post: runboy
  clean script by code fen1c5 8 4,680 Oct-16-2018, 05:11 AM
Last Post: volcano63

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020