Skip to content

Commit

Permalink
Add reboot retries when trying to connect to WiFi (#907)
Browse files Browse the repository at this point in the history
  • Loading branch information
ImUrX committed Dec 8, 2023
1 parent c3b4727 commit c3c7fc8
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class ProvisioningHandler implements SerialListener {

private final Timer provisioningTickTimer = new Timer("ProvisioningTickTimer");
private long lastStatusChange = -1;
private byte connectRetries = 0;
private final byte MAX_CONNECTION_RETRIES = 2;
private final VRServer vrServer;

public ProvisioningHandler(VRServer vrServer) {
Expand All @@ -46,13 +48,14 @@ public void start(String ssid, String password, String port) {
this.password = password;
this.preferredPort = port;
this.provisioningStatus = ProvisioningStatus.NONE;

this.connectRetries = 0;
}

public void stop() {
this.isRunning = false;
this.ssid = null;
this.password = null;
this.connectRetries = 0;
this.changeStatus(ProvisioningStatus.NONE);
this.vrServer.serialHandler.closeSerial();
}
Expand Down Expand Up @@ -118,6 +121,7 @@ public void onSerialDisconnected() {
if (!isRunning)
return;
this.changeStatus(ProvisioningStatus.NONE);
this.connectRetries = 0;
}

@Override
Expand Down Expand Up @@ -151,7 +155,11 @@ public void onSerialLog(@NotNull String str) {
provisioningStatus == ProvisioningStatus.CONNECTING
&& str.contains("Can't connect from any credentials")
) {
this.changeStatus(ProvisioningStatus.CONNECTION_ERROR);
if (++connectRetries >= MAX_CONNECTION_RETRIES) {
this.changeStatus(ProvisioningStatus.CONNECTION_ERROR);
} else {
this.vrServer.serialHandler.rebootRequest();
}
}
}

Expand Down

0 comments on commit c3c7fc8

Please sign in to comment.