Display temperature in datafield

Can someone please help me. I'm trying to get the temperature sensor reading from an edge 1030 to display on a datafield.

According to the API documentation, sensor toybox is not available with datafields and sensor history is not compatible with edge devices. However, I know you can do it because I have a datafield installed on my device that displays the temperature. I have tried reading the API documentation, but I am lost.

  • Former Member
    Former Member in reply to jim_m_58

    Thanks for your quick response,

    I added your function named onTemporalEvent() on View.mc and I added a call onUpdate(). When I compile / execute the project I am getting this message:

    Error: Permission Required
    Details: Symbol 'setEnabledSensors' not available to 'Data Field'
    Stack:
    - onTemporalEvent() at G:\GARMIN Development\GARMIN CONNECT IQ EDGE Bike\source\EDGEBikeView.mc:511 0x1000291c
    - onUpdate() at G:\GARMIN Development\GARMIN CONNECT IQ EDGE Bike\source\EDGEBikeView.mc:289 0x10000d21

    Thanks in advance,

  • That function is for  a background service, and not a view.  It was in response to what GHG23 posted.

  • Hi

    I am new to to CIQ-Development and Monkey C.

    Ive tried to get the internal temperature from my 1030 Plus in a "SimpleDataField"-Project. No luck so far :( Ive read that with CIQ 3.2 this will be much easier but Ive found no examples.

    Can someone provide a full working example for this plan (getting the temperature)? That would be great!

    Thanks
    Frank

  • It is the code for the internal sensor that I posted before here in this thread:

    var sensorIter = getIterator();
    
    fieldValue = (sensorIter != null) ? sensorIter.next().data : 0;
    fieldValue = (utempunits == false) ? fieldValue : fieldValue*1.8+32;
    
    
    function getIterator() {
        //! Check device for SensorHistory compatibility
        if ((Toybox has :SensorHistory) && (Toybox.SensorHistory has :getTemperatureHistory)) {
            return Toybox.SensorHistory.getTemperatureHistory({});
        }
        return null;
    }

    The code is for onUpdate, the function is in the same class as onUpdate. The variable utempunits is based on user input in the settings. When it is true the user wants to use Fahrenheit instead of Celcius.

    Also you need to have a permission in the manifest file:

    <iq:uses-permission id="Sensor"/>

  • Edge devices don't have SensorHistory

  • Thats exactly the problem :(

    I would like to develop a data field which could offset the internal temperature by a specific value (or an mapping table) in case the original field is inaccurate (which is the case of my device).

    Any chance this approach will be possible?

    Frank

  • The calibration itself could be an issue no matter how you get the reading.  In the case of a watch, it will vary if the watch is being worn or not, or worn over a jacket etc. For an edge, being in the sun or not will make a difference.

    And then, when recording an activity, some devices record the internal reading if there's no tempe, and you'd have to record your own data separately.  The easiest solution is to get a tempe for devices that support it

  • I am aware of that.

    The device is an edge, so Tempe is not an option (I know there is a data field with the downside of background proccessing). My 1030+ is 4 degrees off of my previuos 1030. It will be accurate enough to correct these 4 degrees.

    So, I need the temperature without going over the 5 minute background process workaround. Wonder, this is not possible...

  • In the changelog for 3.2.1 theur is this:

    • Allow data fields access to read-only Sensor module APIs.

    Which to me sounds like you don't need a background service on 3.2 devices.

  • Really? That would be awesome! Have tried it at first, but it hasn't worked unfortunatley. Or is it not available for SimpleDatafields?

    Will have a try again - should be the same implementation as for "non" data fields, right?

    Frank