前言
经历过各种问题的磨难终于基本搭建完成了自己的MQTT服务器,接下来我就赶紧写个Python程序测试下.
安装
这里采用paho.mqtt.python编写程序,详情参阅这里
打开powershell,执行pip install paho-mqtt
安装模块
程序
# coding=utf-8
import json
import threading
import paho.mqtt.client as mqtt
# 当连接上服务器后回调此函数
import time
from my_lib.code_handle.code_handle import auto_code
from windows_info.read_info import Win_psutil
class MqttClient:
client = mqtt.Client('tester')
def __init__(self, host, port):
self._host = host
self._port = port
self.client.on_connect = self._on_connect # 设置连接上服务器回调函数
self.client