Particle variable and function are not shown in Console if USB serial is enabled

Hi,

I am working with threads and I also have the SYSTEM_THREAD(ENABLED); at the top of the code.

I have a define for uart debugging with USB, and when I enable the debugging then in the console I cannot see the variables that I expose through Particle.variable( … ) and Particle.function( … ).

When I comment the serial debugging then I can normally see the functions and variables.

When debug is enabled, I can see through my serial communication that the Particle.variable and Particle.function calls in the setup are successful.

Just for completeness, here is the macro:

    #define SERIAL_DEBUG
    #ifdef SERIAL_DEBUG
    #define debug_print   Serial.printf
    #else
    #define debug_print   //
    #endif

and here is the setup:
    void setup() {
        waitUntil(Particle.connected);
        pinMode(LED, OUTPUT);

    #ifdef SERIAL_DEBUG
        Serial.begin(115200);
        while(!Serial.isConnected());
        delay(5000);
    #endif

        debug_print("Particle is connected\n");

        Particle.function("OnOffValve", OnOffValve);
        Particle.function("valveStatus", valveStatus);

        Particle.variable("temp", temp);
        Particle.variable("distance", d_pars.distance);

        read_temp_thread = new Thread("read_temp", read_temp_task, 0);
        start_distance_measurement_thread = new Thread("start_distance measurement", start_distance_measurement_task, 0);
        server_listen_thread = new Thread("server_listen", server_listen_task, 0);
    }

Any ideas? Thanks,
Vasileios.

@kostbill, Particle variables and functions must be declared within a certain time window after setup() starts. If you move your declarations BEFORE the serial code, everything should work.

2 Likes

Thanks for the reply!

I will try that as soon as I get home.

By the way, shouldn’t this be part of the documentation? Or it is and I just didn’t find it?

Thanks,
Vasileios.

Thanks, it worked !

Thanks again!

How do I declare this as solved?

1 Like