JSON returned

When I call the open weather API direct in a browser I get

{"city":{"id":2654710,"name":"Brighton","coord":{"lon":-0.13947,"lat":50.828381},"country":"GB","population":0},"cod":"200","message":0.0097,"cnt":2,"list":[{"dt":1448190000,"temp":{"day":278.17,"min":273.4,"max":278.45,"night":273.4,"eve":275.73,"morn":278.17},"pressure":1019.59,"humidity":84,"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03d"}],"speed":2.76,"deg":316,"clouds":32},{"dt":1448276400,"temp":{"day":277.23,"min":271.73,"max":277.68,"night":277.68,"eve":275.16,"morn":271.73},"pressure":1030.2,"humidity":90,"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"speed":1.97,"deg":318,"clouds":56,"rain":0.66}]}

If I make the same call from CIQ I get

{message=>0.009700, city=>{population=>0, id=>2654710, coord=>{lat=>50.828381, lon=>-0.139470}, name=>Brighton, country=>GB}, cod=>200, cnt=>2, list=>[{pressure=>1019.590027, clouds=>32, weather=>[{main=>Clouds, id=>802, description=>scattered clouds, icon=>03d}], speed=>2.760000, dt=>1448190000, humidity=>84, temp=>{min=>273.399994, night=>273.399994, day=>278.170013, eve=>275.730011, morn=>278.170013, max=>278.450012}, deg=>316}, {pressure=>1030.199951, clouds=>56, weather=>[{main=>Rain, id=>500, description=>light rain, icon=>10d}], speed=>1.970000, dt=>1448276400, humidity=>90, temp=>{min=>271.730011, night=>277.679993, day=>277.230011, eve=>275.160004, morn=>271.730011, max=>277.679993}, deg=>318, rain=>0.660000}]}

{message=>0.009700, city=>{population=>0, id=>2654710, coord=>{lat=>50.828381, lon=>-0.139470}, name=>Brighton, country=>GB}, cod=>200, cnt=>2, list=>[{pressure=>1019.590027, clouds=>32, weather=>[{main=>Clouds, id=>802, description=>scattered clouds, icon=>03d}], speed=>2.760000, dt=>1448190000, humidity=>84, temp=>{min=>273.399994, night=>273.399994, day=>278.170013, eve=>275.730011, morn=>278.170013, max=>278.450012}, deg=>316}, {pressure=>1030.199951, clouds=>56, weather=>[{main=>Rain, id=>500, description=>light rain, icon=>10d}], speed=>1.970000, dt=>1448276400, humidity=>90, temp=>{min=>271.730011, night=>277.679993, day=>277.230011, eve=>275.160004, morn=>271.730011, max=>277.679993}, deg=>318, rain=>0.660000}]}

As you can see there is a duplication of the data when called from CIQ.

Any ideas? (I've added a line break just so you can see the duplication.
  • It appears that you're saying that the callback is invoked twice with the same data, right? I noticed this last night and was just getting ready to write a test case to demonstrate.
  • It appears that you're saying that the callback is invoked twice with the same data, right? I noticed this last night and was just getting ready to write a test case to demonstrate.


    Yup, exactly.
  • I've written up a test case and I'm not seeing it. I went back to the code I was tinkering with previously, and I see now that I was seeing the output of multiple onUpdate() calls, not from multiple onReceive() calls. So, for my case, I'm chalking this up to user error.

    Here is the test case that I developed.

    using Toybox.Graphics as Gfx;
    using Toybox.WatchUi as Ui;
    using Toybox.Lang as Lang;
    using Toybox.Time as Time;
    using Toybox.Application as App;
    using Toybox.Time.Gregorian as Calendar;
    using Toybox.System as Sys;
    using Toybox.Communications as Comm;


    class TestDelegate extends Ui.BehaviorDelegate
    {
    hidden var view;

    function initialize() {
    BehaviorDelegate.initialize();
    }

    function onSelect() {
    var url = "earthquake.usgs.gov/.../query";

    var params = {
    "format" => "geojson",
    "limit" => 1,
    "orderby" => "time"
    };

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

    Sys.println(url);
    notify(:request);

    Comm.makeJsonRequest(url, params, options, method(:onReceive));
    }

    function onReceive(code, data) {
    if (code == 200) {
    Sys.println(data);

    notify(:response);
    }
    }

    function setView(view) {
    self.view = view;
    }

    function notify(symbol, obj, params) {
    if (view != null) {
    view.onNotify(symbol, obj, params);
    }
    }
    }

    class TestView extends Ui.View
    {
    hidden var requests;
    hidden var responses;

    function initialize() {
    View.initialize();
    requests = 0;
    responses = 0;
    }

    function onNotify(symbol, object, params) {
    if (symbol == :request) {
    requests += 1;
    Ui.requestUpdate();
    }
    else if (symbol == :response) {
    responses += 1;
    Ui.requestUpdate();
    }
    }

    function onUpdate(dc) {
    dc.setColor(Gfx.COLOR_BLACK, Gfx.COLOR_BLACK);
    dc.clear();

    dc.setColor(Gfx.COLOR_WHITE, Gfx.COLOR_TRANSPARENT);

    var fx = dc.getFontHeight(Gfx.FONT_SMALL);

    var cx = dc.getWidth() / 2;
    var cy = dc.getHeight() / 2 - fx;

    dc.drawText(cx, cy, Gfx.FONT_SMALL, Lang.format("$1$ requests", [ requests ]), Gfx.TEXT_JUSTIFY_CENTER | Gfx.TEXT_JUSTIFY_VCENTER);
    cy += fx;

    dc.drawText(cx, cy, Gfx.FONT_SMALL, Lang.format("$1$ responses", [ responses ]), Gfx.TEXT_JUSTIFY_CENTER | Gfx.TEXT_JUSTIFY_VCENTER);
    cy += fx;
    }
    }

    class TestApp extends App.AppBase {

    function initialize() {
    AppBase.initialize();
    }

    function getInitialView() {
    var view = new TestView();
    var delegate = new TestDelegate();
    delegate.setView(view);

    return [ view, delegate ];
    }
    }


    Are you able to reliably reproduce a problem (with my test case or yours)? Could you provide a test case?

    Travis
  • Rupert - I don't see it happening with my stuff. Are you seeing it in the simulator or on a device? If on a device, which one/which firmware, and iOS/Andriod for GCM and which version?