webrequest ok on simulator crashes on vivoactivehr

I'm developing a simple app with time, weather info + my company stock price.
The app runs perfectly fine on the eclipse simulator but, crashes on the vivoactive HR.
The CIQ_LOG.TXT isn't very helpful. :(

I have 2 webrequest calls - one for weather + one for stock.
If I remove the stock webrequest, the app works on the vivoactive (i.e. grabs weather info from the web).
So something's amiss with this line of code to fetch stock info on the watch.
Any ideas? Or pointers to source code that works?
Thanks.

// Comm.makeWebRequest("query.yahooapis.com/.../yql, null, {}, method(:onStockReceive));
  • Are you trying to do both requests at the same time? If so, try waiting for one to complete, then do the second. In the sim they could be happening so fast there's no issue.

    How much data are you getting back? In the sim, what does it look like as far as memory on the bottom line if the simulator?
  • Here's my source code and below that, the json rsp.
    So yes, back to back webrequest calls.
    Is there a note in the API docs that says that's a NO-NO?

    // Make the web request
    function makeRequest() {
    Sys.println("Antonio - makeRequests");
    Comm.makeWebRequest("api.openweathermap.org/.../weather", {"lat" => 43.70, "lon" => -79.41, "appid" => "eaceb3c6dcff48730ddad91fe09****"}, {}, method(:onTempReceive));
    // Comm.makeWebRequest("query.yahooapis.com/.../yql, null, {}, method(:onStockReceive));
    }

    {"query":{"count":1,"created":"2016-12-29T16:24:39Z","lang":"en-GB","results":{"quote":{"symbol":"AMD","Ask":null,"AverageDailyVolume":"47605300","Bid":null,"AskRealtime":null,"BidRealtime":null,"BookValue":"0.42","Change_PercentChange":"-0.52 - -4.31%","Change":"-0.52","Commission":null,"Currency":"USD","ChangeRealtime":null,"AfterHoursChangeRealtime":null,"DividendShare":"0.00","LastTradeDate":"12/28/2016","TradeDate":null,"EarningsShare":"-0.69","ErrorIndicationreturnedforsymbolchangedinvalid":null,"EPSEstimateCurrentYear":"-0.15","EPSEstimateNextYear":"0.05","EPSEstimateNextQuarter":"-0.04","DaysLow":null,"DaysHigh":null,"YearLow":"1.75","YearHigh":"12.42","HoldingsGainPercent":null,"AnnualizedGain":null,"HoldingsGain":null,"HoldingsGainPercentRealtime":null,"HoldingsGainRealtime":null,"MoreInfo":null,"OrderBookRealtime":null,"MarketCapitalization":"10.71B","MarketCapRealtime":null,"EBITDA":"-304.00M","ChangeFromYearLow":"9.80","PercentChangeFromYearLow":"+560.00%","LastTradeRealtimeWithTime":null,"ChangePercentRealtime":null,"ChangeFromYearHigh":"-0.87","PercebtChangeFromYearHigh":"-7.00%","LastTradeWithTime":"4:00pm - <b>11.55</b>","LastTradePriceOnly":"11.55","HighLimit":null,"LowLimit":null,"DaysRange":null,"DaysRangeRealtime":null,"FiftydayMovingAverage":"9.40","TwoHundreddayMovingAverage":"7.07","ChangeFromTwoHundreddayMovingAverage":"4.48","PercentChangeFromTwoHundreddayMovingAverage":"+63.33%","ChangeFromFiftydayMovingAverage":"2.15","PercentChangeFromFiftydayMovingAverage":"+22.83%","Name":"Advanced Micro Devices, Inc.","Notes":null,"Open":null,"PreviousClose":"12.07","PricePaid":null,"ChangeinPercent":"-4.31%","PriceSales":"2.71","PriceBook":"29.01","ExDividendDate":null,"PERatio":null,"DividendPayDate":null,"PERatioRealtime":null,"PEGRatio":"0.79","PriceEPSEstimateCurrentYear":null,"PriceEPSEstimateNextYear":"231.00","Symbol":"AMD","SharesOwned":null,"ShortRatio":"1.76","LastTradeTime":"4:00pm","TickerTrend":null,"OneyrTargetPrice":"8.88","Volume":"0","HoldingsValue":null,"HoldingsValueRealtime":null,"YearRange":"1.75 - 12.42","DaysValueChange":null,"DaysValueChangeRealtime":null,"StockExchange":"NCM","DividendYield":"0.00","PercentChange":"-4.31%"}}}}
  • While we wait for the moderator to approve ...

    Yes, I have 2 back-to-back webrequest calls.
    The simulator reports 20.2/122KB.
    Copy the https ... stuff onto a new tab to see the json rsp.
  • So, I moved my stock webrequest to the onTempReceive function that processes the weather webrequest.
    Again, fine on the simulator but this time, app doesn't crash but, stock webrequest fails.
    Here's the .txt file for my app ...


    Antonio - initalizing AppBase
    Antonio - initalizing AMDView
    Antonio - initalizing AMDDelegate
    Antonio - onLayout
    Antonio - makeRequests
    Antonio - onUpdate
    Antonio - onUpdate
    Antonio - onUpdate
    Antonio - onUpdate
    Antonio - onTempReceive
    Antonio - onStockReceive
    Failed to load stocks
    Error: 400
    Antonio - onMasterTimer
    Antonio - onUpdate
    Antonio - onMasterTimer
    Antonio - onUpdate
  • The CIQ_LOG.TXT isn't very helpful. :(

    You might not think it is useful, but it might be a good idea to post it. Someone else may understand what it means.

    So something's amiss with this line of code to fetch stock info on the watch.
    Comm.makeWebRequest("query.yahooapis.com/.../yql,
    null, {}, method(:onStockReceive));



    I think you should be passing the request parameters (the ones that you're including in the URL after the '?') as parameters to the function via the params parameter. I'm not sure, but I think that the call will attempt to encode the URL for you, and you're already encoding it. If you pass the parameters in params they will be encoded for you. If you change the method (from GET to POST) the parameters will be sent in the right place and still be encoded properly.

    var url = "query.yahooapis.com/.../yql";

    var options = {
    :method => Comm.HTTP_REQUEST_METHOD_GET,
    :responseType => Comm.HTTP_RESPONSE_CONTENT_TYPE_JSON
    };

    var params = {
    "q" => "select * from yahoo.finance.quotes where symbol in (\"AMD\")",
    "format" => "json",
    "env" => "store://datatables.org/alltableswithkeys"
    };

    Comm.makeWebRequest(url, params, options, method(:onStockReceive));


    Or pointers to source code that works?

    The source code in this post should work. It doesn't make a call to the yahoo web service API, but it does work.
  • What is the peak value for memory? The number you posted are the idle and max available.

    In general doing two at the same time may not be a problem, doing them serially could help you see what's happening. What's the size of the weather data? I see the stock data.

    When you side load your app if you create a file called <your app name>.txt in the apps/logs directory, you can use Sys.println() to save things for debugging, so that could also help.
  • Here's my source code and below that, the json rsp.

    I'm not really clear about the problem. If you make just the weather request, that succeeds. If you make both the weather and stock request, that fails. But what if you make just the stock request? Does that fail?

    Is there a note in the API docs that says that's a NO-NO?

    I believe there was some documentation about this, but I can't seem to find it. There is a limit of 3 outstanding requests on devices I've tested with. You're only doing 2, so that should not be a problem. I can't remember what the failure mode was (it may have thrown an exception or it may have just failed with BLE_QUEUE_FULL).

    If you want to avoid problems, you could chain the requests... Just move the makeWebRequest() for the yahoo address to the end of your onTempResponse() method. You might want something more robust than this for production, but it should be good enough for testing.
  • I put both versions of the webrequest call (my original one and the one suggested by Travis) in my source code (see way down below). The makeStockRequest call is made after the onTempReceive call (which processes the makeWeatherRequest call).
    I uncomment one or the other.

    If I use his, the simulator console logs report (and only weather info appears)...
    Antonio - initalizing AMDDelegate
    Antonio - onLayout
    Antonio - makeWeatherRequest
    Antonio - onUpdate
    Antonio - onTempReceive
    Antonio - makeStockRequest
    Using Travis's webrequest call
    Antonio - onStockReceive
    Failed to load stocks
    Error: -400
    Antonio - onMasterTimer
    Antonio - onUpdate
    Complete

    On the vivoactive itself, I see the following for AMD.txt and CIQ_LOG.txt
    Antonio - initalizing AppBase
    Antonio - initalizing AMDView
    Antonio - initalizing AMDDelegate
    Antonio - onLayout
    Antonio - makeWeatherRequest
    Antonio - onUpdate
    Antonio - onUpdate
    Antonio - onUpdate
    Antonio - onUpdate
    Antonio - onTempReceive
    Antonio - makeStockRequest
    Using Travis's webrequest call

    ERROR: Unexpected Type Error
    DETAILS: Failed invoking <symbol>
    STORE_ID: 00000000000000000000000000000000
    CALLSTACK:
    d:\Git_Projects\shift_production\TVM\api\Communications.mb (makeWebRequest:197)
    C:\Users\antonio\Documents\GitHub\Garmin\AMD\source\AMDView.mc (makeStockRequest:147)
    C:\Users\antonio\Documents\GitHub\Garmin\AMD\source\AMDView.mc (onTempReceive:100)

    WARNING: failed inside handle_json_callback
    STORE_ID: 00000000000000000000000000000000

    Whereas, for my webrequest call the console reports (and on the simulator, both weather + stock info appear)...
    Antonio - initalizing AppBase
    Antonio - initalizing AMDView
    Antonio - initalizing AMDDelegate
    Antonio - onLayout
    Antonio - makeWeatherRequest
    Antonio - onUpdate
    Antonio - onTempReceive
    Antonio - makeStockRequest
    Using Antonio's webrequest call
    Antonio - onStockReceive
    Antonio - onMasterTimer

    And the AMD.txt for my version reports ...
    Antonio - initalizing AppBase
    Antonio - initalizing AMDView
    Antonio - initalizing AMDDelegate
    Antonio - onLayout
    Antonio - makeWeatherRequest
    Antonio - onUpdate
    Antonio - onUpdate
    Antonio - onUpdate
    Antonio - onUpdate
    Antonio - onTempReceive
    Antonio - makeStockRequest
    Using Antonio's webrequest call
    Antonio - onStockReceive
    Failed to load stocks
    Error: 400
    Antonio - onMasterTimer
    Antonio - onUpdate


    ========================================================
    // Make the stock web request
    function makeStockRequest() {
    Sys.println("Antonio - makeStockRequest");


    Sys.println("Using Antonio's webrequest call");
    Comm.makeWebRequest("query.yahooapis.com/.../yql, null, {}, method(:onStockReceive));


    /*
    Sys.println("Using Travis's webrequest call");
    var url = "query.yahooapis.com/.../yql";
    var options = {
    :method => Comm.HTTP_REQUEST_METHOD_GET,
    :responseType => Comm.HTTP_RESPONSE_CONTENT_TYPE_JSON
    };
    var params = {
    "q" => "select * from yahoo.finance.quotes where symbol in ("AMD")",
    "format" => "json",
    "env" => "store://datatables.org/alltableswithkeys"
    };
    Comm.makeWebRequest(url, options, params, method(:onStockReceive));
    */
    }
  • I posted a (long-ish) reply with some diagnostics.
    I guess we have to wait for the moderators to push the reply to the forums.