Hi there
I am completely stuck and would really like some input. I can get a stable connection to Thingspeak, but all my attempts to post data re unsuccessful. I can either post an empty entry (It shows I have a new entry, with null values for the fields) or I can get a 400 Bad Request returned, but that's it. Any pointers will be welcome!
I am using Wifly.h and connects successfully to the wifi and external sites.
Here is the code for the Bad Request:
I call this function in my main loop:
ThingSpeakUpdate("field1="+String(x)+"&field2="+String(y));
And here is the function:
void ThingSpeakUpdate(String tsData)
{
Serial.println("Data string: " + tsData);
Serial.println("...Connecting to Thingspeak");
// Connecting and sending data to Thingspeak
if(Wifly.connect("api.thingspeak.com","80"))
{
Serial.println("...Connection succesful, updating datastreams");
Wifly.println("POST /update HTTP/1.1");
Wifly.println("Host: api.thingspeak.com");
Wifly.println("Connection: close");
Wifly.println("X-THINGSPEAKAPIKEY: "+myWriteAPIKey);
Wifly.println("Content-Type: application/x-www-form-urlencoded");
Wifly.println("Content-Length: ");
Wifly.println(tsData.length());
Wifly.println();
Wifly.println(tsData);
delay(200);
Serial.println("Thingspeak update sent.");
}
else{
// Failed to connect to Thingspeak
Serial.println("Unable to connect to Thingspeak.");
}