I quite new to programming but I have somehow managed to develop an Android app that I’m using to control the heater in my caravan using an Electron hooked up to the heaters serial interface. It works very well but I have a problem that occurs sometimes that I haven’t been able to solve. Maybe it’s easy or maybe I’m just doing things wrong. Can anyone help me out?
For my app I have a background service that’s listening for events from my Electron. In the service I’m subscribing to events using something like the following code.
public class ListenForDataThread extends Thread {
public void run() {
long subscriptionId;
try {
ParticleCloudSDK.getCloud().logIn(pref_user_id, pref_password);
} catch (ParticleCloudException e) {
e.printStackTrace();
}
try {
myDevice = ParticleCloudSDK.getCloud().getDevice(pref_device);
} catch (ParticleCloudException e) {
e.printStackTrace();
}
if (myDevice != null) {
try {
subscriptionId = myDevice.subscribeToEvents("state",
particleEventHandler = new ParticleEventHandler() {
public void onEvent(String eventName, ParticleEvent event) {
//...Do some things…
}
}
public void onEventError(Exception e) {
e.printStackTrace();
}
});
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
The problem I’m having is that sometimes I get an exception like this:
E/HttpRequestDelegateImpl: javax.net.ssl.SSLException: Read error: ssl=0x71813f7200: I/O error during system call, Software caused connection abort
I don’t know why this happens and I’m unable to catch it when it happens. I suspect that it occurs when something is happening with the network. I can force a similar situation by switching network but that I’m able to catch and act on. When it happens it seems that the ParticleEventHandler dies and I’m no longer receiving any events. Since I’m unable to catch it I don’t know how to act on it in my code and I have to manually restart my app to get it to work again.
Thank you!