Slow initialization. Cloud Functions and variables


Hey guys,

I have a bunch of cloud function and variables in my code and they take about 4seconds to initialize in the setup function. Which is much longer than it did on the photon. (currently using P1)

Anyone know a fix/


We can’t really help unless you can show us your code.


Hey I realised what it was,
I had SystemThread enabled, which runs user code before connecting, so these fucntions/variables take time so the program gets “stuck” until it connects to the cloud.

I put the particle variable and function in a different function (they only intialize after the Particle.connected is true)


This should not be necessary. Registration of functions and variables should be independent of connection status. It’s even recommended to set them up before the connection gets established.
If this behaviour has changed, I’d call it a regression which should be undone.

What Device OS version are you targeting?


This was done on the 0.7.0 version. I use to have the functions and variables in setup before i wrote this post and it use to work fine. But after around the day i made this thread, it started to wait for the regitration to happen before the main loop could be started.


I have now tested your assertion but couldn’t reproduce what you are saying - but due to the lack of a P1 device I did it on a Photon (although there should not be any difference in this regard between the two).

This is what I did

//SYSTEM_THREAD(ENABLED)             // test-option
//SYSTEM_MODE(SEMI_AUTOMATIC)        // test-option

    pinMode(D7, OUTPUT);
//    digitalWrite(D7, HIGH);       // test-option

int a;

void setup() {
    Particle.connect();            // test-option
    waitUntil(Particle.connected); // test-option 
    digitalWrite(D7, HIGH);        // test-option

    Particle.function("test", test);
    Particle.function("test1", test);
    Particle.function("test2", test);
    Particle.function("test3", test);
    Particle.function("test4", test);
    Particle.function("test5", test);
    Particle.function("test6", test);
    Particle.variable("var", a);
    Particle.variable("var1", a);
    Particle.variable("var2", a);
    Particle.variable("var3", a);
    Particle.variable("var4", a);
    Particle.variable("var5", a);
    Particle.variable("var6", a);
    digitalWrite(D7, LOW);

void loop() {

int test(String arg) {
    return 0;

I’ve tried all sorts of combinations of the lines marked // test-option

Can you post a test code that exhibits your reported symptoms?