Thanks for the help (especially BKO)! I got this working and thought I’d post the final working code for posterity:
Bathroom Door Status Publisher:
// -----------------
// Send Bathroom Door Status
// -----------------
int srbs = 0;
void setup()
{
Spark.variable("srbs", &srbs, INT);
//attachInterrupt(D0, updatestatusclosed, FALLING);
//attachInterrupt(D0, updatestatusopen, RISING);
attachInterrupt(D0, updatestatus, CHANGE);
pinMode(D0, INPUT);
pinMode(D7, OUTPUT);
}
void loop()
{
digitalWrite(D7,srbs);
delay(500);
}
void updatestatus()
{
srbs = digitalRead(D0);
if(srbs==1)
{
Spark.publish("srbs-status","closed");
}else
{
Spark.publish("srbs-status","open");
}
}
Bathroom Door Status Subscriber:
// -----------------
// Read Bathroom Door Status
// -----------------
int led = 1;
char const *dataout = "unknown";
void light(const char *event, const char *data)
{
if(strcmp(data,"closed"))
{
led = 1;
}
else
{
led = 0;
}
digitalWrite(D7, led);
dataout = data;
}
void setup()
{
pinMode(D7, OUTPUT);
Spark.subscribe("srbs-status", light, MY_DEVICES);
Serial.begin(9600);
}
void loop()
{
digitalWrite(D7, led);
if (dataout)
Serial.println(dataout);
else
Serial.println("NULL");
delay(500);
}