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

Breaks network on-going network connection when Sleep stop mode is called #1125

Merged
merged 1 commit into from Oct 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion hal/src/photon/wlan_hal.cpp
Expand Up @@ -322,7 +322,8 @@ wlan_result_t wlan_activate()
wlan_result_t wlan_deactivate()
{
wlan_disconnect_now();
return 0;
wiced_result_t result = wiced_wlan_connectivity_deinit();
return result;
}

wlan_result_t wlan_disconnect_now()
Expand Down
9 changes: 7 additions & 2 deletions system/src/system_sleep.cpp
Expand Up @@ -23,6 +23,7 @@
#include "system_task.h"
#include "system_cloud.h"
#include "system_cloud_internal.h"
#include "system_network_internal.h"
#include "system_threading.h"
#include "rtc_hal.h"
#include "core_hal.h"
Expand All @@ -43,10 +44,12 @@ WakeupState wakeupState;

static void network_suspend() {
// save the current state so it can be restored on wakeup
wakeupState.wifi = !SPARK_WLAN_SLEEP;
wakeupState.wifiConnected = wakeupState.cloud | network_ready(0, 0, NULL) | network_connecting(0, 0, NULL);
#ifndef SPARK_NO_CLOUD
wakeupState.cloud = spark_cloud_flag_auto_connect();
#endif
wakeupState.wifi = !SPARK_WLAN_SLEEP;
wakeupState.wifiConnected = wakeupState.cloud || network_ready(0, 0, NULL) || network_connecting(0, 0, NULL);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've noticed that wakeupState.cloud was used before initialization previously.

#ifndef SPARK_NO_CLOUD
// disconnect the cloud now, and clear the auto connect status
spark_cloud_socket_disconnect();
spark_cloud_flag_disconnect();
Expand Down Expand Up @@ -173,5 +176,7 @@ int system_sleep_pin_impl(uint16_t wakeUpPin, uint16_t edgeTriggerMode, long sec
*/
void system_sleep_pin(uint16_t wakeUpPin, uint16_t edgeTriggerMode, long seconds, uint32_t param, void* reserved)
{
// Cancel current connection attempt to unblock the system thread
network.connect_cancel(true);
system_sleep_pin_impl(wakeUpPin, edgeTriggerMode, seconds, param, reserved);
}
42 changes: 42 additions & 0 deletions user/tests/app/stop_mode_power_usage_issue_1098/app.cpp
@@ -0,0 +1,42 @@
#include "application.h"

#define MIN_CONNECT_DURATION 1000 // Milliseconds
#define MAX_CONNECT_DURATION 5000
#define SLEEP_DURATION 5 // Seconds

SYSTEM_MODE(MANUAL)
SYSTEM_THREAD(ENABLED)

namespace {

SerialLogHandler logHandler(LOG_LEVEL_WARN, { // Default logging level
{ "app", LOG_LEVEL_ALL } // Logging level for application messages
});

uint32_t t = 0, d = 0;

void resetTimer() {
d = rand() % (MAX_CONNECT_DURATION - MIN_CONNECT_DURATION) + MIN_CONNECT_DURATION;
t = millis();
}

} // namespace

void setup() {
// Set incorrect WiFi credentials to cause repeated connection attempts
WiFi.on();
WiFi.clearCredentials();
WiFi.setCredentials("param-pam-pam");
WiFi.connect();
resetTimer();
}

void loop() {
if (millis() - t >= d) {
LOG(INFO, "Entering stop mode");
// The current taken by the device should be around 3 mA when the stop mode is active
System.sleep(D1, RISING, SLEEP_DURATION);
LOG(INFO, "Leaving stop mode");
resetTimer();
}
}