I'm trying to use the darksky weather service without success and I've no doubt it will be down to me. I can very happily send json data and display it in a dashboard (https://io.adafruit.com/chrim/dashboard ... ation-data)..
I'm trying to make the call to set up the weather location as documented as:
Code: Select all
POST /api/v2/:username/integrations/weather
Create a new weather integration record. Request body should be a JSON record in the form:
{
"weather": {
"location": locationValue
}
}
Where locationValue is a location string in latitude,longitude format.
Code: Select all
{
"weather": {
"location": "53.599084,-2.839255"
}
}
Code: Select all
void setupAIOWeatherLocation() {
/* -
https://io.adafruit.com/services/weather
POST /api/v2/:username/integrations/weather
Create a new weather integration record. Request body should be a JSON record in the form:
{
"weather": {
"location": locationValue
}
}
Where locationValue is a location string in latitude,longitude format.
//
*/
const int capacity = 2*JSON_OBJECT_SIZE(1);
StaticJsonDocument<capacity> doc;
JsonObject weather = doc.createNestedObject("weather");
weather["location"] = "52.986923,-1.883297";
serialMessageHeader();
Serial.println("Sending weather location to " IO_HOST);
client.setTimeout(10000);
if (!client.connect(IO_HOST, 80)) {
serialMessageHeader();
Serial.println("Connection to " IO_HOST " failed");
return;
}
// Send the first line of the request
// POST /api/v2/:username/integrations/weather
client.println("POST /api/v2/" SECRET_IO_USERNAME "/integrations/weather");
// Send the first part of the HTTP headers
client.println("Host: " IO_HOST);
client.println(F("Connection: close"));
client.print(F("Content-Length: "));
client.println(measureJson(doc));
client.println(F("Content-Type: application/json"));
client.println(F("X-AIO-Key: " SECRET_IO_KEY));
client.println(); // Terminate headers with a blank line
// Send the JSON document in body
serializeJson(doc, client);
//debug show the json in serial
serializeJsonPretty(doc, Serial);
// Check the HTTP status (should be "HTTP/1.1 200 OK")
char status[32] = {0};
client.readBytesUntil('\r', status, sizeof(status));
if (strcmp(status + 9, "200 OK") != 0) {
serialMessageHeader();
Serial.print(F("Unexpected status from AIO: "));
Serial.println(status);
return;
}
// Close the connection
client.stop();
serialMessageHeader();
Serial.println("Done.");
}