Publish test code only prints empty lines

When I flash publishme.ino from the sample library and watch the stream from a terminal using
I see “:ok” and then no text but carriage returns are advancing the cursor. There is nothing in the console window either.
How do I troubleshoot this?

// publishme.ino -- Spark Publishing Example 
unsigned long lastTime = 0UL;
char publishString[40];

void setup() {

void loop() {
    unsigned long now = millis();
    //Every 15 seconds publish uptime
    if (now-lastTime>15000UL) {
        lastTime = now;
        // now is in milliseconds
        unsigned nowSec = now/1000UL;
        unsigned sec = nowSec%60;
        unsigned min = (nowSec%3600)/60;
        unsigned hours = (nowSec%86400)/3600;

What system version are you using?

Firmware 0.7.0

For me your code does produce the expected output just fine

Have you checked the output on

However, I’d slightly change it this way

        snprintf(publishString, sizeof(publishString), "%02u:%02u:%02u", hours, min, sec);
        Particle.publish("Uptime", publishString, PRIVATE);
  • snprintf() is safer since it won’t inadvertently overflow your buffer.
  • "%02u" will give you the commonly used time format with leading zeros: image
  • Spark is outdated and now called Particle
  • PRIVATE: you should not publish to the PUBLIC event stream without good reason and with 0.8.0 this parameter will be compulsory
1 Like

Great suggestions. The code now works.
I see regular Uptime entries on the console and in a terminal with the curl command.

Thanks for your help.