Hi I’m trying the pubish/subribe pattern, getting the data to a python server. I get the messages at my server, however almost only 1 of 20 messages have data, the others are empty. Can someone tell me what going on!?
This is my core code:
int number;
void setup() {
Spark.variable("number", &number, INT);
Serial.begin(9600);
}
void loop() {
delay(200);
if(random(100) < 5) {
Serial.println(millis());
String data = String(number);
Spark.publish("event",data);
}
}
int newNumber(String command) {
number = random(10000);
}
btw you can find the Python Sparkcloud API here:
@tinkerly, from the looks of it, you are publishing too quickly. The (now documented) limit is 1 per second with a burst of 4 per second. You are possibly exceeding that limit, causing a drop in events. The if(random(100) < 5)
is the only code that may or may not slow things down. You may want to add a test (using millis() for example) to ensure you wait a minimum of 1000ms before publishing again.
4 Likes
okay, havent checked the event-intervall, didnt seem so much tho on the server. but I’m gonna add a time-buffer to it. thanks @peekay123
Just out of curiosity, where do you call newNumber()
?
And without checking your subscribing code, are you sure you’re only receiving your own event
s?
Since you are using a - pardon the term - rather common event name, you might see some similarly “boring” events from others, not carrying any data.
It’s always better to choose some “imaginative” event names
3 Likes