Edge IQ! when suspend device

Hi everyone,
I am developing a datafield for Edge 530 and 830; Basically it is to be able to use more than the 10 maximum fields.
In addition to the fields that CIQ exposes, I calculate others such as Normalized Power, TSS, etc ...

I am not a developer and I am very new to all this; every step is costing me a lot.

It seems that the fields were starting to work but I discovered a bug. I had a mechanical breakdown on the bike and stopped to fix it. When I finished my Edge 830 it had turned off and when I turned it on I received an IQ from my datafield!

Looking in the forum I see that it may be a problem with the loss of variables and now when I do a timerStop I store 6 variables. In the onstop clear the variables and in onStart I feed the variables with the stored keys.

But I keep getting the IQ! Message. It's a problem because to reproduce the error I have to pass the .prg file and wait for the Edge to shut down after stopping it.

The error I get is:


Stack:
- pc: 0x100021e1 -> 268444129 (decimal)
- pc: 0x10001709 -> 268441353 (decimal)

<entry filename="C:\\Users\\carlos_2\\OneDrive\\ECLIPSE\\POWER-MARO\\source\\POWERMARO.mc" id="39" lineNum="378" pc="268444108" symbol="compute"/>
<entry filename="C:\\Users\\carlos_2\\OneDrive\\ECLIPSE\\POWER-MARO\\source\\POWERMARO.mc" id="39" lineNum="392" pc="268444138" symbol="compute"/>

altitud = info.altitude.format("%02d");

power30 = power30s(info.currentPower);

<entry filename="C:\\Users\\carlos_2\\OneDrive\\ECLIPSE\\POWER-MARO\\source\\POWERMAROView.mc" id="19" lineNum="426" pc="268441334" symbol="compute"/>
<entry filename="C:\\Users\\carlos_2\\OneDrive\\ECLIPSE\\POWER-MARO\\source\\POWERMAROView.mc" id="19" lineNum="427" pc="268441354" symbol="compute"/>

function compute(info) {
fields.compute(info);
return 1;
}

I use these functions:

function onTimerStop(){
        Storage.setValue("KEY_elapsedTime", fields.elapsedTimer);
		Storage.setValue("KEY_lapINI", fields.lapINI);
		Storage.setValue("KEY_LAPdistINI", fields.LAPdistINI);
		Storage.setValue("KEY_power30", fields.power30);
		Storage.setValue("KEY_powerNPraw", fields.powerNPraw);
		Storage.setValue("KEY_avg_smoothed_power_4", fields.avg_smoothed_power_4);
}

---------------------------------

function onStart(app, state) {
		lapINI = Storage.getValue("KEY_lapINI");
		elapsedTimer = Storage.getValue("KEY_elapsedTime");
		LAPdistINI = Storage.getValue("KEY_LAPdistINI");
		power30 = Storage.getValue("KEY_power30");
		powerNPraw = Storage.getValue("KEY_powerNPraw");
		avg_smoothed_power_4 = Storage.getValue("KEY_avg_smoothed_power_4");
		
		
	}
	
function onStop(app, state) {
		Storage.clearValues();
		
	}

Can you give me a hand to more specifically debug the error or a vision of how not to lose the variables after the device is suspended?
I have read some post about this but they are a bit old and I can't quite fix it.


Thanks for the attention.

  • I'd say the onTimerStop / onTimerStart stuff is a red herring in this instance.

    The error message refers to the lines where you read info, so why not start with those lines?
    You don't say what the actual error you see is, just where it occurs, so I'm going out on a limb and will say it looks like you aren't null checking info's properties.

    EG: Rather than altitude = info.altitude.format("%02d"); you might do better to have a null check function and do something like this:

    function ifSet(val,ifNot) {
        return val != null ? val : ifNot;
    }

    And then:

    altitude = ifSet(info.altitude,0).format("%02d");

  • I have added that function, it seems like a very elegant way to control the variable.
    Until now I used:
               calories = info.calories! = null? info.calories: 0;
    Curiously, this was the only variable that he did not control.
    And I just tried it and it gives no IQ error!
    :) :) :)
    I am very grateful.

    Apparently he had two problems and not one.
    Now I can see that the variables that I save when I restart the device I cannot use them again ...
    Any idea how to do it?
  • I may be being obtuse, but don't you have:

    function onStop(app, state) {
    	Storage.clearValues();
    }

    Doesn't that kinda... you know... clear all the values in storage?

    Not quite sure what you're trying to achieve with Storage, and I am not aware of ever needing to use .clearValues for anything I would have used it for.

  • My intention is that when stopping the Timer, for example in a stop for coffee, it stores the data such as the normalized power.

    The device after a while suspends or shuts down.

    I don't know how to store the data stored in the corresponding variables once I turn the device back on to resume running.

    On the other hand, I add clear in onStop with the intention that the stored data will be deleted if I finish the activity so that it does not exist for the next activity.

    The truth is, I am very lost; I don't know how to deal with it.

  • I think that to store the variables with this it is enough:
    onTimerPause -> SetValue
    onTimerStop -> SetValue

    But I am not clear once the device is turned off, where to reload the variables with the stored ones. Maybe in onStart?
    And if I also have to delete them at some point.

    Maybe in onWorkoutStarted () add the deletion?
    Edge 830 accept CIQ 3.2?

  • I think I have found the way, although it may not be the most optimal way:

    onTimerPause -> SetValue
    onTimerStop -> SetValue

    initialize() --> I load the variables if they exist.

    compute() -->

    if (elapsedTimer == 0) {
    Storage.clearValues();
    }

    I guess it's not the best way but it seems to work; although if you want to start another activity after having finished the previous one, you have to restart the device.