Delay

This unmanged application monitors time status updates for any managed application specified by the user. The application records the difference between wallclock time when message published (included in message payload) and wallclock time when message received (checked against local clock with offset from initial NIST query). The following code demonstrates how this unmanaged application connects to the message broker, set up subscriptions to different topics, and add callback functions without using the NOS-T tools library.

    # Note that these are loaded from a .env file in current working directory
    credentials = dotenv_values(".env")
    HOST, PORT = credentials["HOST"], int(credentials["PORT"])
    USERNAME, PASSWORD = credentials["USERNAME"], credentials["PASSWORD"]

    # build the MQTT client
    CLIENT = mqtt.Client()
    # set client username and password
    CLIENT.username_pw_set(username=USERNAME, password=PASSWORD)
    # set tls certificate
    CLIENT.tls_set()
    # connect to MQTT server on port 8883
    CLIENT.connect(HOST, PORT)
    
    # subscribe to the correct topics
    subList = [(f"{PREFIX}/manager/start",0), (f"{PREFIX}/manager/stop",0), (f"{PREFIX}/heartbeat/settings",0)]
    for i, application in enumerate(hbdr.names):
        subList.append((f"{PREFIX}/status/{application}/time",0))
    CLIENT.subscribe(subList)
    
    # add on_message as a callback function
    CLIENT.on_message = hbdr.on_message
    CLIENT.loop_forever()