Android Question Issue processing JSON weather feed

Peter Simpson

Expert
Licensed User
Longtime User
Hello,
I'm having huge issues processing a JSON weather feed.

When I type the following directly into any browser, the JSON feed works perfect 100% of the time and is instant. The x's are my personal developers key, so I can't really post that.

https://api.forecast.io/forecast/xxxxxxxxxxxxxxxxx/52.4181385,-1.7744557

I use the following to get the feed, but then JobDone can can take a long time fetching the feed.
GetWeatherJSON.Download("https://api.forecast.io/forecast/xxxxxxxxxxxxxxxxx/" & Latitude & "," & Longitude)

The problem is that about 30% of the time, the JobDone Sub shows the following errors.

Errors collected so far:
Error: java.net.SocketTimeoutException: Read timed out
Error: java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)
Error: java.net.UnknownHostException: Unable to resolve host "api.forecast.io": No address associated with hostname

Error: javax.net.ssl.SSLPeerUnverifiedException: No peer certificate

The main problem is that when the errors occur, I can press refresh on the browser and see the feed instantly. Yet my app is constantly trying at the exact same time and randomly bringing back one of the above errors.

My Android devices and development laptop are on the same 100Mbps internet connection.

Thank you
 
Last edited:

Reviewnow

Active Member
Licensed User
Longtime User
The problem with requesting from web services is that the application does not know when you are going to get a valid result, for instance your application can request the data, but on the other end the server is to busy or cant handle the request. the connection to the server Is valid but no result was returned.

this states that your post never reached the server
Error: java.net.UnknownHostException: Unable to resolve host "api.forecast.io": No address associated with hostname

this states that the server or webservice you are connecting to disconnected your request ( could be server was to busy)

Error: java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)


you can try

increase the timeout for your get request
myobject.GetRequest.Timeout = 40000 or what ever length you want default is 20 seconds 20000

Additional issues depend on if the device has a strong enough signal to receive and or post the request

this is why you have

if job.success then
do something
else
'Request failed
Log("Error: " & Job.ErrorMessage)
'Paying attention to your error messages on failure will just drive you nuts because it is un avoidable in some cases
' Just make sure that your not updating your application here as it did fail

End if
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
Thank you @Reviewnow ,
I'm going to look more into this in the morning.

Al the devices are on a 100Mbps internet connection reaching on average about 94% of it's download speed, the devices are not using internet from mobile supplier which in my case is 4g.

I will admit it, the idea of setting myobject.GetRequest.Timeout = xxxxx didn't even cross my mind. so thank you for that one :)
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
Thank you @Erel ,
I already done that before creating this post. I was just wondering if there was anything else that I could do to help the situation. I suppose that I will just have to let nature take its course but in code :)

At the moment, when it fails to retrieve the JSON stream, it waits 60 seconds before trying again...
 
Upvote 0
Top