Default Threaded Behavior

This is probably a first for the Community, but I am wondering why the following works?

I am developing an application with RFID cards. I copied some example code out of the Arduino world that is structured as follows:

loop() {
while( … ) { // wait for an RFID card to be presented
}
// execute some RFID card interaction code here
}

I neglected to explicitly enable the system thread, and yet this code does not crash, even after 15 hours stuck in the tight while() loop. My question is: why does this not crash? My understanding is that the default is for the system thread to be disabled and therefore loop() must complete periodically or else the cloud connection will be lost. But this isn’t happening in my Photon based test setup. The code executes fine and the cloud connection is maintained (at least, the Photon is breathing cyan, the code is executing fine, the Photon shows up as cloud connected in the IDE and Console, etc).

Has the default for threaded operation changed? Also, if I port this code over to an Argon to do the same task while also operating as a Mesh gateway, will this structure hinder Mesh operations? Will explicitly enabling the system thread be helpful, or is this the new default anyway?

Why should it?
We don’t see enough of your code to advise.

1 Like

@ScruffR: my understanding is that cloud connectivity should be lost if loop() is not completed periodically. The tight while() loop inside of loop() prevents this from happening if no RFID card is presented (say for many hours). Yet, cloud connectivity seems to continue, even though the system thread is not enabled (at least, not explicitly). That is what I don’t understand.

The full code is at:

You would need a PN532 based RFID reader (with I2C interface) and a Classic 1K RFID card in order to fully exercise this code, however.

It’s because Adafruit_PN532::readPassiveTargetID() calls Adafruit_PN532::readdata(), which calls delay(), which services the cloud connection when in non-threaded mode.

1 Like

Ahhhhh – that clarifies it nicely. Now I understand that cloud connections are maintained during delay(). I did not know that previously. Makes sense, tho …

@bobg you should mark this ticket as solved.