01-con-discon-success.test 548 字节
Newer Older
1
#!/usr/bin/env python
R
Roger Light 已提交
2 3 4 5 6 7 8 9

import os
import subprocess
import socket
import sys
import time
from struct import *

R
Roger Light 已提交
10
import paho.mqtt.client as mqtt
R
Roger Light 已提交
11 12


13
def on_connect(mqttc, obj, flags, rc):
R
Roger Light 已提交
14 15 16
    if rc != 0:
        exit(rc)
    else:
R
Roger Light 已提交
17
        mqttc.disconnect()
R
Roger Light 已提交
18

R
Roger Light 已提交
19 20
def on_disconnect(mqttc, obj, rc):
    mqttc.loop()
R
Roger Light 已提交
21 22 23 24
    obj = rc


run = -1
25
mqttc = mqtt.Client("01-con-discon-success", run, protocol=mqtt.MQTTv31)
R
Roger Light 已提交
26 27
mqttc.on_connect = on_connect
mqttc.on_disconnect = on_disconnect
R
Roger Light 已提交
28

R
Roger Light 已提交
29
mqttc.connect("localhost", 1888)
R
Roger Light 已提交
30
while run == -1:
R
Roger Light 已提交
31
    mqttc.loop()
R
Roger Light 已提交
32 33

exit(run)