makeWebRequest

Former Member
Former Member
I am trying to download fit file into fenix 5 using makeWebRequest

function onReceive(responseCode, data) {
if (responseCode == 200) {
System.println("data loaded ok:"+data);
Background.exit(data);
} else {
System.println("data load failed:"+responseCode);
//Background.exit(null);
}
}

but the data which I got after makeWebRequest call, doesnt contain data at all. "data loaded ok:Obj: 37"
According debugger it seemed that it's only pointer to resource "data._data=Resource (0x28)"

I would like to use download fit file for navigation but how should I use data variable to force device to save fit file and show it in list of navigation files.

  • Former Member
    Former Member
    It's correct that the device will automatically parse/import/etc a fit file you download via makeWebRequest. You can still process the response code and iterator that get's passed to your callback method. For instance, you may want to exitTo() one of the courses you downloaded.
    function downloadFitFile() {
    Toybox.Communications.makeWebRequest( ... , method(:callbackMethod)); //
    }

    function callbackMethod(responseCode, data) {
    // Here the response code is the HTTP status returned from the server and the data value
    // is PersistedContent.Iterator object. See the example on how to get data from the iterator.
    }