Task returned from timer.scheduleAsync faulted
Hi,
I'm trying to schedule a task that reads the RSSI every 500 ms.
timer = mwBoard.getModule(Timer.class);
timer.scheduleAsync(500, true, new CodeBlock() {
@Override
public void program() {
mwBoard.readRssiAsync().onSuccess(task -> {...})
return null;
}
}).continueWith(task -> {
if (task.isFaulted()){
Log.i(LOG_TAG,"Error : " + task.getError());
}
scheduledTask = task.getResult();
Log.i(LOG_TAG,String.valueOf(task.getResult().id()));
return null;
});
timer.scheduleAsync(500, true, new CodeBlock() {
@Override
public void program() {
mwBoard.readRssiAsync().onSuccess(task -> {...})
return null;
}
}).continueWith(task -> {
if (task.isFaulted()){
Log.i(LOG_TAG,"Error : " + task.getError());
}
scheduledTask = task.getResult();
Log.i(LOG_TAG,String.valueOf(task.getResult().id()));
return null;
});
But the task returned is always failed and the Error is:
Error : java.lang.NullPointerException: Attempt to read from null array
What i'm doing wrong?
And another question: Do you think that this is a good way to monitorize the RSSI?
I've read about the posibility of doing it with the method Handler.post(readRSSI)
being readRSSI a runable code like that:
mwBoard.readRssiAsync()...
handler.postDelayed(readRSSI, 500);
}
}
Or do you think there is a better way to do that?
Thank you.
This discussion has been closed.
Comments
@Override
public void run() {
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mwBoard != null && mwBoard.isConnected() && mBluetoothAdapter.isEnabled()) {
Log.i(LOG_TAG, "connection still active");
handler.postDelayed(readRSSI, 500);
//Read RSSI
mwBoard.readRssiAsync().onSuccess(task -> {
if (task != null && task.isCompleted() && !task.isFaulted() && !task.isCancelled()){
Log.i(LOG_TAG,"RSSI leido de la placa : " + task.getResult());
sendBroadcastMessage(task.getResult().toString());
}
return null;
});
} else {
Log.i(LOG_TAG, "connection lost");
handler.removeCallbacks(readRSSI);
stopSelf();
}
}
};