That looks to be the basics of what one of my nodes does when posting data to thingspeak... I hacked away most of the stuff that is sensor or peculiar to my coad... so should be left mostly with just the remains necessary to do the wifi talk to server bit.
WiFiClient client;
String myWriteAPIKey = ""; // Put your API key here
String fieldToPost = "field1"; // Put the field to update here
const char * server_ip = "184.106.153.149";
const char * server_dns = "api.thingspeak.com";
void setup(void)
{
Particle.publish("oak/userrom/startup", "DS18x20_Particle_Thingspeak v0.6", 60, PRIVATE);
}
void loop(void)
{
updateThingspeak("field1",tempC);
}
// thingspeak needs minimum 15 sec delay between updates
boolean updateThingspeak(String field, float data)
{
//try through DNS first
if (client.connect(server_dns, 80))
{
//construct ThinkSpeak POST URL
String postStr = myWriteAPIKey;
postStr += "&";
postStr += field;
postStr += "=";
postStr += String(data);
postStr += "\r\n\r\n";
//process
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: " + myWriteAPIKey + "\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
client.stop();
return true;
} // END if(client.connect())
else
{
return false; //failed to connect
}
}
}