You can send ALL the ThinkSpeak Fields in 1 snprintf if you want.
I looked at several examples on this forum and this is what I found:
snprintf(msg, sizeof(msg),
// ThingSpeak Field #1 , ThingSpeak Field #2 , ThingSpeak WriteKey
"{\"1\":\"%.1f\" , \"2\":\"%.1f\" , \"k\":\"%s\"}" ,
// Float for Field #1 , Float for Field #2 , ThingSpeak WriteKey
field1 , field2 , myWriteAPIKey) ;
Particle.publish(eventName, msg, PRIVATE, NO_ACK);
Flash this code and play around with it:
// Snprintf example
const char * myWriteAPIKey = "xxxxxxxxxxxxxx"; // From your ThingSpeak Account Info (API KEYS tab)
const char * eventName = "thingSpeakWrite_"; // This must match the name of the event you use for the WebHook
float field1 = 1.1;
float field2 = 2.1;
char msg[256];
void setup() {
}
void loop() {
snprintf(msg, sizeof(msg),
// ThingSpeak Field #1 , ThingSpeak Field #2 , ThingSpeak WriteKey
"{\"1\":\"%.1f\" , \"2\":\"%.1f\" , \"k\":\"%s\"}" ,
// Float for Field #1 , Float for Field #2 , ThingSpeak WriteKey
field1 , field2 , myWriteAPIKey) ;
Particle.publish(eventName, msg, PRIVATE, NO_ACK);
field1 = field1 + 0.1;
field2 = field2 + 0.1;
delay(20000); // Wait 20 seconds before sending ThingSpeak.com more data.
}
/*
Sending 4 Fields to ThingSpeak (Floats, w/ 1 decimal precision) would look like this:
snprintf(msg, sizeof(msg),
"{\"1\":\"%.1f\" , \"2\":\"%.1f\" , \"3\":\"%.1f\" , \"4\":\"%.1f\" , \"k\":\"%s\"}" ,
field1 , field2 , field3 , field4 , myWriteAPIKey) ;
*/