浏览代码

接口调试

q 2 年之前
父节点
当前提交
6e0a8eddc8
共有 2 个文件被更改,包括 37 次插入1 次删除
  1. 0 1
      jf_pump_center.py
  2. 37 0
      jf_test_pump_center.py

+ 0 - 1
jf_pump_center.py

@@ -53,7 +53,6 @@ class jf_pump_center():
         timeStamp = jsonObj['timestamp'] / 1000
         times = datetime.datetime.fromtimestamp(timeStamp)
         print(times)
-        time.sleep(t)
 
     # 获取点位
     def get_base_data(self):

+ 37 - 0
jf_test_pump_center.py

@@ -0,0 +1,37 @@
+import paho.mqtt.client as mqtt
+import json
+ 
+ 
+class EstimationWeightUpdate(object):
+ 
+    def __init__(self):
+        self.init_mqtt()
+        
+        
+    # The callback for when the client receives a CONNACK response from the server.
+    def on_connect(self, client, userdata, flags, rc):
+        print("Connected with result code "+str(rc))    #rc的值很重要,为0代表连接成功。
+     
+        # Subscribing in on_connect() means that if we lose the connection and
+        # reconnect then subscriptions will be renewed.
+        self.client.subscribe("$SYS/#")    #订阅$SYS/下的所有主题
+     
+    # The callback for when a PUBLISH message is received from the server.
+    def on_message(self, client, userdata, msg):
+        print(msg.topic+" "+str(msg.payload))
+ 
+    def init_mqtt(self):
+        self.client = mqtt.Client("ADADWWRWFGWERWRWFGTERTER-SUB")
+        self.client.username_pw_set("admin", password="longruan123")
+        self.client.on_connect = self.on_connect    #连接broker时broker响应的回调
+        self.client.on_message = self.on_message    #接收到订阅消息时的回调
+        
+
+    def subscribe_update_topic(self):
+        self.client.connect("10.71.146.182", 1883, 60)    #连接到broker
+        self.client.subscribe("1/1/2", 0)
+        self.client.loop_forever() 
+        
+if __name__ == "__main__":
+    ew = EstimationWeightUpdate()
+    ew.subscribe_update_topic()