Skip to content

Time Sync

The Open Edge Device Kit publishes a message when the MindSphere 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 MindSphere Clock

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

    1
    2
    3
    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.

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

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

Any questions left?

Ask the community


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