Various fixes

This commit is contained in:
Martin Bauer
2021-07-22 18:39:02 +02:00
parent 0bb0e2f121
commit a307e2a4ea
10 changed files with 19971 additions and 53 deletions

View File

@@ -30,7 +30,7 @@ const OpCodes = {
export default class SwimTrackerWebsocketConnection {
constructor(swimTrackerHost, onData, onStarted, onStopped, onWifiStateInfo, onConnect, onDisconnect) {
this.swimTrackerHost = swimTrackerHost;
this.onData = onData;
this.onStarted = onStarted;
this.onStopped = onStopped;
@@ -41,6 +41,7 @@ export default class SwimTrackerWebsocketConnection {
const wsOptions = {
maxReconnectionDelay: 4000
};
this.ws = new ReconnectingWebSocket(`ws://${swimTrackerHost}:81`, [], wsOptions);
this.ws.onmessage = this._onMessage;
this.ws.onopen = this.onConnect;
@@ -58,6 +59,15 @@ export default class SwimTrackerWebsocketConnection {
this._wifiScanPromises = [];
}
close() {
this.ws.onmessage = null;
this.ws.onopen = null;
this.ws.onclose = null;
this.ws.onerror = null;
this.ws.close();
this.ws = null;
}
sendStartCommand() {
this._sendMsg(OpCodes.START_SESSION);
}
@@ -95,6 +105,7 @@ export default class SwimTrackerWebsocketConnection {
}
wifiSetModeSTA(ssid, password) {
console.log("Setting sta mode", ssid, password);
this._sendMsg(OpCodes.WIFI_STATE_SET, {
"sta_ssid": ssid,
"sta_password": password,
@@ -108,7 +119,7 @@ export default class SwimTrackerWebsocketConnection {
msg = new Uint8Array([code, ...serializedData]);
} else {
msg = new Uint8Array(1);
msg[0] = OpCodes.WIFI_TRIGGER_SCAN;
msg[0] = code;
}
this.ws.send(msg);
}