webrequest ok on simulator crashes on vivoactivehr

Former Member
Former Member
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));
  • Former Member
    Former Member over 8 years ago
    Travis, that didn't help. :(
    I re-wrote the code to use your function call, passing in url, options + params but, it fails ...
    Below, console logs for 1) your code, 2) my modified code and 3) the actual code (I comment one or other version it).
    I haven't tried it on the VAHR.

    ======================================
    Antonio - initalizing AppBase
    Antonio - initalizing AMDView
    Antonio - initalizing AMDDelegate
    Antonio - onLayout
    Antonio - makeWeatherRequest
    Antonio - onUpdate
    Antonio - onTempReceive
    Antonio - makeStockRequest
    Antonio - test this now
    Antonio - onStockReceive
    null
    Failed to load stocks
    Error: -400
    Complete
    Connection Finished
    Closing shell and port

    ======================================

    Antonio - initalizing AppBase
    Antonio - initalizing AMDView
    Antonio - initalizing AMDDelegate
    Antonio - onLayout
    Antonio - makeWeatherRequest
    Antonio - onUpdate
    Antonio - onTempReceive
    Antonio - makeStockRequest
    Antonio - test this one
    Antonio - onStockReceive
    {query=>{results=>{quote=>{OneyrTargetPrice=>8.88, LowLimit=>null, HoldingsGain=>null, AverageDailyVolume=>47605300, Commission=>null, ExDividendDate=>null, MarketCapitalization=>10.74B, HoldingsValueRealtime=>null, LastTradeDate=>12/29/2016, ErrorIndicationreturnedforsymbolchangedinvalid=>null, HighLimit=>null, EPSEstimateNextYear=>0.05, LastTradePriceOnly=>11.59, Symbol=>AMD, LastTradeTime=>4:00pm, PriceSales=>2.60, Bid=>11.63, Volume=>50180155, DaysHigh=>11.62, Notes=>null, PriceBook=>27.76, TradeDate=>null, FiftydayMovingAverage=>9.40, PercentChangeFromYearLow=>+562.29%, DaysLow=>11.01, ChangeRealtime=>null, DaysRangeRealtime=>null, PricePaid=>null, PercentChange=>+0.35%, Name=>Advanced Micro Devices, Inc., symbol=>AMD, AskRealtime=>null, DaysValueChangeRealtime=>null, PriceEPSEstimateNextYear=>231.80, HoldingsGainPercent=>null, YearHigh=>12.42, EPSEstimateCurrentYear=>-0.15, AfterHoursChangeRealtime=>null, BookValue=>0.42, PreviousClose=>11.55, Currency=>USD, SharesOwned=>null, ChangePercentRealtime=>null, DividendYield=>0.00, ChangeFromFiftydayMovingAverage=>2.19, EarningsShare=>-0.69, PEGRatio=>0.78, Ask=>11.66, MoreInfo=>null, TickerTrend=>null, PercebtChangeFromYearHigh=>-6.68%, ShortRatio=>1.76, YearLow=>1.75, YearRange=>1.75 - 12.42, Open=>11.24, Change_PercentChange=>+0.04 - +0.35%, TwoHundreddayMovingAverage=>7.07, ChangeFromYearHigh=>-0.83, PERatioRealtime=>null, PercentChangeFromFiftydayMovingAverage=>+23.26%, DaysRange=>11.01 - 11.62, EPSEstimateNextQuarter=>-0.04, PriceEPSEstimateCurrentYear=>null, LastTradeWithTime=>4:00pm - <b>11.59</b>, StockExchange=>NCM, MarketCapRealtime=>null, HoldingsValue=>null, PERatio=>null, Change=>+0.04, DaysValueChange=>null, DividendShare=>0.00, AnnualizedGain=>null, BidRealtime=>null, LastTradeRealtimeWithTime=>null, ChangeFromTwoHundreddayMovingAverage=>4.52, HoldingsGainRealtime=>null, PercentChangeFromTwoHundreddayMovingAverage=>+63.89%, ChangeFromYearLow=>9.84, HoldingsGainPercentRealtime=>null, OrderBookRealtime=>null, EBITDA=>-304.00M, ChangeinPercent=>+0.35%, DividendPayDate=>null}}, created=>2016-12-30T01:20:26Z, count=>1, lang=>en-US}}
    Antonio - onMasterTimer
    Antonio - onUpdate
    Complete
    Connection Finished
    Closing shell and port

    ======================================

    function makeStockRequest() {
    Sys.println("Antonio - makeStockRequest");

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

    // this works on the simulator
    // Sys.println("Antonio - test this one");
    // var url = "query.yahooapis.com/.../yql
    // var options= null;
    // var params = {};

    // try this on the simulator
    Sys.println("Antonio - test this now");
    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/Falltableswithkeys"
    };

    Comm.makeWebRequest(url, options, params, method(:onStockReceive));
    }
  • Turns out it was a typo. I reversed the params and options parameters to makeWebRequest(). I've tested in the simulator and this works just fine...

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

    //var headers = {
    // "Content-Type" => Comm.REQUEST_CONTENT_TYPE_URL_ENCODED
    //};

    var options = {
    //:method => Comm.HTTP_REQUEST_METHOD_GET,
    //:headers => headers,
    //: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(:onWebResponse));


    I've gone back and updated the code in my previous post to be sure nobody else is affected by this silly bug.

    Travis
  • Former Member
    Former Member over 8 years ago
    That works (on the simulator)!! :)
    Did you try in on watch itself?

    My original cmd worked on the simulator as well but, failed on the watch.
  • Did you try in on watch itself?

    I'm away from home and don't have access to my cables to copy files to a device. I'm pretty sure this should work though.

    Travis
  • Former Member
    Former Member over 8 years ago
    FYI that it's working now but only after I added a delay (30 secs) between makeWebRequest calls.
    That is, it failed with your version of the function call.
  • I'm not yet sure what is going on here. I wrote up a sample app from scratch and it sometimes causes Garmin Connect Mobile on iOS to crash when I try to execute the web requests. Other times it returns a -2 error code (BLE_HOST_TIMEOUT). I'll keep investigating and file bugs as is necessary.

    That said, you can significantly improve the response time of the stock query by selecting only the data you need. You can do this by selecting only the column of data that you want...

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


    You can get the list of fields by looking at this page. In my device testing on the vivoactive_hr, your original query takes about 12 seconds to get a response on the device and the new one takes less than 4 seconds.

    If you could do something like this with the other query, I think you'd get a significant improvement. You may be able to execute both queries simultaneously.

    Travis