# Spark events handler not triggering

**URL:** <https://community.particle.io/t/spark-events-handler-not-triggering/9173>\
**Category:** Firmware\
**Created:** [January 6, 2015, 12:20am UTC](https://community.particle.io/t/spark-events-handler-not-triggering/9173 "2015-01-06T00:20:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)\
**Post date:** [January 6, 2015, 12:20am UTC](https://community.particle.io/t/spark-events-handler-not-triggering/9173/1 "2015-01-06T00:20:25Z")

</div>

Moved the conversation from github: [https://github.com/spark/firmware/issues/365](https://github.com/spark/firmware/issues/365)

Here’s the receiver’s code: [https://gist.github.com/robertdolca/c5240e6d5ee18ce3c3c8](https://gist.github.com/robertdolca/c5240e6d5ee18ce3c3c8)

Here’s the publisher’s code: [https://gist.github.com/robertdolca/84c78855f6bface51491](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.

---

<div class="post-metadata">

**Author:** ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)\
**Post date:** [January 6, 2015, 12:23am UTC](https://community.particle.io/t/spark-events-handler-not-triggering/9173/2 "2015-01-06T00:23:49Z")

</div>

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

**Subscriber**

```auto
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**

```auto
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!");
    }
}

```

---

<div class="post-metadata">

**Author:** ![bko](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/bko/32/20704_2.png) [@bko](https://community.particle.io/u/bko)\
**Post date:** [January 6, 2015, 1:34am UTC](https://community.particle.io/t/spark-events-handler-not-triggering/9173/3 "2015-01-06T01:34:49Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)\
**Post date:** [January 6, 2015, 1:51am UTC](https://community.particle.io/t/spark-events-handler-not-triggering/9173/4 "2015-01-06T01:51:09Z")

</div>

@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 😉

---

<div class="post-metadata">

**Author:** ![Dave](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/dave/32/181_2.png) [@Dave](https://community.particle.io/u/Dave)\
**Post date:** [January 8, 2015, 4:31pm UTC](https://community.particle.io/t/spark-events-handler-not-triggering/9173/5 "2015-01-08T16:31:40Z")

</div>

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. 🙂

> <https://gist.github.com/dmiddlecamp/65a5a94deaef6fdc4167>

Thanks,  
David
