Spark events handler not triggering

Moved the conversation from github: https://github.com/spark/firmware/issues/365

Here’s the receiver’s code: https://gist.github.com/robertdolca/c5240e6d5ee18ce3c3c8

Here’s the publisher’s code: https://gist.github.com/robertdolca/84c78855f6bface51491

@robertdolca let’s continue the discussion here instead of github issues.

Summary:

The core that is subscribing to the status event doesn’t seem to receive it when published from another core.

Here’s a sample test code that maybe you can try out:

Subscriber

void setup(){
    pinMode(D7,OUTPUT);
    Serial.begin(115200);
    Spark.subscribe("status", statusHandler);
}

void statusHandler(const char *event, const char *data) {
  digitalWrite(D7,!digitalRead(D7));
  Serial.println("Subscribed!");
} 

Publisher

void setup() {
  pinMode(D7,OUTPUT);
  Serial.begin(115200);
}

unsigned long last_time = 0;

void loop() {
    if(millis() - last_time > 3000){
        Spark.publish("status");
        last_time = millis();
        digitalWrite(D7,!digitalRead(D7));
        Serial.println("Published!");
    }
}

Hi @kennethlimcp and @robertdolca

I tested the code above (I fixed a small typo) and it works fine for me!

It has been sitting here running for a few minutes. Is there something more I should look at?

@bko thanks for testing!

Indeed the code above was meant to demonstrate that things are working fine.

There’s the 2 code @robertdolca used in his project and i simply slimmed it down to the bare pub/sub essentials for demonstration if you are interested to test out :wink:

Hey All,

For those who are losing subscriptions when a core drops and re-establishes its connection –

I just wrote up an example of how you could use heartbeat type events to detect if a subscription is lost, and reset your core / cloud connection to get it back. This is totally a temporary workaround type of thing, but it was fun to write anyway. Obviously this is a drastic workaround, and while it might work at home, I wouldn’t recommend this for say forklifts, and killer robots and stuff. :slight_smile:

Thanks,
David