Often the temperature data is wrong

Issue #19 new
Mike Budimon created an issue

When you run .getMainInstance().getTemperature() to get the temperature data, al lot of times it's over 280 Fahrenheit which is like 130 Celsius and it doesn't change until you restart your program.

Comments (8)

  1. Benjamin Schluck

    Hi, I just tried to reproduce and analyse the issue, because my application is showing the same results from time to time. I realized that the returned values are okay for the parameters "units=metric" and "units=imperial", but as soon as you use any other string after "units=", the returned value is close to 280. So perhaps there is some point where the URL string is not concatenated correctly?

    Cheers, Benny

  2. Pete Arvanitis

    I did some debugging on this. It looks like the unit type is being specified in uppercase on the URL string. This is what is being called:

    http://api.openweathermap.org/data/2.5/weather?lat=32.77&lon=-79.94&mode=json&units=IMPERIAL&appId=<myAppId>

    This returns a value close to 280.

    {"coord":{"lon":-79.93,"lat":32.78},"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"base":"cmc stations","main":{"temp":287.314,"pressure":1034.61,"humidity":94,"temp_min":287.314,"temp_max":287.314,"sea_level":1034.65,"grnd_level":1034.61},"wind":{"speed":6.32,"deg":170},"rain":{"3h":2.295},"clouds":{"all":92},"dt":1455560199,"sys":{"message":0.0092,"country":"US","sunrise":1455537755,"sunset":1455577529},"id":4574324,"name":"Charleston","cod":200}

    However, if you submit the same string with a lowercase "imperial" it works correctly.

    {"coord":{"lon":-79.93,"lat":32.78},"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"base":"cmc stations","main":{"temp":57.5,"pressure":1034.61,"humidity":94,"temp_min":57.5,"temp_max":57.5,"sea_level":1034.65,"grnd_level":1034.61},"wind":{"speed":13.65,"deg":170},"rain":{"3h":2.295},"clouds":{"all":92},"dt":1455560199,"sys":{"message":0.0092,"country":"US","sunrise":1455537755,"sunset":1455577529},"id":4574324,"name":"Charleston","cod":200}

  3. Pete Arvanitis

    The quick fix for this issue would be to update the Units enumeration in OpenWeatherMap.java and implement the toString method.

    public static enum Units {
            METRIC("metric"),
            IMPERIAL("imperial");
    
            private final String unit;
    
             public String toString() { return unit;} 
    
            Units(String unit) {
                this.unit = unit;
            }
        }
    
  4. Mike Budimon reporter

    I implemented your solution Pete Arvanitis, but nothing changed and I still get a lot of times wrong temperature data.

  5. Pete Arvanitis

    You may also need to explicitly set the unit type in code (which I was already doing in my app). I'm now consistently getting Metric values by both explicitly setting the units and by adding "toString" to the Units enum.

    owm.setUnits(Units.METRIC);
    
  6. Mark

    Same problem here. I added a toString method to units and lang classes in order to have lower case in the URL. However sometimes the temp value is still wrong. I suspect a problem of openweathermap

  7. Mark

    Openweathermap customer support said that their server has problems randomly to convert kelvin to celsius. The solution is to modify the code in order to always ask for kelvin degree and convert the temperature client side.

  8. Ashutosh Kumar Singh repo owner

    Hi all, thanks for reaching out to me. And apologies for the late response. I wasn't able to work on this lib for long time, but finally I have decided to work on it and make it the full-featured lib. for OpenWeatherMap.org

    I have shifted the repo. to http://go.aksingh.net/owm-japis. Kindly check it there.

    OWM has now 3 units, out of which only 2 were supported in old version. And the new version of OWM JAPIs at the new link supports all 3 units, and should work properly for all units. Thank you.

  9. Log in to comment