Some help with Cellular.connect() please

Hi -

I need some (more) help please :slight_smile: The idea is to completely turn off the GSM radio (and most other peripherals on the PCB when the device is going into ULP mode to preserve battery life, hence two separate regulators on the PCB.

The process then is to start up, check everything and publish, then shut down everything but the uC and external RTC (Abracon) by turning off the second regulator. All of this seems to be working, but when starting back up, my question is ho to tell the uC to “wait” until the device is connected before publishing an event. I am testing with this simple fuel gauge reading, but it works once, shuts dow, starts back up but does not publish. I think I can see why, just not sure how to fix it :slight_smile: If I add a longer delay, giving the modem time to connect, before the Particle.publish() command it works, but does not seem like the best way to do things.

void Fuel_Gauge() {
    
    digitalWrite (D4, HIGH);  // Peripherals Regulator EN pin
    delay(500);

    if (Cellular.ready() == true) {
        
        Particle.publish("Capacity: " + String(gauge.getCapacity()) + "mAh", PRIVATE);
        delay(500);

        Particle.publish("VCELL: " + String(gauge.getVoltage()) + "mV", PRIVATE);
        delay(500);
        
        Particle.disconnect(CloudDisconnectOptions().graceful(true).timeout(5s)); // Newly added, found this in the reference docusments and seemed like a good idea to add?? 
        Cellular.disconnect();

        Cellular.disconnect();
        
        delay(1000);
        digitalWrite (D4, LOW);
        
    } else {}
    
//    Particle.publish("DONE - waiting 60sec", PRIVATE);
    
    delay(120000);
}

I know I should use timers instead of delays, but will get to that still… baby steps :slight_smile:

Regards, Friedl.

Have you tried one of these?

2 Likes

Hi @ScruffR -

Oh wow, thanks, will have a look. I tried searching for wait - ‘just-about-anything’ but had no results. I will try these now. Was about to try the following while loop but will first look at this.

void Fuel_Gauge() {
    
    digitalWrite (D4, HIGH); 
    
        while (Cellular.ready() == false) {
   
    } else {
        
        Particle.publish("Capacity: " + String(gauge.getCapacity()) + "mAh", PRIVATE);
        delay(1000);
    }

        delay(1000);
        digitalWrite (D4, LOW);

    delay(120000);
}

Pretty sure it wasn’t going to work… haha.

Regards, Friedl.

Hi @ScruffR -

Thanks, seem to work like a charm! Will let it run for a bit and see. Here is my code;

void Fuel_Gauge() {
    
    digitalWrite (D4, HIGH); 
    
    Particle.connect();
    waitUntil(Particle.connected);
    
    Particle.publish("Capacity: " + String(gauge.getCapacity()) + "mAh", PRIVATE);
    delay(1000);
   
    Particle.disconnect(CloudDisconnectOptions().graceful(true).timeout(5s));
    Cellular.disconnect();

    digitalWrite (D4, LOW);
    
//    Particle.publish("DONE - waiting 120sec", PRIVATE);
    
    delay(120000);
}

Just one question if you don’t mind… The following seem to put the device in listen mode (breathing dark blue), is this to be expected?

Particle.disconnect(CloudDisconnectOptions().graceful(true).timeout(5s));
    Cellular.disconnect();

It does however come out of it after the 120s delay.

Regards,
Frield.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.