3 Replies Latest reply on Jan 13, 2018 10:11 PM by jknorr RSS
    jknorr Newbie

    Detect lost connection Java SDK

    I took one of the Java SDK application examples and wanted to write property changes into a file, as soon as the connection to the platform gets lost, so that i can try to send them again later.

    My problem is that i dont know how to catch a connection loss properly.

    I tried it with checking client.isConnected() before i update and push a property with updateSubscribedProperties() but somehow this works only on my Windows pc.

    I have a Raspberry PI with linux and it seems like the connection won't be closed after a timeout and isConnected() returns true even if there is no real connection to ThingWorx.  And updateSubscribedProperties() doesn't throws an exception during an connection timeout on both systems.

    Any idea what the reason for this could be or what a better way to detect a lost connection would be ?

    Here the code of the procesScanRequest method that i call in the main of the Java SDK client to send properties periodically from the Device to the Platform:


    public void processScanRequest() {


      Location location = getLocation();

      DateTime time = getTimestamp();



           try {

                this.setProperty("Location", location);

                this.setProperty("Timestamp", time);



           } catch (Exception e) {

                LOG.error("Exception occured while updating properties.", e);



           //write new property values into a file