makeRequest does not call method(:onReceive) in background / WF

Hi !

i've a problem i can't deal with (as a newbie!)

In a watchFace, i put a background Service to call a Financial web service API (would be the same for weather API).

The BF is ok, makeRequest call the webservice, i have my info in the simu / file -> View HTTP Traffic.

But after the request, onreceive function isn't called.

Andy Idea ?

(i put Sys.println almost everywhere…  !)

thanks !

Marco

PS:

time simulation speeding Don't  have any impact on background time services?

I set time simu to x100 faster, but obliged to wait for 5mn !

(

testing target MK1

Photon 4.8.0

SDK 3.1.6

)

  • Here's a trick I use in background processes that do comm.

    In the callback for makeWebRequest, if the status is 200, I return the data, but if it isn't 200, I return the status.  Like this:

    		function receiveWeather(responseCode, data) {
    			if(responseCode==200) {Background.exit(data);}
    			else {Background.exit(responseCode);}
    		}

    Then in onBackgroundData(data), 

    With

    if(data instanceof Number) {

    you can see if you got data or an error, and in the case of an error, you can display it.  It really helps when looking at comm issues, as I have the comm status as an option for data fields in my watch faces.  If comm isn't working, you can see why.

  • thanks.I'll take it !

    I'm parsing the data yet…

    getting Something like :

    { "Global Quote": { "01. symbol": "MSFT", "02. open": "148.9300", "03. high": "149.9900", "04. low": "148.2700", "05. price": "149.9700", "06. volume": "21475451", "07. latest trading day": "2019-11-15", "08. previous close": "148.0600", "09. change": "1.9100", "10. change percent": "1.2900%" } }

    Version 1 of my WF is mainly for technical dev purpose, so lot of job/var hardcoded

    V2 i will optimize it (or try to!)

    V3 will probably be with users options setup...  so if i can already put some code in this way ;-)

    even if it's a strange WF, as said it's mainly for developping purpose (BG, webrequest, phone cnx, icons, fonts, circles, etc)

    ... I'll add weather, msg/alarm ...

    still some work to do !

    ;-)

  • The callback is the way you see when data has been obtained, and it could take some time for that (seconds.

    The background isn't blocked until that happens.  That's my you have to do the Background.exit() in the callback.

  • thanks.

    Something like externals methods (like phone connex http etc) are themselves "system" BG process ?

  • Not sure of the question, but when a makeWebRequest is done, the reason you specify a call back, is so that when the request is done and there's data or an error, you're callback runs to handle that.

    CIQ does not block on the makeWebRequest, your callback is the way to see when it completes.

  • Hi,

    since you are talking about MakeWebRequest and don't want to flood with an other thread, I have please an extra question,

    Is it possible to do 2 MakeWebRequest at the same time?

    if yes, how to deal with the 2 differents :OnReceive since after receiving data the Background is closed with Bg.Exit?

    Have a great day

  • You can have 3 outstanding makeWebRequests at the same time, but in the past, there was an issue when having 3 with android.  So, what I do is chain them.  Do request 1, and in it's callback, do request 2 if there's no error, and in the callback for request 2 return the data from both.

    I do that to get weather from two different locations for example.

  • oh ok so I put this on the 2nd request

    Bg.exit({
    			"OWMF" => resultF,
    			"OWMC" => result
    });

    and remove the Bg.exit from the first, right?

  • I use bg.exit() in the first if there is an error and don't do the second, but yes, in general, I return the data from the 1st and 2nd in the 2nd..