Simulate Heart Rate Sensor: null value.

Former Member
Former Member
Hello,

I'm trying to use the simulator to generate fake data for the Heart Rate sensor. The problem is that sensorInfo is still null. Also i would like to know where the .FIT file is generated.

Here is my code:

function onShow() {
Sensor.setEnabledSensors( [Sensor.SENSOR_HEARTRATE] );
Sensor.enableSensorEvents( method(nSensor) );
}

function onSensor(sensorInfo)
{
if (!sensorInfo){
System.println("No data");
}else{
if (currentValue != sensorInfo.heartRate){
currentValue = sensorInfo.heartRate;
}
}
WatchUi.requestUpdate();
}


Thanks you!
  • The code above doesn't simulate a heart rate sensor, it attempts to read heart rate data from a sensor. These things are very different. If you are just trying to get access to the data from the simulator, you don't need to establish a connection to the sensor at all.

    Here is a quote from my response to your post over in the Garmin Developer Information forum.

    This appears to be a ConnectIQ question. If you have questions about ConnectIQ, you should probably post to the ConnectIQ forum area here.

    When you are in the simulator, you can click Simulate > FIT Data > Simulate Data to generate fake data. You can replay a .FIT file in the simulator by clicking Simulate > Playback File.... While most fit files would work, the playback functionality works best if the file was recorded using 1 second recording mode.

    I wrote a quick test, and I can verify that the object returned by Sensor.getInfo() is not null when run under the simulator with generated data or with data playback. Here is a capture from the simulated data...

    altitude: 5116.690430
    cadence: 174
    heartRate: 114
    power: 172
    pressure: 39924.617188
    speed: 8.052387
    temperature: null


    Travis


    If you are implementing a data field, the compute() method is called once a second with data generated (or being played back) by the simulator. If you are writing an app or widget, you can simply call Sensor.getInfo() to access the sensor data that is already handled by the device. You don't need to call setEnabledSensors() or enableSensorEvents(). As an example...

    // in your view class...
    function onUpdate(dc) {
    var s = Sensor.getInfo();
    if (s != null) {
    // we got sensor data

    if (s.heartRate != null) {
    // we got heart rate data

    Sys.println(s.heartRate);
    }
    }
    }


    If you really do want to establish a connection to a physical sensor from the simulator, I believe you'll need an ANT+ stick connected to your computer. I do not believe that the simulator captures FIT file data. If you want to provide a FIT file to the simulator, you'll have to generate one (possibly using your Garmin device) or download one (possibly from Garmin Connect).

    Travis
  • Former Member
    Former Member over 10 years ago
    Thanks. Very good explanation!