How to get a value from this object?

I have the following data returned by my Ecowitt weather station:

{time=>1723724790, data=>{rainfall=>{yearly=>{unit=>mm, time=>1723724776, value=>0.0}, daily=>{unit=>mm, time=>1723724776, value=>0.0}, rain_rate=>{unit=>mm/hr, time=>1723724776, value=>0.0}, weekly=>{unit=>mm, time=>1723724776, value=>0.0}, hourly=>{unit=>mm, time=>1723724776, value=>0.0}, event=>{unit=>mm, time=>1723724776, value=>0.0}, monthly=>{unit=>mm, time=>1723724776, value=>0.0}}, battery=>{sensor_array=>{unit=>, time=>1723724776, value=>0}}, outdoor=>{humidity=>{unit=>%, time=>1723724776, value=>51}, app_temp=>{unit=>℃, time=>1723724776, value=>31.2}, dew_point=>{unit=>℃, time=>1723724776, value=>18.3}, feels_like=>{unit=>℃, time=>1723724776, value=>30.4}, temperature=>{unit=>℃, time=>1723724776, value=>29.5}}, indoor=>{humidity=>{unit=>%, time=>1723724776, value=>59}, temperature=>{unit=>℃, time=>1723724776, value=>26.8}}, pressure=>{relative=>{unit=>inHg, time=>1723724776, value=>27.99}, absolute=>{unit=>inHg, time=>1723724776, value=>27.99}}, solar_and_uvi=>{solar=>{unit=>W/m², time=>1723724776, value=>202.5}, uvi=>{unit=>, time=>1723724776, value=>1}}, wind=>{wind_gust=>{unit=>km/h, time=>1723724776, value=>9.4}, wind_direction=>{unit=>º, time=>1723724776, value=>149}, wind_speed=>{unit=>km/h, time=>1723724776, value=>6.5}}}, msg=>success, code=>0}

How can I get the value of the outdoor temperature (data.outdoor.temperature.value)?

I tried the following and got a crash:

var temp = data["data"]["outdoor"]["temperature"]["value"];
var unit = data["data"]["outdoor"]["temperature"]["unit"];

Thanks in advance

Best regards

Aaron

  • On a real Garmin device every 4 seconds could be an issue (if it works at all) due to network speeds and BT speed between your phone and your Garmin. Your computer probably has a much faster network and no BT involved.

    And in reality, the weather data really doesn't change that fast. 

  • You may have a timer already to do the WatchUi.requestUpdate(), so it's pretty each so that every "X" timer ticks it requests data.  And then in the makeWebRequest callback, do the watchUi.requestUpdate() when you get good data.  It will be more friendly battery wise.  Fewer data requests and fewer screen updates.

  • This Is how I ended up doing it, I just published the app (verification is pending) and I plan to upload the source to Github once I cleaned everything up and added proper exception handling...

  • Have you run it on a real garmin device and not just the sim?

    Android or iOS?

    I seem to recall it didn't work with Android (but this was a year or two back) and never tried iOS.

  • Yes, I tested it on my Venu 2 (with my Android phone) as that's the only Garmin watch I have:

  • Ok, I tried my old app on a watch and it gives me a -400 yet works in the sim.

    Could you post what you are using for options in the makeWebRequest?

    Thanks.