Created
April 30, 2015 05:14
-
-
Save harrisonhjones/1bfc327f90e18ea17e62 to your computer and use it in GitHub Desktop.
QueuedPublishEventsSpark
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
char eventMessages[10][65]; // 10 messages of a max 65 char length | |
char eventMessage[65]; // A buffer for outgoing publish events | |
int queueIndex = -1; // -1 = nothing to send, 0+ = a message is queued | |
// In your main loop(); | |
// Your code here | |
// Step 1 - Build your publish string | |
sprintf(eventMessage, "The temp outside is %d C", tempValue); | |
// Step 2 - Attempt to send it | |
if(Spark.publish('eventName', eventMessage) != true) | |
{ | |
// Step 3 - Queue it | |
if((queueIndex+1) >= 10) | |
{ | |
// We've run our of queue spots. What to do now? | |
} | |
else | |
{ | |
queueIndex++; | |
strncpy(eventMessages[queueIndex], eventMessage, 65); | |
eventMessages[queueIndex][64] = '\0'; // Prevent possible overflow condition | |
} | |
} | |
delay(1000); | |
// Step 4 - Send out the queue | |
while(queueIndex >= 0) | |
{ | |
if(Spark.publish('queuedEventName', eventMessage[queueIndex]) == true) | |
{ | |
queueIndex--; // Decrement the queue counter | |
} | |
delay(1000); // Wait a second so we don't exceed the publish limit | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment