Access to the internal barometer

Former Member
Former Member
Is there any way to access the internal barometer yet? I could not find something in the documentary. Thank you and best wishes from Germany!
  • Former Member
    Former Member over 10 years ago
    Pressure is currently available from the Sensor module.
  • It looks like you can write...

    var status = Sensor.getInfo();

    var temp = status.temperature;
    var pressure = status.pressure;
  • I want to use the pressure input for a datafield, and tried your code in the following code:

    //!----- Code start --------------------------------------------------------------------------
    using Toybox.WatchUi as Ui;
    using Toybox.Application as App;
    using Toybox.System as Sys;
    using Toybox.Sensor as Snsr;
    using Toybox.Time as Time;


    //!SimpleDataField
    class DataField extends Ui.SimpleDataField
    {
    //! Constructor
    function initialize()
    {
    label = "Pressure";
    }

    //! Handle the update event
    function compute(info)
    {
    var status = Sensor.getInfo();
    var Pressure = status.pressure;

    return Pressure;
    }
    }

    //! main is the primary start point for a Monkeybrains application
    class SimpleDataField extends App.AppBase
    {
    function onStart()
    {
    return false;
    }

    function getInitialView()
    {
    return [new DataField()];
    }

    function onStop()
    {
    return false;
    }
    }
    //!----- Code end --------------------------------------------------------------------------

    When compiling the above code I get this error message:
    BUILD: com.garmin.monkeybrains.asm.AssemblerException: Unable to resolve entry class. Check the manifest file.

    I guess it is because acces to the sensor API is not allowed for datafields..?

    How do I get pressure data for use on data fields?
  • Former Member
    Former Member over 10 years ago
    When compiling the above code I get this error message:
    BUILD: com.garmin.monkeybrains.asm.AssemblerException: Unable to resolve entry class. Check the manifest file.


    This error message means the value for the "entry" attribute in the <iq:application> tag in your manifest file is wrong. Based on the code you posted you'll want that value to be "SimpleDataField".
  • The error you are getting is because the name of the entry point specified in the manifest file (manifest.xml) is not equal to the name of a class in your application. In this case, the entry point class name should be set to SimpleDataField.

    Once you work that out, you'll run into the problem with the Sensor module only being available to apps and widgets. There isn't currently any way to get barometer data in a data field.

    Travis
  • Thanks for the tip on the manifest file. :o)

    I'm now able to build the project, but it doesn't Work on my Watch. I guess its because I dont have acces to the sensor API for data fields... a bit anoying...
    But I guess I'm able to use the "activity.info.altitude" instead...
  • Hi Again

    I've now used the following function to get barometric pressure in mbar, based on the altitude data, for making a datafield:

    //! ------ code begin -----
    //!SimpleDataField
    class DataField extends Ui.SimpleDataField
    {

    //! Constructor
    function initialize()
    {
    }

    //! Handle the update event
    function compute(info)
    {
    var Pressure = null;
    var AltEQ = null;
    var Calc = null;

    //! Pressure calculated from a formula found on wikipedia and
    //! rearranged in the following form:
    //! Pressure[mBar] = ((1-HeightInMeters/a)^b)*c
    //! Where:
    //! a = 44307.69 (Different value needed for imperial mode)
    //! b = 5.255303
    //! c = 1013.25

    if( info.altitude != null )
    {
    AltEQ = info.altitude;
    Calc = 1 - AltEQ/44307.69;

    AltEQ = Math.pow(Calc , 5.255303);
    Pressure = AltEQ * 1013.25;
    }
    return Pressure;
    }
    }
    //! ----- Code end -----

    It works and I've used this for a Depth gauge that I'll describe in a another thread