hi there
i try to write a very simple code but i don’t know why it doesn’t work.
the code should just show on thingspeak 2 graph, each graph for each integet.
let’s say x=5, y=10, and i want to see it on a graph on thinkspeak.
i use the code from the particle docs and it works fine.
but i don’t understand how can i work with integers, and how do i publish to the web more than 1 graph
this is the code
thank you
int led = D7; // The on-board LED
void setup() {
pinMode(led, OUTPUT);
}
void loop() {
digitalWrite(led, HIGH); // Turn ON the LED
String temp = String(random(60, 80));
Particle.publish("temp", temp, PRIVATE);
delay(200); // Wait for 30 seconds
digitalWrite(led, LOW); // Turn OFF the LED
delay(200); // Wait for 30 seconds
}
Hello
i try to use ThinkSpeak and i have a small problem that i can’t fix.
i use the original code and it works fine, but i don’t know how to make small changes to it.
i want to see in ThinkSpeak 2 graphs, one to show “x” and one to show “y”.
i add here my new code.
can you please try to explain how i fix my code ?
This is the code, and after it i added the original code which works fine
THIS IS THE ORIGINAL CODE THAT WORKS GREAT
void setup() {
}
void loop() {
String i = String(random(60, 80));
Particle.publish("temp", i, PRIVATE);
}
AND THIS IS THE NEW CODE THAT DOESN’T WORK
void setup() {
int x=1;
int y=2;
}
void loop() {
Particle.publish("temp", x, PRIVATE);
Particle.publish("temp", y, PRIVATE);
}
@haytov, the two Particle.publish() in a row and the non-delaying loop() violate the 1 publish per second rule. From the documentation:
NOTE: Currently, a device can publish at rate of about 1 event/sec, with bursts of up to 4 allowed in 1 second. Back to back burst of 4 messages will take 4 seconds to recover.
You need to allow one second between publishes or combine the data into a single publish. I am not familiar enough with Thingspeak and dealing with multiple variables so perhaps someone in the know can take over from here.
Also check your datatypes and scope of the used variables between version 1 and 2.
BTW, since you use the same name for both publishes, they’d not be seen as seperate variables but just different values of the same variable.
thank you all for the help
i added a delay but it didn’t solve the problem.
can i use “int” or i do i have to use “string”? (maybe this is the problem?)