I’m running a cloud disabled system and had a small doubt.
Does my loop() need some sort of delay? I can’t seem to trace how functions like SPARK_WLAN_Loop() get called otherwise once I am connected (I see them getting called while it’s being setup). I’m reading through the main.cpp and how the application loop() gets called.
To be fair I am seeing the light change with connection and disconnection, but I just don’t see how this SPARK_WLAN_Loop is getting called in a connected mode with a tight (no delay) loop.
thanks - I’ve been following those flags (I’m reading through main) but I still don’t see how if I am connected and not in setup SPARK_WLAN_Loop gets called:
I’m not entirely sure, so please correct me if I’m wrong. The way I understood it was as following: the whole Spark firmware runs as a continuous loop. Inside that loop is your sketch, which can loop as well. By defining whether or not to enable/disable wifi (or other settings for that matter) inside your sketch, you’re actually toggling them on/off inside the firmware loop.
That’s my general concept of how it works, but as I’ve said, I could be wrong.
I think I might have misread this SPARK_WLAN_SETUP as a variable showing if we are in a sort of “setup” mode, it seems on closer reading to represent that we are already setup so main makes more sense. I think these logic variable can be a little tricky to parse as some seems to be flags, others are state.
If you are wondering how the RGB led is updated if you are Cloud disabled, it gets updated via a background Interrupt Service Routine. This has nothing to do with SPARK_WLAN_Loop();
Speaking of that though… here’s some code that’s useful if you are doing serial debugging and bouncing back and fourth between cloud enabled and cloud disabled:
// Uncomment to disable the WiFi and ultimately the Cloud connection as well
//#include "spark_disable_wlan.h"
void setup(void) {
Serial.begin(115200); // Make sure your serial terminal is closed before power the Core.
while(!Serial.available()) { // Open serial terminal and Press ENTER.
#ifdef SPARK_WLAN_SETUP
SPARK_WLAN_Loop(); // Only process b/g tasks if the WiFi is enabled
#endif
}
Serial.print("Hello, Sparky!");
}