Particle `publish` events firing too frequently

Hello! I’m attempting to monitor temperature using a DS18B20 sensor and the Particle Photon. I’m attempting to publish a temp event via Particle#publish every 2 minutes. Unfortunately, I’m observing events published every ~16 seconds via the CLI’s handy particle subscribe. Here’s my project file:

// This #include statement was automatically added by the Particle IDE.
#include "OneWire/OneWire.h"

// This #include statement was automatically added by the Particle IDE.
#include "spark-dallas-temperature/spark-dallas-temperature.h"

#define ONE_WIRE_BUS D2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensor(&oneWire);
DeviceAddress deviceAddress;
const unsigned long sampleDuration = 2 * 60 * 1000UL;

// Initialize with `0` so it runs on the first loop
unsigned long lastSampled = 0;
int16_t temp;

void setup() {
    // Serial.begin(9600);
    // Mutates `deviceAddress`?
    sensor.getAddress(deviceAddress, 0);

void loop() {
    unsigned long now = millis();
    if (now - lastSampled >= sampleDuration) {
        temp = sensor.getTemp(deviceAddress);

        // Serial.print("Temperature: ");
        // Serial.println(temp);
        Particle.publish("temp", String(temp));

I’ve also tried dropping the if branch and simply using a delay(12000). Same thing happens.

And here’s the output from the CLI:


Any thoughts? Could my firmware be crashing every few seconds?

Just reviewed the API documentation for System#sleep. Would this be more appropriate than delay in the first place?

You will need to update lastSampled in the loop with lastSampled = millis()


Also, since you’re publishing to the publish firehouse, and your SSE hasn’t got the most original name, you’ll be picking up events from others, with the same name, as well.
Either make the name more unique, or publish them Privately.


Gah! Yes, of course. Thanks!

I’m using the CLI like so:

particle subscribe temp mine

This only listens to my (single) photon, if I understand right. I’ll add a prefix to see if that changes things. Thanks for the suggestion!

Hmm. It seems the editor isn’t flashing the Photon over-the-air. I changed the event name to swashcap-temp:

Particle.publish("swashcap-temp", String(temp), 60, PRIVATE);

…but the CLI indicates that the old event (temp) is still firing every ~16 seconds. Unfortunately, it’s off site. I’ll check it out this weekend and report back.

Does it say flash successful.....? You can watch` for events that are published when an update is happening.

Be sure to also select the correct device in the devices tab :wink:

Didn’t even know that existed! Awesome. It does say “Flash successful!” but the dashboard reveals the spark/flash/status event gets { "data": "failed" } in the response body.

spock interesting


Haha! That’s a little bug but i think your firmware has been flashed properly.

Did the published event name changed You should be able to see the eventstream in the dashboard and which device published it.

Thanks for sticking with me, here. Nice bug! Unfortunately, the event name didn’t change. I get:

  • hook-response/temp/0
  • hook-sent/temp
  • temp

I wonder what happens when I clear’s “cache”…

Update: clearing cache didn’t help.

hmmmm? The device is publishing a message to trigger a webhook i guess?

Can you place a Particle.publish("test", "213231") in setup() just to be sure the latest firmware is flashed and this line runs?

Did you see the event temp getting published in the dashboard?

Okay, added a test event to setup() suggested. Then:

No test event fired. Old event name is back. Interesting.

Ha…You might want to share your code…

Totally forgot about this thread. Turned out, the WiFi connection was super flakey, and flashing via the Web IDE was never successful. I moved Particle next to the router, flashed, then moved it back to the testing location. All’s good!