0

I am trying to read both gyroscope and linear_acclerometer data in the highest sample rate on my Moto 360 . I will press a button on the handheld, which will register sensors on the watch and start loggging all the sensor data, and when I press another button, the watch will unregister these sensors and stop logging.

However, the sensor value will become a constant value sometimes. I found if I restart the watch, the sensor will start working and generate meaningful sensor value again.

Does anyone has encounter the similar problem or have some ideas on why this may happen ?

private void startSensorListeners() {
        Log.d(TAG, "startSensorListeners");
        isCollecting = true;
        //Register the motion Sensor Listener
        mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE), SENSOR_DELAY);
        mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION), SENSOR_DELAY);
}

public  void stopSensorListeners() {
         isCollecting = false;
          mSensorManager.unregisterListener(this);
    }

 public final void onSensorChanged(SensorEvent event) {
       if(!isCollecting){
           mSensorManager.unregisterListener(this, event.sensor);
           return ;
        }
    // Save sensordata into local files, I also output the values[] in event on the logcat to monitor the sensor values in the realtime.
    saveData(event);
    }

Thanks

Foreverniu
  • 349
  • 1
  • 3
  • 18
  • I believe I've encountered something similar to this, but without seeing the code it's hard to tell what exactly goes wrong. – dkarmazi Aug 07 '15 at 19:57
  • @dkarmazi Thanks for your response. I have somehow figured out a solution to this problem. You can see my answer below. I feel this is a bug of the system itself. I have used the similar sensor logger code on a phone, and it never had the similar issue before. This problem only occurred on Android watch. – Foreverniu Aug 07 '15 at 22:44
  • @dkarmazi I found the old problem happened again. What was the reason caused your problem earlier ? Thanks – Foreverniu Aug 08 '15 at 00:16
  • @dkarmazi I found once I restarted my watch, the sensor will work again. Is that possible that I did not unregister the sensor in the right way? I have put my code in the orignial post. – Foreverniu Aug 08 '15 at 00:25
  • could you please also show onSensorChanged callback – dkarmazi Aug 08 '15 at 00:48
  • multiple issues here can happen: first, what exactly do you do in saveData? How does it write information to local files? This callback is called very often, so whatever you do must be very performance light. It'd be best if you can share the complete code for saveData and all functions that you call from there. – dkarmazi Aug 08 '15 at 00:59

1 Answers1

1

I don't have an actual answer for this. I'm just sharing my problem because I feel like they are very similar. The problem occurs on a Moto 360 and was not tested on another device.

I use the Magnetic sensor.

mMagneticSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);

I register my Fragment as a listener to new values.

mSensorManager.registerListener(this, mMagneticSensor, SensorManager.SENSOR_DELAY_NORMAL);

I was developing an application. At the beginning, they were changing as expected but, after ~an hour, the values from the sensor just froze, remaining exactly the same no matter what.

I suspect two things: battery level and data rate renewal.

Maybe the battery dropped below some acceptable level (was around 25% when it stopped working)... it would be weird but it would not a big surprise.

Secondly, I remember having changed SensorManager.SENSOR_DELAY_NORMAL) to SensorManager.SENSOR_DELAY_UI) at some point, not long before the values froze. Perhaps it's a coincidence. The SensorManager.SENSOR_DELAY_UI is a faster data rate renewal than SensorManager.SENSOR_DELAY_NORMAL and as I was modifying a bitmap each time I got a new value. Maybe a buffer was full and wasn't emptied...maybe

Anyway, if I got some news on this subject I will update this post.

Gordak
  • 2,060
  • 22
  • 32
  • Thanks for sharing your experience. I found I can always solve this problem by restarting the watch. And I agree the battery level is one thing I suspected . – Foreverniu Sep 19 '15 at 20:32
  • I let the application run for a few hours just to see what would happen. I started at battery level 100% and stopped near 5%. I tried both data renewal rates (NORMAL and UI) and the values never froze. So maybe it's related to one of the development procedures. – Gordak Sep 23 '15 at 06:53
  • I suspect one possible reason is that if you sample the data too fast, and the watch start heating, then the data may froze. I am still having the same issue here. – Foreverniu Sep 24 '15 at 06:14
  • Did you ever find the cause of this? Im having similar problems with my moto360 sensors freezing after I replace fragments a bunch of times, and restarting the watch makes them work again. – Highway62 Feb 01 '16 at 19:17
  • I have not been working on this for a while now. I think it happened to me only twice. There is an important update of the firmware to do on the moto 360. The factory firmware was just very bad at the beginning. Try to update it and it might just solve your problem. https://motorola-global-portal.custhelp.com/app/answers/prod_answer_detail/a_id/107206/p/2815,9141 – Gordak Feb 02 '16 at 10:26