40 lines
1 KiB
Python
Executable file
40 lines
1 KiB
Python
Executable file
#!/bin/python
|
|
|
|
import time
|
|
import paho.mqtt.client as mqtt
|
|
import argparse
|
|
import json
|
|
|
|
import mqtt_client
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description="Allen & Heath Qu MQTT event emulator")
|
|
parser.add_argument("mqtt_hostname", help="IP of the MQTT broker")
|
|
args = parser.parse_args()
|
|
|
|
print(f"MQTT broker hostname: {args.mqtt_hostname}")
|
|
|
|
def on_connect(client, userdata, flags, reason_code, properties):
|
|
print(f"Connected: {reason_code}")
|
|
client.subscribe("#")
|
|
|
|
client = mqtt.Client(callback_api_version=mqtt.CallbackAPIVersion.VERSION2)
|
|
client.on_connect = on_connect
|
|
|
|
client.connect(args.mqtt_hostname, mqtt_client.MqttClient.MQTT_SERVER_PORT, 60)
|
|
client.loop_start()
|
|
|
|
j = json.dumps({"command": "scene_recall", "args": {"scene_id": 0}})
|
|
# j = json.dumps({'command': 'shutdown'})
|
|
|
|
client.publish(mqtt_client.MqttClient.MQTT_COMMAND_TOPIC, payload=j, qos=0, retain=False)
|
|
|
|
time.sleep(2)
|
|
|
|
client.loop_stop()
|
|
client.disconnect()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|