Widget - Access to sensor

Hye everyone,

I would like to have access to sensor in a widget,

So far I've get the Heading and the Elevation easily (from internal one)

but I cannot get pressure and temperature (like other widgets do).

here is my code:

function onShow() {
timer = new Timer.Timer();
timer.start(method(:timerCallback), 250, true);

}

function timerCallback() {
Ui.requestUpdate();
}

    function onUpdate(dc) {

var SensInfo = Sensor.getInfo();
heading = SensInfo.heading;
speed = SensInfo.speed;
alt = SensInfo.altitude;
press = SensInfo.pressure;
temp = SensInfo.temperature;

}

Do I need to use SensorHistory?

I can't use direct Sensor Data on Widget?

Many thanks.

Ps I either tried:

Sensor.setEnabledSensors([Sensor.SENSOR_TEMPERATURE]);
Sensor.enableSensorEvents( method(:onSnsr) );

  • Sensor is generally used to connect to an external sensor, so for non-Edge devices, SENSOR_TEMPERATURE is used if you want to connect to a Tempe.  You probably are looking for the internal temperature sensor, and in that case you use SensorHistory.getTemperatureHistory() and use the newest sample.

    For pressure, you can use SensorHistory.getPressureHistory(), but you can also see pressure (in different forms) from Acityity.getActivityInfo()

    Note for both of these, the data is only available if the device has a baro altimeter

    BTW, what you can do is use

    Sensor.enableSensorEvents( method(:onSnsr) );

    And probably skip the timer, as it will be called regularly.

  • Many thanks. 

    It work well now, 

    I. Have a small ttouble with speed which I get from gps, it is always changing,

    Starts At good speed and increase again and again about 3 ot 4 times ans go back to good one. 

    For exemple (in kmh)

    135 to 477 to 1217 to 6336 to ans go bac to 135.

  • You're starting GPS in the widget?  Are you checking the accuracy?

    You may want to ignore things that don't indicate a good fix.

    Also, when you are standing still, there is some fluctuation in GPS, which will indicate a non-zero speed.

    Are your numbers really kmh or meters/hour?

  • hye Jim, yes I start it on continous mode, No I don't check the accuracy, I'm gonna do that,

    there is a kind of loop in sim and real watch, but only for the speed, for altitude, loop on sim but stable on watch.

    yes my number is km/h, when I send it I twas testing my widget on car.(don't worry I'm not the driver ;) )