DataField Temporal webrequest returns -101

I have a datafield based off of the simpledatafield example to which I have added a background class and temporal event to perform a webrequest.

The webpage is working, the sim traffic logs show the result but the response code is -101. PrintIn shows the web call only happens once so doesnt seem to be an issue with flooding the requests.

anyone have any ideas as to what could be going wrong?

  • -101 is "Too many requests have been made."

    Are you use you are only making 1 request at at time?  Based on Android or iOS, the Garmin device may only allow one at a time.

  • positive, and this is all via the Simulator with direct access. The Http Traffic logs show only 1 call (which works) and the PrinIn only shows once

    Background.mc

    using Toybox.Background;
    using Toybox.System ;
    
    // The Service Delegate is the main entry point for background processes
    // our onTemporalEvent() method will get run each time our periodic event
    // is triggered by the system.
    
    (:background)
    class BgbgServiceDelegate extends Toybox.System.ServiceDelegate {
    	
    	function initialize() {
    		System.ServiceDelegate.initialize();
    //		inBackground=true;				//trick for onExit()
    	}
    	
        function onTemporalEvent() {
        	var now=System.getClockTime();
        	var ts=now.hour+":"+now.min.format("%02d");
            System.println("bg exit: "+ts);
            //just return the timestamp
            $.makeDFwebRequest(null);
            Background.exit(ts);
        }
        
    
    }

  • (:background)
    
    function makeDFwebRequest(callBack) {
    //debug	p("setting headers for makewebcall");
    	var options = {
    		:method => Comms.HTTP_REQUEST_METHOD_GET,
    		:headers => {"Content-Type" => Comms.REQUEST_CONTENT_TYPE_JSON},
    		:responseType => Comms.HTTP_RESPONSE_CONTENT_TYPE_JSON
    		
    	};
    		
    		var URL = "https://<!website url removed>";
    		var loc = $.getLocation();
    	
    	if (loc != null) {
    		var params = {
    		
    			"la" => loc[0],
    			"lo" => loc[1],
    
    		};Sys.println("web params" + params);
    	Comms.makeWebRequest(URL, params, options, (callBack == null ? new Lang.Method($, :onReceiveDFBackground) : callBack));
    
    
    	}
    }
    
    (:background)
    function onReceiveDFBackground(responseCode as Number, data as Dictionary?) {
    //$.p("onReceiveDFBackground: " + responseCode.format("%.0f"));
    	$.DFData(responseCode, data);
    	//	Bg.exit($.DFData(responseCode, data));
    }
    
    (:background)
    function DFData(responseCode as Number, data as Dictionary?) {
    	var result;
    	
    //debug		$.p(responseCode);
    	if (responseCode == 200) {	
    		result = [responseCode,
    			data["location"]];
    	
    	// HTTP error
    	} else {
    		result = [responseCode];
    	Sys.println("web call response: " + responseCode);
    	}
    		
    	return result;
    
    }
    

  • SimpleDataFiledApp.mc

    //
    // Copyright 2016-2021 by Garmin Ltd. or its subsidiaries.
    // Subject to Garmin SDK License Agreement and Wearables
    // Application Developer Agreement.
    //
    
    import Toybox.Application;
    import Toybox.Lang;
    import Toybox.WatchUi;
    using Toybox.System ;
    using Toybox.Time;
    
    
    //! This app is a simple data field that alternates
    //! between showing heart rate, distance and total time.
    //! It also uses the data field settings and alerts.
    class SimpleDataField extends Application.AppBase {
    
        //! Constructor
        public function initialize() {
            AppBase.initialize();
        }
    
        //! Handle app startup
        //! @param state Startup arguments
        public function onStart(state as Dictionary?) as Void {
        }
    
        //! Handle app shutdown
        //! @param state Shutdown arguments
        public function onStop(state as Dictionary?) as Void {
        }
    
        //! Return the initial view for the app
        //! @return Array [View]
        public function getInitialView() as Array<Views or InputDelegates>? {
            return [new $.DataField()] as Array<Views>;
               	System.println("App.getInitialView");
        	
        	// 5 minutes from now
        	var eventTime = Time.now().add(new Time.Duration(300));
        	
        	//Background.registerForTemporalEvent(eventTime);
        }
    
        //! Return the settings view and delegate for the app
        //! @return Array Pair [View, Delegate]
        public function getSettingsView() as Array<Views or InputDelegates>? {
            return [new $.DataFieldSettingsView(), new $.DataFieldSettingsDelegate()] as Array<Views or InputDelegates>;
        }
    
         function getServiceDelegate(){
        	var now=System.getClockTime();
        	var ts=now.hour+":"+now.min.format("%02d");    
        	System.println("getServiceDelegate: "+ts);
            return [new BgbgServiceDelegate()];
        }
        
        function onAppInstall() {
        	System.println("onAppInstall");
        }
    }
    

  • You shouldn't do the Background.exit() on line 22.  With the makeWebRequest, the Background.exit(() should only be don in the callback for the request

  • even without that the respnse is still -101 with only 1 call.

  • Did you comment out the Background.exit() on line 22?

  • I did, Which I swear I had done before but that seemed to do the trick. Now instead of the -101 I have -402 and then a -403 so thank you Jim.

    Now I just need to figure out if I can make the payload small enough to be worth the bother of the datafield 

    Leaving this link here just to help in the future

    https://developer.garmin.com/connect-iq/api-docs/Toybox/Communications.html

  • The Background.exit() you had at line 22 right after you did the makeWebRequest() was terminating the background service before any data came back from the makeWebRequest.

  • Do you still have this working code ? I'd like to copy it and try to modify it.  I tried pasting the above code into a new project but errors abound.