简体   繁体   English

在 Android Wear OS(即 CSV)上保存和传输智能手表传感器数据的最佳方式是什么?

[英]What is the best way to save and transfer smartwatch sensor data on Android Wear OS (i.e. as CSV)?

I have written a Wear application for the Fossil Gen 6 smartwatch which extracts photoplethysmogram (PPG) data from an onboard sensor and updates the value on the screen continuously.我为 Fossil Gen 6 智能手表编写了一个 Wear 应用程序,它从板载传感器中提取光电体积描记 (PPG) 数据并不断更新屏幕上的值。 Here is my onSensorChanged method, which recognizes events from the PPG sensor and updates the TextView object accordingly.这是我的onSensorChanged方法,它识别来自 PPG 传感器的事件并相应地更新TextView object。 I also attempt to write each datum to a CSV file using a FileWriter object.我还尝试使用FileWriter object 将每个数据写入 CSV 文件。

@Override
    public void onSensorChanged(SensorEvent event) {

        // On event from PPG sensor, update text on screen and
        // write to CSV file.
        if (event.sensor.getType() == 65572) {
            sensorData = event.values[0];
            String dataString = Float.toString(sensorData);
            textView.setText(dataString);
            try {
                writer.write(dataString);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

The file writer is declared at the top of the MainActivity :文件编写器在MainActivity的顶部声明:

    private FileWriter writer;

And is defined in the onResume method:并在onResume方法中定义:

protected void onResume() {
        super.onResume();
        try {
            writer = new FileWriter("data.csv",true);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

What I am not sure how to do is actually have this file available to write to, whether it should be stored on the watch or on the paired phone somehow, and how I can ultimately retrieve the CSV data on my PC for analysis in MATLAB, etc. (Is there a better way to be doing this?) Thanks!我不知道该怎么做实际上是可以写入这个文件,它是否应该以某种方式存储在手表上或配对的手机上,以及我如何最终在我的 PC 上检索 CSV 数据以在 MATLAB 中进行分析,等(有没有更好的方法来做到这一点?)谢谢!

I just want to start by saying that there are many ways to do this, and what's considered the "best" approach is highly dependent on the specifics to your use case (and sometimes personal preferences).我只想首先说有很多方法可以做到这一点,而被认为是“最佳”的方法在很大程度上取决于您的用例的具体情况(有时是个人偏好)。

The most important thing to remember is that the watch has very limited resources (battery, memory, CPU) compared to a typical phone.最重要的是要记住,与典型的手机相比,手表的资源(电池、memory、CPU)非常有限。

Here are a few things to keep in mind no matter what your exact solution will look like:无论您的确切解决方案是什么样的,都需要牢记以下几点:

  1. Writing to a file is an expensive operation.写入文件是一项昂贵的操作。 Doing this for every data point you receive from a sensor is not ideal.对您从传感器接收到的每个数据点执行此操作并不理想。 Consider saving your data to a database using Room instead.考虑使用 Room将数据保存到数据库。 An easier alternative, as long as you are OK potentially losing some data if the app crashes or the device reboots unexpectedly, is to keep it in memory.如果应用程序崩溃或设备意外重启,只要您确定可能会丢失一些数据,一个更简单的替代方法是将其保存在 memory 中。 This can be done using a basic array or some sort of Map (timestamp and value) depending on exactly what data you need.这可以使用基本数组或某种 Map(时间戳和值)来完成,具体取决于您需要的数据。 You can also use a hybrid of the two approaches and save data in batches.您还可以混合使用这两种方法并批量保存数据。

  2. Sending data between the watch and the phone is also expensive.在手表和手机之间发送数据也很昂贵。 I highly suggest storing things on the watch itself and transfer it to the phone only when needed.我强烈建议将东西存放在手表本身上,并仅在需要时将其转移到手机上。 This can be a manual trigger, daily at a certain time, when the watch is charging, or some other clever strategy to minimize the impact on the watch's battery life.这可以是手动触发,每天在特定时间,当手表充电时,或其他一些巧妙的策略,以尽量减少对手表电池寿命的影响。

  3. You can send your data to the phone using the Wearable Data Layer API .您可以使用可穿戴数据层 API将数据发送到手机。 You will have to set up either a MessageClient or a ChannelClient depending on how much data you need to transfer.您必须根据需要传输的数据量来设置MessageClientChannelClient If you stick to data structures that are supported by Android (as opposed to creating your own one), sending them over should be fairly straight forward.如果您坚持使用 Android 支持的数据结构(而不是创建自己的数据结构),那么发送它们应该是相当简单的。

  4. If you need to process or format your data in order for it to be easily analyzed in MATLAB, consider doing this on the phone rather than the watch.如果您需要处理或格式化您的数据以便在 MATLAB 中轻松分析,请考虑在手机而不是手表上执行此操作。 Simpler operations on reasonably sized data sets can of course be performed directly on the watch.对合理大小的数据集进行更简单的操作当然可以直接在手表上执行。

Exactly how you decide to get the file to your computer is outside of the scope of what I'm trying to answer here.您决定如何将文件传输到您的计算机的确切方式不在我试图在这里回答的 scope 之外。 There are plenty of well-documented ways to do this.有很多有据可查的方法来做到这一点。 The easiest being to manuallytransfer it via adb .最简单的方法是通过 adb 手动传输它 This can be done directly from the watch too, so you don't even have to send data to the phone.这也可以直接在手表上完成,因此您甚至不必向手机发送数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将HashMap数据从移动设备传输到Android Wear - Transfer HashMap Data From Mobile to Android Wear Android Wear Smartwatch中的按钮 - push-button in Android Wear smartwatch 将传感器数据保存到android中的文件 - Save sensor data to file in android 生成 Swagger API 的最佳方法? 即 codegen vs swagger 编辑器(Spring Boot API) - Best way to generate Swagger API? i.e. codegen vs swagger editor (Spring Boot API) WearableRecyclerView Android Wear OS - WearableRecyclerView Android Wear OS 如何在 Android Studio 的所有页面上保存功能(即 SFX 或音乐等设置)? - How to save a feature (i.e. setting like SFX or Music) across all pages in Android Studio? Spring Data Mongo:如何仅保存日期,即不保存时间 - Spring Data Mongo: How to save only date i.e. not time 在BlackBerry上传输数据的最佳方法 - Best way to transfer data on BlackBerry 使用 Spring Security 时,在 bean 中获取当前用户名(即 SecurityContext)信息的正确方法是什么? - When using Spring Security, what is the proper way to obtain current username (i.e. SecurityContext) information in a bean? 如何在 Android 内部保存流式传感器数据? - How to save the streaming sensor data internally on Android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM