Skip to content

Time Sync

The Open Edge Device Kit publishes a message when the Insights Hub clock differs from the device clock. The clock skew is published in the diff field of the topic agentruntime/monitoring/clockskew. It holds the time difference in seconds represented by an integer which is acquired using the following formula:

serverTime [s] - deviceTime [s]

This means for example, that if diff is -10, the device clock must be turned back by 10 seconds.

Synchronizing Device Clock and Insights Hub Clock

  1. Establish a connection to the MQTT broker where <mqtt_host> is the host name and <mqtt_port> is the port:

    String broker = String.format("tcp://%s:%d", <mqtt_host>, <mqtt_port>);
    MqttClient mqttClient = new MqttClient(broker, "MQTTClientID");
    mqttClient.connect();
    
  2. Subscribe to the respective topic.

    mqttClient.subscribe("agentruntime/monitoring/clockskew", mqttMessageListener);
    
  3. Handle the message and generate a log message. Update the device time (not shown below).

    @Override
    public void messageArrived(String topic, MqttMessage message) {
        LOG.info("MQTT message arrived: {} --> {}", topic, message.toString());
    }
    

Last update: April 13, 2023

Except where otherwise noted, content on this site is licensed under the Development License Agreement.