@@ -57,6 +57,12 @@ StaticTask_t driverRsiTaskBuffer;
57
57
/* Declare a variable to hold the data associated with the created event group. */
58
58
StaticEventGroup_t rsiDriverEventGroup ;
59
59
60
+ /* Declare a flag to differentiate between after boot-up first IP connection or reconnection */
61
+ static bool is_wifi_disconnection_event = false;
62
+
63
+ /* Declare a variable to hold connection time intervals */
64
+ static uint32_t retryInterval = WLAN_MIN_RETRY_TIMER_MS ;
65
+
60
66
bool hasNotifiedIPV6 = false;
61
67
#if (CHIP_DEVICE_CONFIG_ENABLE_IPV4 )
62
68
bool hasNotifiedIPV4 = false;
@@ -162,12 +168,9 @@ static void wfx_rsi_join_cb(uint16_t status, const uint8_t * buf, const uint16_t
162
168
* We should enable retry.. (Need config variable for this)
163
169
*/
164
170
WFX_RSI_LOG ("%s: failed. retry: %d" , __func__ , wfx_rsi .join_retries );
165
- #if (WFX_RSI_CONFIG_MAX_JOIN != 0 )
166
- if (++ wfx_rsi .join_retries < WFX_RSI_CONFIG_MAX_JOIN )
167
- #endif
168
- {
171
+ wfx_retry_interval_handler (is_wifi_disconnection_event , wfx_rsi .join_retries ++ );
172
+ if (is_wifi_disconnection_event || wfx_rsi .join_retries <= WFX_RSI_CONFIG_MAX_JOIN )
169
173
xEventGroupSetBits (wfx_rsi .events , WFX_EVT_STA_START_JOIN );
170
- }
171
174
}
172
175
else
173
176
{
@@ -180,6 +183,10 @@ static void wfx_rsi_join_cb(uint16_t status, const uint8_t * buf, const uint16_t
180
183
#else
181
184
xEventGroupSetBits (wfx_rsi .events , WFX_EVT_STA_CONN );
182
185
#endif
186
+ wfx_rsi .join_retries = 0 ;
187
+ retryInterval = WLAN_MIN_RETRY_TIMER_MS ;
188
+ if (is_wifi_disconnection_event )
189
+ is_wifi_disconnection_event = false;
183
190
}
184
191
}
185
192
@@ -195,9 +202,10 @@ static void wfx_rsi_join_cb(uint16_t status, const uint8_t * buf, const uint16_t
195
202
*********************************************************************/
196
203
static void wfx_rsi_join_fail_cb (uint16_t status , uint8_t * buf , uint32_t len )
197
204
{
198
- WFX_RSI_LOG ("%s: error: failed status: %02x on try %d " , __func__ , status , wfx_rsi . join_retries );
205
+ WFX_RSI_LOG ("%s: error: failed status: %02x" , __func__ , status );
199
206
wfx_rsi .join_retries += 1 ;
200
- wfx_rsi .dev_state &= ~WFX_RSI_ST_STA_CONNECTING ;
207
+ wfx_rsi .dev_state &= ~(WFX_RSI_ST_STA_CONNECTING | WFX_RSI_ST_STA_CONNECTED );
208
+ is_wifi_disconnection_event = true;
201
209
xEventGroupSetBits (wfx_rsi .events , WFX_EVT_STA_START_JOIN );
202
210
}
203
211
#ifdef RS911X_SOCKETS
@@ -420,39 +428,37 @@ static void wfx_rsi_do_join(void)
420
428
*/
421
429
wfx_rsi .dev_state |= WFX_RSI_ST_STA_CONNECTING ;
422
430
431
+ if ((status = rsi_wlan_register_callbacks (RSI_JOIN_FAIL_CB , wfx_rsi_join_fail_cb )) != RSI_SUCCESS )
432
+ {
433
+ WFX_RSI_LOG ("%s: RSI callback register join failed with status: %02x" , __func__ , status );
434
+ }
435
+
423
436
/* Try to connect Wifi with given Credentials
424
- * until there is a success or maximum number of tries allowed
437
+ * untill there is a success or maximum number of tries allowed
425
438
*/
426
- while (++ wfx_rsi .join_retries < WFX_RSI_CONFIG_MAX_JOIN )
439
+ while (is_wifi_disconnection_event || wfx_rsi .join_retries <= WFX_RSI_CONFIG_MAX_JOIN )
427
440
{
428
-
429
441
/* Call rsi connect call with given ssid and password
430
442
* And check there is a success
431
443
*/
432
-
433
444
if ((status = rsi_wlan_connect_async ((int8_t * ) & wfx_rsi .sec .ssid [0 ], (rsi_security_mode_t ) wfx_rsi .sec .security ,
434
445
& wfx_rsi .sec .passkey [0 ], wfx_rsi_join_cb )) != RSI_SUCCESS )
435
446
{
436
447
437
448
wfx_rsi .dev_state &= ~WFX_RSI_ST_STA_CONNECTING ;
438
449
WFX_RSI_LOG ("%s: rsi_wlan_connect_async failed with status: %02x on try %d" , __func__ , status ,
439
450
wfx_rsi .join_retries );
440
- vTaskDelay (400 );
441
- /* TODO - Start a timer.. to retry */
451
+
452
+ wfx_retry_interval_handler (is_wifi_disconnection_event , wfx_rsi .join_retries );
453
+ wfx_rsi .join_retries ++ ;
442
454
}
443
455
else
444
456
{
457
+ WFX_RSI_LOG ("%s: starting JOIN to %s after %d tries\n" , __func__ , (char * ) & wfx_rsi .sec .ssid [0 ],
458
+ wfx_rsi .join_retries );
445
459
break ; // exit while loop
446
460
}
447
461
}
448
- if (wfx_rsi .join_retries == MAX_JOIN_RETRIES_COUNT )
449
- {
450
- WFX_RSI_LOG ("Connect failed after %d tries" , wfx_rsi .join_retries );
451
- }
452
- else
453
- {
454
- WFX_RSI_LOG ("%s: starting JOIN to %s after %d tries\n" , __func__ , (char * ) & wfx_rsi .sec .ssid [0 ], wfx_rsi .join_retries );
455
- }
456
462
WFX_RSI_LOG ("Returning the do join" );
457
463
}
458
464
}
@@ -835,4 +841,46 @@ int32_t wfx_rsi_init_platform()
835
841
return status ;
836
842
}
837
843
844
+ /********************************************************************************************
845
+ * @fn void wfx_retry_interval_handler(bool is_wifi_disconnection_event, uint16_t retryJoin)
846
+ * @brief
847
+ * Based on condition will delay for a certain period of time.
848
+ * @param[in] is_wifi_disconnection_event
849
+ * @param[in] retryJoin
850
+ * @return None
851
+ ********************************************************************************************/
852
+ void wfx_retry_interval_handler (bool is_wifi_disconnection_event , uint16_t retryJoin )
853
+ {
854
+ if (!is_wifi_disconnection_event )
855
+ {
856
+ /* After the reboot or a commissioning time device failed to connect with AP.
857
+ * Device will retry to connect with AP upto WFX_RSI_CONFIG_MAX_JOIN retries.
858
+ */
859
+ if (retryJoin < MAX_JOIN_RETRIES_COUNT )
860
+ {
861
+ SILABS_LOG ("%s: Next attempt after %d Seconds" , __func__ , CONVERT_MS_TO_SEC (WLAN_RETRY_TIMER_MS ));
862
+ vTaskDelay (pdMS_TO_TICKS (WLAN_RETRY_TIMER_MS ));
863
+ }
864
+ else
865
+ {
866
+ SILABS_LOG ("Connect failed after max %d tries" , retryJoin );
867
+ }
868
+ }
869
+ else
870
+ {
871
+ /* After disconnection
872
+ * At the telescopic time interval device try to reconnect with AP, upto WLAN_MAX_RETRY_TIMER_MS intervals
873
+ * are telescopic. If interval exceed WLAN_MAX_RETRY_TIMER_MS then it will try to reconnect at
874
+ * WLAN_MAX_RETRY_TIMER_MS intervals.
875
+ */
876
+ if (retryInterval > WLAN_MAX_RETRY_TIMER_MS )
877
+ {
878
+ retryInterval = WLAN_MAX_RETRY_TIMER_MS ;
879
+ }
880
+ SILABS_LOG ("%s: Next attempt after %d Seconds" , __func__ , CONVERT_MS_TO_SEC (retryInterval ));
881
+ vTaskDelay (pdMS_TO_TICKS (retryInterval ));
882
+ retryInterval += retryInterval ;
883
+ }
884
+ }
885
+
838
886
struct wfx_rsi wfx_rsi ;
0 commit comments