I have a roving networks wifly shield from a company called tinysine. I'm using the wiflyhq library from harlequin on github. I'm able to connect to my local wifi and send an http get request for a website like www.google.com and print it out from ... to tag.
When I replace that site for api.openweather.org/... along with its corresponding api call string, I get an error.
Before getting to the error, is there something special that needs to be done to an http request that returns xml data such as is the case here?
Thats why I included the "before getting to the error"... bit. I want to first make sure I understand how the http request should work so that I can then proceed to debug the error myself. If that fails then Ill come back and ask for help on the error itself along with the error.
Thats why my posts are so long...i always try to understand as much as possible of what is going on.
Before getting to the error, is there something special that needs to be done to an http request that returns xml data such as is the case here?
No. While you may want to tell the server that you accept XML files, if you don't explicitly state that, the server will assume that you will accept them and treat them as text. Since that's what you will do, there is no reason to add to the overhead of communication with the server.
Ok, then Ill have to do more testing because when I download/print the google website, which is plain HTML, it prints fine onto the serial monitor, an api call which returns xml fails for some reason.
So far all I know about the error is that the WiFlyHQ library says: Failed to get prompt.
where somewhere near the bottom Greg Meyer 19 Mar 2015 mentions:
In the new one you've posted, you added another println: client.print("Content-Length: "); # This used to be print rather than println client.println(data.length()); client.println(); client.println(data); So you were no longer malforming the requests.
[\quote]
So I changed my code to:
void callSite(){
if (wifly.open(site, 80)) {
Serial.print("Connected to ");
Serial.println(site);
SurferTim:
The GET or POST line should be the first line in the request, not the "Accept" parameter.
Yes. Another problem is that the OP is specifying HTTP/1.0 . HTTP version 1.0 doesn't take headers - it has to be a bare GET. Furthermore, I imagine that many web servers simply won't respond to 1.0 requests at all, these days.
Well what I get back is xml from openweather.org that looks like this...and I would like to put it into an array/dictionary so that I can parse the data Im interested in, out of it. For example, I just want the time dictionaries:
MiamiUS0.003
...I erased the ones in between but basically there are 8 of these per day for 5 days...
Marciokoko:
Well what I get back is xml from openweather.org that looks like this...and I would like to put it into an array/dictionary so that I can parse the data Im interested in, out of it. For example, I just want the time dictionaries:
There is no magic formula. You read the response on character at a time. After all the characters are read, parse it. That's what the WebClient example does.
And there is always the other option which I had thought of, and is mentioned in this post, having my own server fetch and serve a digested version of it to Arduino. I guess Id use php to fetch this xml, create an array, fetch the multiple day records and somehow average them (since I dont plan to have such a detailed forecast per 3 hours) and then serve that up for my arduino project to pick up in a much simpler format such as an array of 5 days, each day with just a dayID, temp, rain%, uv...
Oh I just noticed there is no UV or rain%, just humidity and pressure, so still, an array with 5 elements and each element dictionary with 4 keys (dayID, temp, humidity & psi).
I guess Id use php to fetch this xml, create an array, fetch the multiple day records and somehow average them (since I dont plan to have such a detailed forecast per 3 hours)
One php script should fetch the xml and create (and store) the data. That script should be running on the server, and should run again some time later.
Another php script that the Arduino calls, should get the records for the last n days, perform the averaging (by day?) and return just the last n days averages.
Push as much of the hard stuff off onto more powerful machines, whenever possible.
Of course, I can't really figure out what role the Arduino needs to have...