Publish Example Using Spark.publish()

It looks like the Publish example is using spark.publish, which isn’t working. As soon as I changed the lines to Particle.Publish, it started working again.

1 Like

Where do you see Spark.publish()?
Providing a link helps.

The docs do show Particle.publish().
https://docs.particle.io/reference/firmware/photon/#particle-publish-

If you start in the Web IDE, Click Code, Then Click under Example Apps. #4 is Publish. Which is the URL of https://build.particle.io/examples/56214d636666d9ece3000004

 if (beamBroken==true) {
        // If the beam was broken before, then this is a new status.
        // We will send a publish to the cloud and turn the LED on.

        // Send a publish to your devices...
        Spark.publish("beamStatus","intact",60,PRIVATE);
        // And flash the on-board LED on and off.
        digitalWrite(boardLed,HIGH);
        delay(500);
        digitalWrite(boardLed,LOW);

        // Finally, set the flag to reflect the current status of the beam.
        beamBroken=false;
    }
    else {
        // Otherwise, this isn't a new status, and we don't have to do anything.
    }
  }

  else {
      // If you are below the threshold, the beam is probably broken.
      if (beamBroken==false) {

        // Send a publish...
        Spark.publish("beamStatus","broken",60,PRIVATE);
        // And flash the on-board LED on and off.
        digitalWrite(boardLed,HIGH);
        delay(500);
        digitalWrite(boardLed,LOW);

        // Finally, set the flag to reflect the current status of the beam.
        beamBroken=true;
      }
1 Like

I see.
But when I build that sample it still builds without error for me (on Core 0.5.3, Photon 0.6.0-rc.2).

Still, thanks for pointing that out. I’ll open an issue on the repo for an update.

3 Likes

Thanks! It builds without error. But none of the events show up in the Console. :slight_smile: I am also on 5.3 of the firmware. It isn’t a big issue, but its the little things in life that make me lose my hair.

That’s odd!
@suda, any idea about that?
If Spark.xxxx() was deprecated already, the build should fail :confused:

1 Like

Thanks for catching this! It seems we forgot to update the examples after we deprecated Spark namespace. It should be fixed now (you might need to clear the Build cache).

1 Like

@suda, will the build now fail when using Spark.xxxx() functions?
If they don’t work anymore, a compile time message would be expected.

I just updated the examples to use Particle instead of Spark. An error should appear if someone is using Spark.

No it does not!
I just tried that (against 0.6.0-rc.2 and 0.5.3) immediately before posting above comment, and there was no error, only a warning and these are not displayed when there is no breaking error.

1 Like

Oh you’re right! We’ll need to add some UI to warn users about deprecation even if compilation succeeds.

1 Like