I have a wear-os standalone application written in java, which connects as client (org.java_websocket.client.WebSocketClient) via WLAN websockets to a server (org.java_websocket.server.WebSocketServer) running on the smartphone (TicWatch Pro 3). When I run the code, everything works fine (web sockets connect) as long as the smartwatch is charging. As soon as I disconnect the charger and try to connect the smartwatch client via websockets to the smartphone server no connection can be established. No error is shown, there is simply no connection established.
This is a simplified version of the Runnable class used to start the web socket client.
public class BackgroundReceiverThread implements Runnable {
public static void startBackgroundReceiver(){
AsyncTask.execute(new BackgroundReceiverThread());
}
private BackgroundReceiverThread() {}
//@Override
public void run() {
try {
client=new BackgroundReceiverClient(new URI("ws://localhost:8887"));
client.connect();
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
}
The BackgroundReceiverClient class looks the following:
public class BackgroundReceiverClient extends WebSocketClient {
public BackgroundReceiverClient(URI serverUri) {
super(serverUri);
}
@Override
public void onOpen(ServerHandshake serverHandshake) {
Log.i("mytag","On Open");
}
@Override
public void onError(Exception e) {
Log.i("mytag","On Error:"+e.getMessage());
}
}
When the smartwatch is charging and BackgroundReceiverThread.startBackgroundReceiver() is invoked, the onOpen() method is invoked. When the charger is disconnected the onOpen() method is not invoked.
I assume this is due to energy saving precautions of the smartwatch, which are activated when not charging. I have already tried to identify the respective setting on the smartwatch but couldn't find it.
How can I get the client connecting to the server when the smartwatch is not charging?
from Establishing WearOS webSocket connection when smartwatch not charging
No comments:
Post a Comment