forked from yidao620c/python3-cookbook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.py
More file actions
30 lines (24 loc) · 908 Bytes
/
controller.py
File metadata and controls
30 lines (24 loc) · 908 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""
Topic: 模拟手机客户端
Desc :
"""
import paho.mqtt.client as mqtt
# The callback for when the client receives a CONNACK response from the server.
def on_connect(cli, userdata, rc):
# Subscribing in on_connect() means that if we lose the connection and
print("Connected with result code " + str(rc))
# reconnect then subscriptions will be renewed.
cli.publish("clients/command/{}".format('001'), "Open")
cli.subscribe('clients/result/{}'.format('001'))
# The callback for when a PUBLISH message is received from the server.
def on_message(cli, userdata, msg):
print(msg.topic + " " + str(msg.payload))
cli.disconnect()
if __name__ == '__main__':
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect("192.168.203.95", 1883, 60)
client.loop_forever()