Skip to content

Commit

Permalink
Try to bind multiple times in case of connection timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
pbogut committed Aug 21, 2020
1 parent f46d914 commit 94b787b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@ public class EWPESmartBindingConstants {
public static final int DATAGRAM_SOCKET_TIMEOUT = 5000;
public static final int MINIMUM_REFRESH_TIME = 1000;

public static final int BIND_DEVICE_TRIES = 10;
public static final int SEND_MESSAGE_TRIES = 10;
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,29 @@ public void initialize() {
"Invalid EWPE Smart config. Check configuration.");
} else {
scheduler.execute(() -> {
bindDevice();
int tryNo = 1;
while(true) {
try {
bindDevice();
break;
} catch (SocketTimeoutException e) {
logger.debug("EWPESmart: failed to scan for airconditioners due to Timeout, try no. {}", tryNo);
if (tryNo >= BIND_DEVICE_TRIES) {
logger.warn("EWPESmart failed to bind device thing.getUID() due to connection timeout after {} tries", e.getMessage(), tryNo);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"Could not bind device due to multiple connection timeouts.");
break; // just give up
}
tryNo++;
}
}
});
}

logger.debug("Finished initializing!");
}


private void bindDevice() {
private void bindDevice() throws SocketTimeoutException {
ipAddress = config.getIpAddress();
refreshTime = config.getRefresh();
broadcastAddress = config.getBroadcastIp();
Expand Down Expand Up @@ -152,6 +166,9 @@ private void bindDevice() {
}
}
updateStatus(ThingStatus.ONLINE);
} catch (SocketTimeoutException e) {
// bubble up so we can retry
throw e;
} catch (UnknownHostException e) {
logger.debug("EWPESmart failed to scan for airconditioners due to {} ({})", e.getMessage(), e.getClass());
} catch (IOException e) {
Expand Down

0 comments on commit 94b787b

Please sign in to comment.