Can Spark.publish() speak unto Particle.subscribe()?

Good Evening,

I have a mixed population of Spark and Photons controlling lights in a smart home configuration. The publishes from both types are picked up just fine within my PC web browser if it subscribes to the event streams concerned. However, I have a photon subscribing to those same “smartHome” events from a Spark board and it doesn’t seem to be getting those events - though clearly they are being generated because a web server running on a PC on the same LAN is getting and displaying them. Is there any basic incompatibility between Spark.publish() and Particle.subscribe() Or, should they be fully interchangeable? I can’t find any mentioned of incompatibility in the reference pages.

Thanks yet again
Alan T.

They should be the same as far as I’m concerned. Are you publishing these as PRIVATE?

Good morning :wink:

In addition to @Moors7’s question: Are all devices claimed to the same account, all publishing PRIVATE and subscribing to MY_DEVICES (or PUBLIC/ALL_DEVICES - which is default without explicitly telling) and are all devices running the same system version.
There have been changes between 0.3.4 pub/sub that might have broken the communication between “incompatible” versions.

Thanks for the suggestions gents.

Let’s see…

Yes, they are all claimed to the same account.
The publish line looks like.

Spark.publish(“smartHome”,publishBuffer,10,PRIVATE); // publishBuffer is char[132] filled by a sprintf.

The subscribe side looks like.

Particle.subscribe(“smartHome”,kliteMsg);

void kliteMsg( const char *event, const char *data){
invertLED();
}
void invertLED() {
digitalWrite(7,! digitalRead(7));
}

which as you can see, should just mean that whenever the photon gets a message via the subscription, it toggles the LED state - but that never happens.

The Spark is firmware version 0.3.4 whilst the Photon is 0.5.2 Does that amount to a version mismatch? @ScruffR? Or do the two have different release streams?
Best regards
Alan T

Yes, you’ll see some incompatibility between those versions.
Previously the distinction between PRIVATE publishes and ALL_DEVICES subscriptions was different, but now you need to subscribe with MY_DEVICES when you want to catch a PRIVATE event.
See https://github.com/spark/firmware/issues/645

But I’d suggest upgrading your 0.3.4 to 0.5.2 for all the bug fixes and consistency anyway.

Yes, that did it, added MY_DEVICES and we’re off to the races! Thanks.
As you suggest I will update my residual Spark devices ASAP - although I may be replacing them with Photons anyway in a couple of weeks.

Thanks for your help.
Best regards
Alan T

P.S.
Strangely, this morning while looking for something completely different, I stumbled across this.

http://daraghbyrne.github.io/diotlabs/7-communicating-events/events/
which gives really good starter-level coverage of this whole area.

3 Likes