I’m trying to access the geocod.io api for geocoding conversion. I’ve received an api key and used the following http:// web browser request and seen that it works great:
http://api.geocod.io/v1/geocode?q=my_zip&fields=timezone&api_key=my_api_key
where my_zip and my_api_key are replaced with the appropriate values.
I’m having trouble getting the appropriate Arduino sequence of client prints.
The geocod.io documentation says:
The base API url is https://api.geocod.io/v1/.
You can also use Geocodio over plain HTTP, but it’s not recommended.
All HTTP responses (including errors) are returned with JSON-formatted output.
I’ve tried the following:
if ( WiFi.status() == WL_CONNECTED) {
if (client.connect({46,4,34,210}, 80)) {
Serial.println(“connected to geocod.io server”);
// Make a HTTP request:
client.println(“GET /v1/geocode?q=my_zip&fields=timezone&api_key=my_api_key HTTP/1.1”);
client.println(“Host: api.geocod.io/”);
client.println(“User-Agent: me@my_address”);
client.println(“Accept: application/json”);
client.println(“Connection: close”);
client.println();
Serial.println(“Done with client.println routine calls for geocod.io.”);
latlon_requested = true;
latlon_attempted_reads = 0;
}
else {
Serial.println(“Failed to connect to geocod.io server!”);
latlon_timeout = true;
}
}
I’ve got the ip address (retrieved from nslookup), because when I put api.geocod.io there, it wouldn’t connect. When I do client.read() calls, I end up seeing text like this:
HTTP/1.1 400 Bad Request
Server: nginx/1.6.2
Date: Tue, 07 Jun 2016 01:36:05 GMT
Content-Type: text/html
Content-Length: 172
Connection: close
400 Bad Request
nginx/1.6.2 ---------------------------------------------
I get the feeling I’m not actually talking to the api engine. Is it clear from the web browser line (that does work) how to put together the Arduino sequence?
Thanks.
co_buckfast