Help needed connecting to cloud using SYSTEM_MODE(MANUAL)

I am trying to use SYSTEM_MODE(MANUAL) and then Particle.connect() in setup(). When viewing the console.particle.io I see my data being published but functions and variables do not appear even after after refreshing them. Also pinging my device from the console fails. Yet, my publishes keep being displayed.
I had this type of connection working 5 or 6 weeks ago but tried to make some changes yesterday and can’t get it to work.

Any help is appreciated.

I am using an Electron, Asset Tracker 2, compiling with --target 0.6.2.

Here is my code reduced to a simple test. The calls to Particle.function() and Particle.variable() both return true. I tried making the calls after Particle.connect() and before with the same results.

Thanks.
Lynd

// Test for registering functions using manual connect.
SYSTEM_MODE(MANUAL)

int myVariable = 123;

int foo(String s)
{
    Serial.println(s);
    return 1;
}
void setup()
{

    Serial.begin(9600);
    // wait for monitor connection
    delay(10000);
    if ( Particle.function("foo", foo) == false){
	    Serial.println("Particle.function returned false");
    } else {
	    Serial.println("Particle.function returned true");
    }
    if ( Particle.variable("var", myVariable) == false){
	    Serial.println("Particle.function returned false");
    } else {
	     Serial.println("Particle.function returned true");
    }
    Serial.println("Calling connect...");
    Particle.connect();
    Serial.println("Back from calling connect");
}


unsigned long lastPublish = 0;
unsigned long delaymillis = 10000;

void loop() {
    unsigned long now;
    String nowstr;
    now = millis();
    if ((now - lastPublish) > delaymillis ){
	    nowstr = String::format("%d", now);
	    Particle.publish("now", nowstr);
	    Serial.println(nowstr);
	    lastPublish = millis();
    }
}

Hmm, actually this should work as you have it there. I’d have to see for myself.
But just to state the fact, Particle functions and variables need to be registered before or shortly after the connection gets established (but you do anyway :confused:)
For good measure I’d explicitly add a WiFi.on() statement.

Well, I found a work-around but I would still like to know what is going on.
I added a call to Particle.process() to loop() and now it works perfectly.

In trying to figure it out, I tried putting just one call to Particle.process at the end of setup() and none in loop() but that didn’t fix it.

(My Electron has cellular and no wifi. Adding Cellular.on() made no difference.)

Doh' - sure. What you found as workaraound is actually required. Sorry for missing that.

https://docs.particle.io/reference/firmware/photon/#manual-mode

If you only want to control connect/disconnect you may want to opt for SEMI_AUTOMATIC mode