@@ -30,6 +30,8 @@ static retained uint32_t phase = 0;
3030
3131constexpr system_tick_t CLOUD_CONNECT_TIMEOUT = 10 * 60 * 1000 ;
3232
33+ time32_t sNetworkOffTimestamp = 0 ;
34+
3335} // anonymous
3436
3537test (01_System_Sleep_With_Configuration_Object_Hibernate_Mode_Without_Wakeup) {
@@ -622,7 +624,7 @@ test(24_System_Sleep_With_Configuration_Object_Ultra_Low_Power_Mode_Wakeup_By_Ce
622624#endif
623625#endif // HAL_PLATFORM_CELLULAR
624626
625- #if HAL_PLATFORM_WIFI
627+ #if HAL_PLATFORM_WIFI && HAL_PLATFORM_GEN == 3
626628test (25_System_Sleep_With_Configuration_Object_Stop_Mode_Wakeup_By_WiFi) {
627629 Serial.println (" >> Device enters stop mode. Please reconnect serial after waking up by network data" );
628630 Serial.println (" >> Press any key now" );
@@ -648,7 +650,6 @@ test(25_System_Sleep_With_Configuration_Object_Stop_Mode_Wakeup_By_WiFi) {
648650 assertEqual ((int )result.wakeupReason (), (int )SystemSleepWakeupReason::BY_NETWORK);
649651}
650652
651- #if HAL_PLATFORM_GEN == 3
652653test (26_System_Sleep_With_Configuration_Object_Ultra_Low_Power_Mode_Wakeup_By_WiFi) {
653654 Serial.println (" >> Device enters ultra-low power mode. Please reconnect serial after waking up by network data" );
654655 Serial.println (" >> Press any key now" );
@@ -673,10 +674,17 @@ test(26_System_Sleep_With_Configuration_Object_Ultra_Low_Power_Mode_Wakeup_By_Wi
673674 assertEqual (result.error (), SYSTEM_ERROR_NONE);
674675 assertEqual ((int )result.wakeupReason (), (int )SystemSleepWakeupReason::BY_NETWORK);
675676}
676- #endif
677- #endif // HAL_PLATFORM_WIFI
677+ #endif // HAL_PLATFORM_WIFI && HAL_PLATFORM_GEN == 3
678678
679- test (27_System_Sleep_With_Configuration_Object_Stop_Mode_Execution_Time) {
679+ test (27_System_Sleep_With_Configuration_Object_Execution_Time_Prepare) {
680+ System.on (network_status, [](system_event_t ev, int data) -> void {
681+ if (ev == network_status && data == network_status_off) {
682+ sNetworkOffTimestamp = Time.now ();
683+ }
684+ });
685+ }
686+
687+ test (28_System_Sleep_With_Configuration_Object_Stop_Mode_Execution_Time) {
680688 constexpr uint32_t SLEEP_DURATION_S = 3 ;
681689 Serial.printf (" >> Device enters stop mode. Please reconnect serial after %ld s\r\n " , SLEEP_DURATION_S);
682690 Serial.println (" >> Press any key now" );
@@ -688,23 +696,22 @@ test(27_System_Sleep_With_Configuration_Object_Stop_Mode_Execution_Time) {
688696 Serial.println (" >> Connecting to the cloud" );
689697 Network.on ();
690698 Particle.connect ();
691- waitFor (Particle.connected , CLOUD_CONNECT_TIMEOUT);
692- assertTrue (Particle.connected ());
699+ assertTrue (waitFor (Particle.connected , CLOUD_CONNECT_TIMEOUT));
693700 Serial.println (" >> Connected to the cloud. You'll see the RGB is turned on after waking up." );
694701
695702 SystemSleepConfiguration config;
696703 config.mode (SystemSleepMode::STOP)
697704 .duration (SLEEP_DURATION_S * 1000 );
698705
699- time32_t enter = Time. now () ;
706+ sNetworkOffTimestamp = 0 ;
700707 SystemSleepResult result = System.sleep (config);
701708 time32_t exit = Time.now ();
702709
703710 waitUntil (Serial.isConnected );
704- assertMoreOrEqual (exit - enter, SLEEP_DURATION_S );
705- // There might be up to 30s delay to turn off the modem for particular platforms.
706- assertLessOrEqual (exit - enter, 30 + SLEEP_DURATION_S );
707- Serial.printf (" Sleep execution time: %ld s\r\n " , exit - enter );
711+ assertNotEqual ( sNetworkOffTimestamp , 0 );
712+ assertMoreOrEqual (exit - sNetworkOffTimestamp , SLEEP_DURATION_S);
713+ assertLessOrEqual (exit - sNetworkOffTimestamp , SLEEP_DURATION_S * 3 / 2 );
714+ Serial.printf (" Sleep execution time: %ld s\r\n " , exit - sNetworkOffTimestamp );
708715
709716 assertEqual (result.error (), SYSTEM_ERROR_NONE);
710717 assertEqual ((int )result.wakeupReason (), (int )SystemSleepWakeupReason::BY_RTC);
@@ -713,7 +720,7 @@ test(27_System_Sleep_With_Configuration_Object_Stop_Mode_Execution_Time) {
713720 assertTrue (waitFor (Particle.connected , CLOUD_CONNECT_TIMEOUT));
714721}
715722
716- test (28_System_Sleep_With_Configuration_Object_Ultra_Low_Power_Mode_Wakeup_Execution_Time ) {
723+ test (29_System_Sleep_With_Configuration_Object_Ultra_Low_Power_Mode_Wakeup_Execution_Time ) {
717724 constexpr uint32_t SLEEP_DURATION_S = 3 ;
718725 Serial.printf (" >> Device enters ultra-low power mode. Please reconnect serial after %ld s\r\n " , SLEEP_DURATION_S);
719726 Serial.println (" >> Press any key now" );
@@ -725,23 +732,22 @@ test(28_System_Sleep_With_Configuration_Object_Ultra_Low_Power_Mode_Wakeup_Execu
725732 Serial.println (" >> Connecting to the cloud" );
726733 Network.on ();
727734 Particle.connect ();
728- waitFor (Particle.connected , CLOUD_CONNECT_TIMEOUT);
729- assertTrue (Particle.connected ());
735+ assertTrue (waitFor (Particle.connected , CLOUD_CONNECT_TIMEOUT));
730736 Serial.println (" >> Connected to the cloud. You'll see the RGB is turned on after waking up." );
731737
732738 SystemSleepConfiguration config;
733739 config.mode (SystemSleepMode::ULTRA_LOW_POWER)
734740 .duration (SLEEP_DURATION_S * 1000 );
735741
736- time32_t enter = Time. now () ;
742+ sNetworkOffTimestamp = 0 ;
737743 SystemSleepResult result = System.sleep (config);
738744 time32_t exit = Time.now ();
739745
740746 waitUntil (Serial.isConnected );
741- assertMoreOrEqual (exit - enter, SLEEP_DURATION_S );
742- // There might be up to 30s delay to turn off the modem for particular platforms.
743- assertLessOrEqual (exit - enter, 30 + SLEEP_DURATION_S );
744- Serial.printf (" Sleep execution time: %ld s\r\n " , exit - enter );
747+ assertNotEqual ( sNetworkOffTimestamp , 0 );
748+ assertMoreOrEqual (exit - sNetworkOffTimestamp , SLEEP_DURATION_S);
749+ assertLessOrEqual (exit - sNetworkOffTimestamp , SLEEP_DURATION_S * 3 / 2 );
750+ Serial.printf (" Sleep execution time: %ld s\r\n " , exit - sNetworkOffTimestamp );
745751
746752 assertEqual (result.error (), SYSTEM_ERROR_NONE);
747753 assertEqual ((int )result.wakeupReason (), (int )SystemSleepWakeupReason::BY_RTC);
0 commit comments