How do we return data from sensor readings?

public static void gyroscope(MetaWearBoard metaWearBoard) {

    final GyroBmi160 gyroBmi160 = metaWearBoard.getModule(GyroBmi160.class);
    gyroBmi160.configure()
            .odr(GyroBmi160.OutputDataRate.ODR_3200_HZ)
            .range(GyroBmi160.Range.FSR_2000)
            .commit();
    '''gyroBmi160.angularVelocity().addRouteAsync(source ->
            source.stream((Subscriber) (data, env) ->
            {
                Log.i("Gyro", data.value(AngularVelocity.class).toString());
            })).continueWith((Continuation<Route, Void>) task -> {
        gyroBmi160.angularVelocity();
        gyroBmi160.start();
        return null;
    });'''

}

How can i return the '''data.value(AngularVelocity.class).toString())''' back to an object? We want to put it into an sqllite database but I am not sure how to store it. Any suggestions?

Comments

  • Don't convert the object to a string.

  • Ok so i found the downloadasync method. I was wondering how I use it. Here is my code
    view.findViewById(R.id.temp_start).setOnClickListener(new View.OnClickListener() {

    '''@Override
            public void onClick(View v) {
    
                final Logging logging = metawear.getModule(Logging.class);
    
                logging.start(true);
    
                MbientSensors.temperature(metawear);
    
                logging.stop();
    
    
                     // download log data and send 100 progress updates during the download
                        logging.downloadAsync(100, new Logging.LogDownloadUpdateHandler() {
                            @Override
                            public void receivedUpdate(long nEntriesLeft, long totalEntries) {
                                Log.i("MainActivity", "Progress Update = " + nEntriesLeft + "/" + totalEntries);
                            }
                        }).continueWithTask(new Continuation<Void, Task<Void>>() {
                            @Override
                            public Task<Void> then(Task<Void> task) throws Exception {
                                Log.i("MainActivity", "Download completed");
                                System.out.println(task.isCompleted());
                                System.out.println(task);
                                task.getResult();
    
                                return task;
                            }
    
                        });'''
    

    When I try to do anything I either get null or bolts.task. I was wondering how to parse it or make it into something usable. What is your suggestion?

    Thanks

  • Again, wrap your code with backticks (```) and edit your post if it the text does not render correctly.

    I'm confused as to what you are asking now. First, you use code for streaming, now you are bringing logging code. Which one are you using?

  • Well i am trying to find the easiest way to download the data from the sensor and put it into a database. I am not sure how to get the data and put it there. I'm sorry about 2 different code blocks. My question would be how can i use the data from the logger after it is downloaded? I know it is put into a task object. How can I access the data in that task object?

  • Data handling is setup with routes:
    https://mbientlab.com/androiddocs/3/data_route.html#handling-data

    The sample code prints it to Logcat, so adapt it to do what you want to do with the data.

Sign In or Register to comment.