Thingspeak multiple fields problem

Hello,
I’m using a photon with 5 webhooks. Those webhooks transfer the data to Thingspeak. And now to the problem, I want to use the main JSON file for a project. But I cant send all 5 at once, so I put a delay between every dataset. But now in the JSON file it tells me “null” at some fields.

Is there a way to send 5 webhooks at the same time to Thingspeak or another way to get rid of this problem?

Here is the part of my code, where it sends the data to thingspeak:

Particle.publish("biergartenSensor1", String(sen1), PRIVATE);
for(int i = 1; i < 4; i++){
    digitalWrite(ledPin2, HIGH);
    delay(100);
    digitalWrite(ledPin2, LOW);
    delay(100);
}
delay(30000);

Particle.publish("biergartenSensor2", String(sen2), PRIVATE);
for(int i = 1; i < 4; i++){
    digitalWrite(ledPin2, HIGH);
    delay(100);
    digitalWrite(ledPin2, LOW);
    delay(100);
}
delay(30000);

Particle.publish("biergartenSensor3", String(sen3), PRIVATE);
for(int i = 1; i < 4; i++){
    digitalWrite(ledPin2, HIGH);
    delay(100);
    digitalWrite(ledPin2, LOW);
    delay(100);
}
delay(30000);

Particle.publish("biergartenSensor4", String(sen4), PRIVATE);
for(int i = 1; i < 4; i++){
    digitalWrite(ledPin2, HIGH);
    delay(100);
    digitalWrite(ledPin2, LOW);
    delay(100);
}
delay(30000);

Particle.publish("biergartenSensor5", String(sen5), PRIVATE);
for(int i = 1; i < 4; i++){
    digitalWrite(ledPin2, HIGH);
    delay(100);
    digitalWrite(ledPin2, LOW);
    delay(100);
}
delay(30000);

An here is how my JSON looks like:

First, the rate limit for publishes is 1 per second (with a burst of 4 with a 4sec pause following).
So you’d not need your delay(30000) and the extra 600ms inside your blink-loops.

And next, do you actually need five webhooks, can you not just use one with all the data at once, with a custom template?

You can have a data payload for your publish even like this

char _json[256];
snprintf(_json, sizeof(_json), "{\"field1\":\"%d\",\"field2\":\"%d\",\"field3\":\"%d\",\"field4\":\"%d\",\"field5\":\"%d\"}", sen1, sen2 ,sen3, sen4, sen5);
Particle.publish("biergartenSensor", _json, PRIVATE);
1 Like

Thanks! :slight_smile:

I got 5 sensors, which only tell me 1 or 0. The idea with just one sounds cool.
How can I create a custom template?

Seen my edit above?

BTW, there is a ThingSpeak library too, maybe you can get around webhooks completely.

2 Likes

Hey,
I used the library and everything works fine! Thank you!

2 Likes