Created
February 5, 2015 06:16
-
-
Save harrisonhjones/0c104713c8637d5390a0 to your computer and use it in GitHub Desktop.
Spark SubPub Issue
This file contains 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
#include "application.h" | |
char lastTimeRec1[40]; | |
char lastTimeRec2[40]; | |
unsigned long lastTime = 0UL; | |
char publishString[40]; | |
bool whichOne = false; | |
void handleTest1( const char * event, const char * data ); | |
void handleTest2( const char * event, const char * data ); | |
void setup() | |
{ | |
Serial.begin(9600); | |
// Now open your Serial Terminal, and hit any key to continue! | |
while(!Serial.available()) SPARK_WLAN_Loop(); | |
Spark.variable( "lastRec1", &lastTimeRec1, STRING ); | |
Spark.variable( "lastRec2", &lastTimeRec2, STRING ); | |
if(Spark.subscribe( "db2015/test/pub2" , handleTest2 ) == true) | |
{ | |
Serial.println("Subscribe Handler 2 Success!"); | |
} | |
else | |
{ | |
Serial.println("Subscribe Handler 2 Failure!"); | |
} | |
if(Spark.subscribe( "db2015/test/pub1" , handleTest1 ) == true) | |
{ | |
Serial.println("Subscribe Handler 1 Success!"); | |
} | |
else | |
{ | |
Serial.println("Subscribe Handler 1 Failure!"); | |
} | |
} | |
void loop() | |
{ | |
unsigned long now = millis(); | |
//Every 15 seconds publish uptime | |
if (now-lastTime>5000UL) { | |
Serial.print("Publishing an event! ("); | |
lastTime = now; | |
// now is in milliseconds | |
unsigned nowSec = now/1000UL; | |
unsigned sec = nowSec%60; | |
unsigned min = (nowSec%3600)/60; | |
unsigned hours = (nowSec%86400)/3600; | |
sprintf(publishString,"%u:%u:%u",hours,min,sec); | |
Serial.print(publishString); | |
Serial.println(")"); | |
if( whichOne == false){ | |
Spark.publish("db2015/test/pub1",publishString ); | |
}else{ | |
Spark.publish("db2015/test/pub2",publishString ); | |
} | |
whichOne = !whichOne; | |
} | |
} | |
void handleTest1( const char * event, const char * data ) | |
{ | |
Serial.println("Handle 1 Test Called!"); | |
} | |
void handleTest2( const char * event, const char * data ) | |
{ | |
Serial.println("Handle 2 Test Called!"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment