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

)

  • What are you seeing as the entrie dictionare.  I'll make an assumpter here based on what you posted, but

    var price=data["Global Quote"][ "01. symbol"];

    could do it (you'll probably what to have things like 

    if(data!=null && data["Global Quote"]!=null)

    someplace.

  • i'm sorry my post disappeared with some "garmin forum error please contact admin etc"  !

    So here is the dictionary:

     data={Global Quote=>{02. open=>150.0700, 05. price=>150.3400, 10. change percent=>0.2467%, 04. low=>148.9800, 01. symbol=>MSFT, 09. change=>0.3700, 03. high=>150.5500, 06. volume=>21489795, 07. latest trading day=>2019-11-18, 08. previous close=>149.9700}}

    I indeed have somthing like data["Global Quote"] since i have to test either  some error message (data["Error message"] s from a stock mispelling, apikey error and so on).

    Thanks, Very much !  i'll test the direct access key

    var price=data["Global Quote"][ "05. price"];

    it should work.

    Any idea of the order changes? (just for my own culture ;-)  ).

    =>

    i put again the text content of the HTTP Traffic for the returning GET :

    181\r\n{\n    "Global Quote": {\n        "01. symbol": "MSFT",\n        "02. open": "150.0700",\n        "03. high": "150.5500",\n        "04. low": "148.9800",\n        "05. price": "150.3400",\n        "06. volume": "21528020",\n        "07. latest trading day": "2019-11-18",\n        "08. previous close": "149.9700",\n        "09. change": "0.3700",\n        "10. change percent": "0.2467%"\n    }\n}\r\n

  • The order change is common.  When you see the data it may be in any order, so that's why you want to use keys. You can't code based on the order.

  • fantastic thread! thanks for the incredible insights into this topic. will be using this soon.

  • ---- i just remember data coming from onReceive are not in the same order than the http  !! ----

    Thanks to Jim,( and the Shent's question)  i get all my data's back from 2 makeWebRequest. in BG !

    (the 1st onReceive1 calling the 2nd makeWebrequest and exit in this 2nd onReceive2).

    I'm dealing with response code and datas in onbackgrounddata, putting

    dataFromWebRequest = {    
                            "dataStock"     => dataFromWebRequestStock,
                            "dataWeather"    => dataFromWebRequestWeather
                        };

    in the bg.exit(dataFromWebRequest );

    Thanks again :)

  • dataFromWebRequest = {    
                            "dataStock"     => dataFromWebRequestStock,
                            "dataWeather"    => dataFromWebRequestWeather
                        };

    you could also just do 

    datafromWebRequest =[datafromWebRequesrStock,dataFromWebRequestWeather];

    and with an array, data[0] would be stock, data[1] would be weather.  A bit simpler (and smaller) when passed to the main app

  • thanks. i'm trying this way asap.

    I'm now  trying to get the weather icon from - still in BG - from web.

    In BG i can't get the palette so i try without.

    I get something in http traffic view, but no way to drawbitmap of it.

    I know it may be better to use weather font icon (i have one) but i'd like to test makeImageRequest in BG.

    Is there any way to get it ? I put the onReceive(data) in a global var to use it in my wiew.

    instanceof WatchUi.BitmapResource is false... and can't test BitmapResource in onreceive / BG...

    thanks

    (

    i'm quite confusing - little bit boring - with lanching my app on my watch and having trouble with symbol etc

    i tried global var, OS, local...float, double...user settings... only hard coded lat long seems to work now (it was ok some time ago!)

    ->Line 43 :  var locs = Activity.getActivityInfo().currentLocation.toDegrees();

    Error: Unexpected Type Error
    Details: 'Failed invoking <symbol>'
    Time: 2019-11-22T09:26:22Z
    Part-Number: 006-B2859-00
    Firmware-Version: '8.00'
    Language-Code: fre
    ConnectIQ-Version: 3.1.6
    Filename: 3488488C
    Appname: CubeWatch

    GCM Android

    (MK1)

    i'll create n new thread maybe, later)

    )

  • below is what i receive from http... maybe something to do with all this ?

    \x89PNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00\x00\x002\x00\x00\x002\x08\x06\x00\x00\x00\x1E?\x88\xB1\x00\x00\x00\tpHYs\x00\x00\x0B\x13\x00\x00\x0B\x13\x01\x00\x9A\x9C\x18\x00\x00\x05LiTXtXML:com.adobe.xmp\x00\x00\x00\x00\x00<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 5.1.2">\n   <rdf:RDF xmlns:rdf="">www.w3.org/.../22-rdf-syntax-ns <rdf:Description rdf:about=""\n            xmlns:xmp="">ns.adobe.com/.../">\n         <xmp:ModifyDate>2012-07-27T13:07:95</xmp:ModifyDate>\n         <xmp:CreatorTool>Pixelmator 2.0.5</xmp:CreatorTool>\n      </rdf:Description>\n      <rdf:Description rdf:about=""\n            xmlns:tiff="">ns.adobe.com/.../">\n         <tiff:Orientation>1</tiff:Orientation>\n         <tiff:YResolution>72</tiff:YResolution>\n         <tiff:Compression>5</tiff:Compression>\n         <tiff:ResolutionUnit>1</tiff:ResolutionUnit>\n         <tiff:XResolution>72</tiff:XResolution>\n      </rdf:Description>\n      <rdf:Description rdf:about=""\n            xmlns:exif="">ns.adobe.com/.../">\n         <exif:PixelXDimension>50</exif:PixelXDimension>\n         <exif:ColorSpace>65535</exif:ColorSpace>\n         <exif:PixelYDimension>50</exif:PixelYDimension>\n      </rdf:Description>\n      <rdf:Description rdf:about=""\n            xmlns:dc="">purl.org/.../">\n         <dc:rights>\n            <rdf:Alt>\n               <rdf:li xml:lang="x-default">(c) Roberto1977 | Dreamstime.com</rdf:li>\n            </rdf:Alt>\n         </dc:rights>\n      </rdf:Description>\n   </rdf:RDF>\n</x:xmpmeta>\n\x16'\x1F:\x00\x00\x05/IDATh\x05\xEDW]Hde\x18\xFE\xE6\xEF\xCC\x8C\xAB;\xBA\xF8\x13\n#\xB2\x84\x83I\xAE\xEDE\x91d\xE9\x8AA\nE7\xA9$A\xAC4\x08\xEB\x85\xADW^I\x94\xC1.a4\x88\x9A?\x19A\x17Y\xBA\x17\xD1B)!\x1B+\xA1\x12\xA1\x16j\x927\x19\x8E\x8E?\xE3\xE88\x7F\xA7\xE7=\xEDa\x0F6g\xE6\xCCY\x8F\x1Br>\xF8\xF8\xCE\x9C\xEF\xFD\xDE\xF7}\x9E\xF7\xE7;c

    and so on with D4b@O-\x8D\x88 etc etc

  • You want to null check Activity.Info.currentLocation, as the way you are doing it, there will be a crash if that's null.  Being null is common.

    The way you want to do this is get the location in your main app, and if it's not null, put it in storage and have your backgrouund get it from storage.  That way if Activity.Info.currentLocation is null, you have the last good location available.