Should I use service or/and alarm manager to download log entries from the board?
Hi,
What is the best way to periodically and reliably download logs from the board?
Should I use two apps one to program the sensor and another app (service/alarm manager) to download logs?
Right now I stream data and immediately upload to the cloud but when phone gets disconnected from the board I am loosing entries.
I was trying to split the app into two but I don't know how to get the MessageHandler to run on the service app.
Thank you very much,
Michael
This discussion has been closed.
Comments
For some reason the board doesn't re-connect. Works only the first time around. Should I also reset BLE? Thanks!
android.os.Handler handler = new android.os.Handler();
private final Runnable sendData = new Runnable(){
public void run(){
try {
//prepare and send the data here..
i++;
Log.i("tutorial", "Doownload#:" + String.format("%d",i));
if(!mwBoard.isConnected()){
mwBoard.connect();
Log.i("tutorial", "Disconnected, try to connect");
}
if(mwBoard.isConnected()){
//download from board/upload to cloud
Log.i("tutorial", "connected ");
try {
accModule = mwBoard.getModule(Bmi160Accelerometer.class);
accModule.stop();
accModule.disableAxisSampling();
loggingModule = mwBoard.getModule(Logging.class);
loggingModule.stopLogging();
Log.i("tutorial","stop logging");
} catch (UnsupportedModuleException e) {
Log.e("tutorial", e.toString());
}
loggingModule.downloadLog(0.f, new Logging.DownloadHandler() {
@Override
public void onProgressUpdate(int nEntriesLeft, int totalEntries) {
if (nEntriesLeft == 0) {
Log.i("tutorial", "Log download complete");
}
}});
accModule.enableAxisSampling();
accModule.start();
loggingModule.startLogging(true);
Log.i("tutorial", "start logging and disconnect");
mwBoard.disconnect();
}
//------------------------------------------------------------------
handler.postDelayed(this, INTERVAL);
}
catch (Exception e) {
e.printStackTrace();
}
}
};
I am using your starter sample. Also what's the most frustrating is that the log gets wiped out if I restart the app. How do I preserve it and download first?
When MetaWearBoard.ConnectionStateHandler() is connected I download log off the board and then disconnect in "connected()" method and only connect again on every run from Runnable expecting "connected()" event to fire to start download and disconnect again. I don't understand then why this isn't working for me on every iteration. It works perfectly when I connect manually and push download button from activity fragment.
Thanks again for all your help.
Hi,
I am actually using Eric's link from above . It is not a service but scheduled task. It works great for my project. I have a dedicated Android phone that uploads data from sensor's log when it is in close proximity.
I use MQTT and Node-Red to store data into DashDB on IBM Bluemix. Then I run specific analytics and send results back as an email message using Node-Red every few hours.
Here is my post with links to code samples:
https://developer.ibm.com/answers/questions/270908/mqtt-client-cant-connect-to-my-iot-application-on.html#answer-270942
Your idea is great but it will be one expensive cap. I am replacing batteries every week and they are not cheap. Maybe you should consider making a cap for wine bottles and say "you drink TOO much"
Sorry, couldn't resist the joke.
Good luck with your project! It's a lot of fun and MbientLab guys are awesome.
Michael