Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Particle.connect() should not allow loop() to run until Particle.connected() is true #973

Closed
technobly opened this issue Apr 20, 2016 · 2 comments · Fixed by #1145

Comments

@technobly
Copy link
Member

commented Apr 20, 2016

Particle.connect() should not allow loop() to run until Particle.connected() is true

See issue particle-iot/docs#367 in Docs, make sure to update behavior when resolved.

Test App compiled with v0.5.0-rc.2 on Photon

SYSTEM_MODE(SEMI_AUTOMATIC);

void setup() {
    pinMode(D7, OUTPUT);
    digitalWrite(D7, LOW);
    Particle.connect();
}

void loop() {
    digitalWrite(D7, HIGH);
    // D7 LED should not light until Particle.connected() is true, but it does.
}

Completeness:

  • Minimum test case added
  • Device, system and user firmware versions stated
  • Particle confirmed

@technobly technobly added the bug label Apr 20, 2016

@technobly technobly added this to the 0.6.x milestone Apr 20, 2016

@m-mcgowan

This comment has been minimized.

Copy link
Contributor

commented Jun 7, 2016

I hear your case, but I don't feel this is a bug. That's the intended behavior of SEMI_AUTOMATIC mode, that the system always runs setup then loop, independently of the cloud connection state.

If it were AUTOMATIC mode then loop shouldn't run until connected, and that is indeed the case.

A simple workaround is to add this in setup()

    Particle.connect();
    waitUntil(Particle.connected);

To so summarize - the behavior is by design that semi-automatic mode doesn't stop the loop from running when the device isn't connected.

The situation would be the same with multithreaded code too - the setup()/loop() functions execute independently of the cloud state. In cases where the app wants to wait for the device to be in a given state, the waitFor function is always ready for duty!

The Particle.connect()/disconnect() calls are not themselves blocking - they just set flags. These flags do affect what happens next time the background loop is executed, and that is when any delay is experienced (in single-threaded mode) to connect to the cloud.

@m-mcgowan m-mcgowan added the question label Jun 7, 2016

@technobly technobly removed this from the 0.6.x milestone Aug 9, 2016

@m-mcgowan

This comment has been minimized.

Copy link
Contributor

commented Sep 13, 2016

On review, I think your suggestion is the ideal behavior - in SEMI_AUTOMATIC mode, loop/setup should not be run until the cloud is connected while Particle.connect() has been called. But not in MANUAL mode - there setup and loop run freely independently of the cloud state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.