CLI publish event not received by Core

Is it possible to use ‘particle publish’ from the CLI and have my Core receive that message? I’ve trying to debug a subscription and have setup a Core to respond to a publish event which works from core to core but when I publish the same event via CLI the Core doesn’t react. My subscribe line is:

Spark.subscribe("sensorData", processRemoteData, MY_DEVICES);

And the handler has been stripped down to:

void processRemoteData(const char *event, const char *data)
    Spark.publish("receipt","Received sensorData", 60, PRIVATE);

When I publish from the CLI it shows up in the Spark Dashboard as device ‘cloud’ so perhaps it’s not seeing the CLI as one of MY_DEVICES?

Yes you are correct. The particle publish comes from the :cloud: and is not considered a MY_DEVICES condition

Would this be screwing up my webhooks then? I created simple webhook using the steps show here:

I can see in the dashboard the publish event that calls the webhook as well as the 5 responses starting with (hook-response/get_weather/0) but the Core doesn’t react to it. I’m using the same handler and with the subscribe statement using MY_DEVICES as in the example code.

Good question i never tried but from the example that should work with MY_DEVICES for Spark.publish()

So you are getting a response but not triggering on the core… I will have to test and see how it goes. One second.

Can you change the line to Spark.subscribe("hook-response", gotWeatherData, MY_DEVICES); and test again?

I think the old subscribe bug still applies to the core :smile:

Sorry about that!

Thanks, that fixes my webhook issue; and removing MY_DEVICES allows my Core to hear my CLI published events.

1 Like

I think I spoke too soon about the webhooks. My handler is getting called but no data is being passed to it.

For future reference if you have 2 subscribes that match the same name; ie ‘hook-response’ and ‘hook-response/get_weather’ and an event comes in matching both, ie ‘hook-response/get_weather/0’; then the data parameter sent to the handlers is null/empty, at least on a Core.

The other problem is very strange, apparently the order of subscriptions matter. If I do this everything works:

Spark.subscribe("hook-response/glowfish", glowfishHandler, MY_DEVICES);
Spark.subscribe("sensorData", processRemoteData, MY_DEVICES);

If I switch the order, as shown below, then the responses from the glowfish webhooks are never seen by my Core. Even if I set both to use the same handler.

Spark.subscribe("sensorData", processRemoteData, MY_DEVICES);
Spark.subscribe("hook-response/glowfish", glowfishHandler, MY_DEVICES);

It is a known bug that has been fixed but not yet available for the core at this point in time using the :cloud: compiler.