Select Git revision

Matthias Stefan Bodenbenner authored
publish.py 1.22 KiB
import datetime
import json
import random
import time
import uuid
from src import mqtt
### Ask for settings and individual credentials ###
MQTT_USER = "bdn-aafdecf0-a14c-4cb5-bb08-3844399e0a25"
MQTT_PASSWORD = "azesR4Q8~M7UBKh<7S~d\"NN-|)i9:Le["
MQTT_BROKER = "mqtt.wzl-mq.rwth-aachen.de"
MQTT_PORT = "0"
MQTT_VHOST = "metrology"
### to connect to the central MQTT-Broker of MQ-MS use the following settings:
# MQTT_BROKER = "wzl-mbroker01.wzl.rwth-aachen.de"
# MQTT_PORT = 1883
# MQTT_VHOST = "metrology"
### Ask for settings and individual credentials ###
if __name__ == "__main__":
client = mqtt.MQTTPublisher(prefix="bdn-212d8419-c75c-471f-8ea5-f3a5c19ac42e")
client.connect(MQTT_BROKER, MQTT_USER, MQTT_PASSWORD, vhost=MQTT_VHOST, port=MQTT_PORT, ssl=True)
while True:
try:
message = json.dumps({"value": [random.uniform(0, 5) for i in range(3)], "timestamp": datetime.datetime.utcnow().isoformat() + "Z",
"covariance": [[2, 0, 0], [0, 2, 0], [0, 0, 0]], "nonce": str(uuid.uuid4()), "hash": None, "unit": "MTR"})
client.publish("channel-001", message.encode("utf-8"), 2)
# time.sleep(0.01)
except KeyboardInterrupt:
break