-
Notifications
You must be signed in to change notification settings - Fork 511
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
Fixes Particle.connect() behavior in SEMI_AUTOMATIC mode #1403
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -407,17 +407,26 @@ void manage_safe_mode() | |
} | ||
} | ||
|
||
bool semi_automatic_connecting(bool threaded) { | ||
return system_mode() == SEMI_AUTOMATIC && !threaded && spark_cloud_flag_auto_connect() && !spark_cloud_flag_connected(); | ||
} | ||
|
||
void app_loop(bool threaded) | ||
{ | ||
DECLARE_SYS_HEALTH(ENTERED_WLAN_Loop); | ||
if (!threaded) | ||
Spark_Idle(); | ||
|
||
static uint8_t SPARK_WIRING_APPLICATION = 0; | ||
do { | ||
if(threaded || SPARK_WLAN_SLEEP || !spark_cloud_flag_auto_connect() || spark_cloud_flag_connected() || SPARK_WIRING_APPLICATION || (system_mode()!=AUTOMATIC)) | ||
{ | ||
if(threaded || !SPARK_FLASH_UPDATE) | ||
{ | ||
if (semi_automatic_connecting(threaded)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The diff isn't so clear in github, but logically, I imagine this is the primary change - to not invoke loop while connecting in semi-automatic mode. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct. https://github.com/spark/firmware/pull/1403/files?w=1 gives a bit better diff |
||
break; | ||
} | ||
|
||
if ((SPARK_WIRING_APPLICATION != 1)) | ||
{ | ||
//Execute user application setup only once | ||
|
@@ -428,6 +437,9 @@ void app_loop(bool threaded) | |
#if !(defined(MODULAR_FIRMWARE) && MODULAR_FIRMWARE) | ||
_post_loop(); | ||
#endif | ||
if (semi_automatic_connecting(threaded)) { | ||
break; | ||
} | ||
} | ||
|
||
//Execute user application loop | ||
|
@@ -441,6 +453,7 @@ void app_loop(bool threaded) | |
} | ||
} | ||
} | ||
} while(false); | ||
#if PLATFORM_ID == 3 && SUSPEND_APPLICATION_THREAD_LOOP_COUNT | ||
// Suspend thread execution for some minimum time on every Nth loop iteration in order to workaround | ||
// 100% CPU usage on the virtual device platform | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#include "application.h" | ||
|
||
SYSTEM_MODE(SEMI_AUTOMATIC); | ||
SYSTEM_THREAD(DISABLED); | ||
|
||
LOG_SOURCE_CATEGORY("test") | ||
|
||
namespace { | ||
|
||
SerialLogHandler logHandler(LOG_LEVEL_NONE, { | ||
{ "test", LOG_LEVEL_ALL } | ||
}); | ||
|
||
static bool loopExecuted = false; | ||
static bool testFinished = false; | ||
|
||
static void fail() { | ||
testFinished = true; | ||
RGB.control(true); | ||
RGB.color(0xff0000); // Red | ||
LOG(ERROR, "TEST FAILED"); | ||
} | ||
|
||
static void pass() { | ||
testFinished = true; | ||
RGB.control(true); | ||
RGB.color(0x00ff00); // Green | ||
LOG(INFO, "TEST SUCCEEDED"); | ||
} | ||
|
||
} // namespace | ||
|
||
void setup() { | ||
waitUntil(Serial.isConnected); | ||
|
||
LOG(INFO, "Test started"); | ||
LOG(INFO, "Connecting to WiFi network"); | ||
WiFi.on(); | ||
WiFi.connect(); | ||
waitUntil(WiFi.ready); | ||
LOG(INFO, "Connected to WiFi network"); | ||
|
||
LOG(INFO, "Connecting to the cloud"); | ||
Particle.connect(); | ||
if (Particle.connected()) { | ||
fail(); | ||
} | ||
} | ||
|
||
void loop() { | ||
if (testFinished) { | ||
return; | ||
} | ||
|
||
if (!loopExecuted) { | ||
loopExecuted = true; | ||
|
||
// First time the loop is running. We should be connected to the cloud | ||
if (!Particle.connected()) { | ||
fail(); | ||
return; | ||
} | ||
|
||
LOG(INFO, "Connected to the cloud"); | ||
|
||
// Disconnect from the cloud | ||
LOG(INFO, "Disconnecting from the cloud"); | ||
Particle.disconnect(); | ||
waitUntil(Particle.disconnected); | ||
LOG(INFO, "Disconnected from the cloud"); | ||
|
||
LOG(INFO, "Connecting to the cloud"); | ||
Particle.connect(); | ||
} else { | ||
// Second time the loop is running, we should also be connected to the cloud again | ||
if (!Particle.connected()) { | ||
fail(); | ||
return; | ||
} | ||
LOG(INFO, "Connected to the cloud"); | ||
|
||
pass(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the purpose of the do/while(false) - isn't it the same as a regular block?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to short-circuit the execution at line https://github.com/spark/firmware/pull/1403/files#diff-17aa9c74822820227ce1b5db3aab8d76R527 We can change that to
goto
if it looks better :)