Core + DO published event not always triggering Core action

Hey there,

I’ve set up a core to blow a train whistle via digitalWrite(pin, HIGH); when a DO button is pushed. Unfortunately, it doesn’t work reliably. It seems to work only immediately after startup/reflashing and will also work somewhat unreliably (with delays or not at all) shortly after startup/reflashing. I looked at the log for the DO publish event recipe and the recipe does seem to be getting triggered everytime.

I’m not really sure what the Core is seeing/doing as it is currently installed and not easily accessible. So I’m hoping to get some help for a better setup or some debugging tips…

In setup:

Spark.subscribe("HONK", hornHandler, MY_DEVICES);
    Serial.begin(9600);

added the following handler:

void hornHandler(const char *event, const char *data) {
  honk();
  allOn();
  i++;
  Serial.print(i);
  Serial.print(event);
  Serial.print(", data: ");
  if (data)
    Serial.println(data);
  else
    Serial.println("NULL");
  Spark.publish("triggered", data, 60);
  }

Function to toot the whistle:

void honk() {
    relayOn(horn);
    delay(1500);
    relayOff(horn);
    delay(1500);
    relayOn(horn);    
    delay(1500);
    relayOff(horn);
}

I was thinking maybe the Core is going to sleep and disconnecting from the network after sometime and just not reconnecting properly, but who knows…

Hey @quoudten, the function() used by Spark.subscribe() or any other :cloud: functions in general should execute quick instead of having delay.

The reason is that the functions need to return a status code to the :cloud: at the end of the function() call to the request sent.

It would be better to set/unset some flags that are constantly polled in the loop() and execute stuff accordingly! :smile:

3 Likes