What to do with these ERA reports?

So in my ERA I get these reports for example the following it says Invalid Value

Im getting a an iterator then I'm getting the next value and I do checks on the value and then set the text of a label. It gives me error invalid value on the setText part of the label.

I don't know what I could do more to check if its correct or not? I wish ERA would report the actual value that was given or something. 

var sensorIter = getIterator();

var lastvalue = sensorIter.next();

if (lastvalue != null &&
    lastvalue has :data &&
    lastvalue.data != null &&
    (lastvalue.data instanceof Number ||
    lastvalue.data instanceof Float ||
    lastvalue.data instanceof Long ||
    lastvalue.data instanceof Double)) {
          
        hpadifference.setText(lastvalue.data.toNumber().toString());
}

  • so

    1. getRegisteredSensors() is from 3.2

    2. lastvalue is type of Sensor.SensorInfo and its data is a dictionary

    What do you want to fetch? ble/ant id? What do you expect in data? Value from sensor?

  • Yes

    its all working on my watch and in the simulator and most other peoples watches too. Just once a while I'll just see this error pop up in ERA

  • What do you want to fetch? ble/ant id? What do you expect in data? Value from sensor?

  • var lastvalue = sensorIter.next();

    lastvalue.data 

    Yes value from the sensor. Like I said it works fine. But sometimes ERA reports invalid value. 

  • show getIterator(), I think you use sensor history not sensor

  •  function getIterator() {
        // Check device for SensorHistory compatibility
        if (AppSettingscharttype == 1) {
          if (
            Toybox has :SensorHistory &&
            Toybox.SensorHistory has :getHeartRateHistory
          ) {
            return Toybox.SensorHistory.getHeartRateHistory({
              :period => new Time.Duration(3600),
            });
          } else {
            return null;
          }
        } else if (AppSettingscharttype == 2) {
          if (
            Toybox has :SensorHistory &&
            Toybox.SensorHistory has :getOxygenSaturationHistory
          ) {
            return Toybox.SensorHistory.getOxygenSaturationHistory({
              :period => new Time.Duration(3600),
            });
          } else {
            return null;
          }
        } else if (AppSettingscharttype == 3) {
          if (
            Toybox has :SensorHistory &&
            Toybox.SensorHistory has :getStressHistory
          ) {
            return Toybox.SensorHistory.getStressHistory({
              :period => new Time.Duration(7200),
            });
          } else {
            return null;
          }
        } else if (AppSettingscharttype == 4) {
          if (
            Toybox has :SensorHistory &&
            Toybox.SensorHistory has :getBodyBatteryHistory
          ) {
            return Toybox.SensorHistory.getBodyBatteryHistory({
              :period => new Time.Duration(43200),
            });
          } else {
            return null;
          }
        } else if (AppSettingscharttype == 5) {
          if (
            Toybox has :SensorHistory &&
            Toybox.SensorHistory has :getTemperatureHistory
          ) {
            return Toybox.SensorHistory.getTemperatureHistory({
              :period => new Time.Duration(3600),
            });
          } else {
            return null;
          }
        } else if (AppSettingscharttype == 6) {
          if (
            Toybox has :SensorHistory &&
            Toybox.SensorHistory has :getElevationHistory
          ) {
            return Toybox.SensorHistory.getElevationHistory({
              :period => new Time.Duration(3600),
            });
          } else {
            return null;
          }
        } else {
          if (
            Toybox has :SensorHistory &&
            Toybox.SensorHistory has :getPressureHistory
          ) {
            return Toybox.SensorHistory.getPressureHistory({
              :period => new Time.Duration(7200),
              :order => SensorHistory.ORDER_NEWEST_FIRST,
            });
          } else {
            return null;
          }
        }
      }
    }

    To be honest the problem is not with what comes out of this tho. Because lastvalue could be whatever. It's after all the checks I do on lastvalue that it still ERA's on invalid value, but on the part I do after all the checking. 

  • Even if I just hard type

    lastvalue = null;  or lastvalue = "fsdfsdf"

    It still works fine. So I don't know why some watches ERA on the .setText(lastvalue) part. 

  • so your code crash because you don't check if sensorIter is null

  • No it's not full code

    I do

     var sensorIter = getIterator();
        if (sensorIter) {
  • The problem is really that it crashes on

    setText
    It gives me exactly this line in ERA
    Invalid value, but I do every check possible to make sure it has a value.