Argon - Particle.connect() seems to be not working

Hello everyone,

I have an Argon running a very simple test code that toggles the WiFi module every 30 seconds and toggles an LED whenever the Argon is connected to WiFi, but for some reason the Argon remains breathing white even after calling Particle.connect()

If I reset the Argon it connects immediately and starts breathing cyan, but as soon as the 30 seconds pass it will disconnect from WiFi, start breathing white and will no longer connect (I know the code “flow” works because I see how the LED starts blinking again even though the Argon isn’t trying to connect.

Am I missing something? I’ve just started working with mesh products so any help will be much appreciated.

Here is the code I am testing:

Timer ledTimer(1000, toggleLed);
Timer connectionTimer(30000, toggleConnection);

int ledState;
int connectionState;
boolean updateConnection;

void toggleLed() {
    ledState = 1 - ledState;
}

void toggleConnection() {
    updateConnection = true;
}

void setup() {
    pinMode(D7, OUTPUT);
    
    ledTimer.start();
    connectionTimer.start();
    ledState = 0;
    connectionState = 1;
    updateConnection = false;
}

void loop() {
    if(ledState == 1 && connectionState == 1) {
        digitalWrite(D7, HIGH);
    }
    else {
        digitalWrite(D7, LOW);
    }
    
    if(updateConnection == true) {
        updateConnection = false;
        
        if(connectionState == 0) {
            connectionState = 1;
            Particle.connect();
            
        }
        else {
            connectionState = 0;
            Particle.disconnect();
            WiFi.off();
        }
    }

}

I think this was an oversight, but currently Particle.connect() does not power up the radio module. You should do that explicitly via WiFi.on().
If you only call Particle.disconnect() or even WiFi.disconnect() Particle.connect() should do its job just right.
Consequently I’d not say that Particle.connect() is not working, it’s just not doing all the other things the same command does on previous devices :wink:

I have filed a GitHub issue for that

4 Likes

Hi! Thank you for your quick response, and I apologize for my late one.

Following up on your reply, calling WiFi.on() before Particle.connect() leaves the RGB LED breathing blue (not cyan). I could not find this mode in the docs, but Particle.connected() returns false. To get the Argon to successfully reconnect I had to call WiFi.connect() instead.

I find this behavior a little weird, I would have expected Particle.connect() to behave exactly as it did on previous generation devices. I am currently updating a firmware that can handle both Photons/Electrons, and now I’ll have to add rules for Argons and possibly Borons separately as well.

Anyways, thanks a lot! I really appreciate your help :grinning:

2 Likes

Hi @morduno, speaking of writing platform-specific instructions into shared code, are you aware of a simple way to identify the platform (Argon vs Boron vs Electron) during runtime for conditional logic? I just starting looking into this once I realized the Argon was going to require unique things and thought maybe you’d already researched. Thanks for any tips, Sam

You can check PLATFORM_ID during runtime too as it will just be expanded into its numeric value.
But if you need specific code that would be best handled at compile time.

Platform IDs:

PLATFORM_SPARK_CORE                 0
PLATFORM_SPARK_CORE_HD              2
PLATFORM_PHOTON_PRODUCTION          6
PLATFORM_P1                         8
PLATFORM_ELECTRON_PRODUCTION        10
PLATFORM_ARGON			            12
PLATFORM_BORON		               	13
PLATFORM_XENON			            14
2 Likes