-
Notifications
You must be signed in to change notification settings - Fork 73
/
MQTT_remote.py
49 lines (38 loc) · 1.36 KB
/
MQTT_remote.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import paho.mqtt.client as mqtt
import time
def on_connect(mqttc, obj, flags, rc):
print("rc: " + str(rc))
def on_message(mqttc, obj, msg):
print(msg.topic + " " + str(msg.qos) + " " + str(msg.payload))
def on_publish(mqttc, obj, mid):
print("mid: " + str(mid))
pass
def on_subscribe(mqttc, obj, mid, granted_qos):
print("Subscribed: " + str(mid) + " " + str(granted_qos))
def on_log(mqttc, obj, level, string):
print(string)
mqttc = mqtt.Client()
mqttc.on_message = on_message
mqttc.on_connect = on_connect
mqttc.on_publish = on_publish
mqttc.on_subscribe = on_subscribe
mqttc.on_log = on_log
mqttc.connect("192.168.12.1", 1883, 60)
mqttc.loop_start()
infot = mqttc.publish("controller/action", "standDown", qos=2)
infot.wait_for_publish()
time.sleep(2)
infot = mqttc.publish("controller/action", "standUp", qos=2)
infot.wait_for_publish()
time.sleep(2)
infot = mqttc.publish("controller/action", "recoverStand", qos=2)
infot.wait_for_publish()
time.sleep(2)
infot = mqttc.publish("controller/action", "walk", qos=2)
infot.wait_for_publish()
time.sleep(2)
infot = mqttc.publish("controller/stick", "\xac\x4a\x3a\x3e\x00\x00\x00\x00\x00\x00\x00\x00\x2e\x64\x42\x3e", qos=2)
infot.wait_for_publish()
time.sleep(1)
infot = mqttc.publish("controller/stick", "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00x00", qos=2)
infot.wait_for_publish()