The `server` thing has the following configuration parameters:
-| Parameter | Required | Description |
-|--------------------|----------|-----------------------------------------------------------------------------------------------------------|
-| host | yes | The host name or IP address of the remote openHAB server. |
-| useHttps | no | Set to true if you want to use HTTPS to communicate with the remote openHAB server. Default is false. |
-| port | yes | The HTTP port to use to communicate with the remote openHAB server. Default is 8080. |
-| trustedCertificate | no | Set to true if you want to use HTTPS even without a valid SSL certificate provided by your remote server. |
-| restPath | yes | The subpath of the REST API on the remote openHAB server. Default is /rest |
-| token | no | The token to use when the remote openHAB server is setup to require authorization to run its REST API. |
+| Parameter | Required | Description |
+|-----------------------|----------|-----------------------------------------------------------------------------------------------------------|
+| host | yes | The host name or IP address of the remote openHAB server. |
+| useHttps | no | Set to true if you want to use HTTPS to communicate with the remote openHAB server. Default is false. |
+| port | yes | The HTTP port to use to communicate with the remote openHAB server. Default is 8080. |
+| trustedCertificate | no | Set to true if you want to use HTTPS even without a valid SSL certificate provided by your remote server. |
+| restPath | yes | The subpath of the REST API on the remote openHAB server. Default is /rest |
+| token | no | The token to use when the remote openHAB server is setup to require authorization to run its REST API. |
+| accessibilityInterval | no | Minutes between checking the remote server accessibility. 0 to disable the check. Default is 3. |
+| aliveInterval | no | Number of last minutes to take into account to determine whether the remote server is alive. 0 to disable this feature. Default is 5. |
The `thing` thing has the following configuration parameters:
public boolean trustedCertificate = false;
public String restPath = "/rest";
public String token = "";
+ public int accessibilityInterval = 3;
+ public int aliveInterval = 5;
}
private static final String DATE_FORMAT_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
private static final DateTimeFormatter FORMATTER_DATE = DateTimeFormatter.ofPattern(DATE_FORMAT_PATTERN);
- private static final long CONNECTION_TIMEOUT_MILLIS = TimeUnit.MILLISECONDS.convert(5, TimeUnit.MINUTES);
private static final int MAX_STATE_SIZE_FOR_LOGGING = 50;
private final Logger logger = LoggerFactory.getLogger(RemoteopenhabBridgeHandler.class);
updateStatus(ThingStatus.UNKNOWN);
- startCheckConnectionJob();
+ scheduler.submit(this::checkConnection);
+ if (config.accessibilityInterval > 0) {
+ startCheckConnectionJob(config.accessibilityInterval, config.aliveInterval);
+ }
}
@Override
}
}
- private void startCheckConnectionJob() {
+ private void startCheckConnectionJob(int accessibilityInterval, int aliveInterval) {
ScheduledFuture<?> localCheckConnectionJob = checkConnectionJob;
if (localCheckConnectionJob == null || localCheckConnectionJob.isCancelled()) {
checkConnectionJob = scheduler.scheduleWithFixedDelay(() -> {
long millisSinceLastEvent = System.currentTimeMillis() - restClient.getLastEventTimestamp();
- if (millisSinceLastEvent > CONNECTION_TIMEOUT_MILLIS) {
- logger.debug("Check: Maybe disconnected from streaming events, millisSinceLastEvent={}",
+ if (aliveInterval == 0 || restClient.getLastEventTimestamp() == 0) {
+ logger.debug("Time to check server accessibility");
+ checkConnection();
+ } else if (millisSinceLastEvent > (aliveInterval * 60000)) {
+ logger.debug(
+ "Time to check server accessibility (maybe disconnected from streaming events, millisSinceLastEvent={})",
millisSinceLastEvent);
checkConnection();
} else {
- logger.debug("Check: Receiving streaming events, millisSinceLastEvent={}", millisSinceLastEvent);
+ logger.debug(
+ "Bypass server accessibility check (receiving streaming events, millisSinceLastEvent={})",
+ millisSinceLastEvent);
}
- }, 0, CONNECTION_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
+ }, accessibilityInterval, accessibilityInterval, TimeUnit.MINUTES);
}
}
<description>The token to use when the remote openHAB server is setup to require authorization to run its REST API.</description>
<advanced>true</advanced>
</parameter>
+
+ <parameter name="accessibilityInterval" type="integer" min="0" step="1" unit="min">
+ <label>Accessibility Interval</label>
+ <description>Minutes between checking the remote server accessibility. 0 to disable the check. Default is 3.</description>
+ <default>3</default>
+ <advanced>true</advanced>
+ </parameter>
+
+ <parameter name="aliveInterval" type="integer" min="0" step="1" unit="min">
+ <label>Alive Interval</label>
+ <description>Number of last minutes to take into account to determine whether the remote server is alive. 0 to
+ disable this feature. Default is 5.</description>
+ <default>5</default>
+ <advanced>true</advanced>
+ </parameter>
</config-description>
</bridge-type>