21
21
#include <esp_https_ota.h>
22
22
#include <esp_wifi_types.h>
23
23
#include <esp_wifi.h>
24
+ #if CONFIG_BT_ENABLED
25
+ #include <esp_bt.h>
26
+ #endif /* CONFIG_BT_ENABLED */
24
27
25
28
#include <esp_rmaker_utils.h>
26
29
#include "esp_rmaker_ota_internal.h"
@@ -159,7 +162,7 @@ static esp_err_t esp_rmaker_ota_default_cb(esp_rmaker_ota_handle_t ota_handle, e
159
162
160
163
esp_rmaker_ota_report_status (ota_handle , OTA_STATUS_IN_PROGRESS , "Starting OTA Upgrade" );
161
164
162
- /* Using a warning just to highlight the message */
165
+ /* Using a warning just to highlight the message */
163
166
ESP_LOGW (TAG , "Starting OTA. This may take time." );
164
167
esp_https_ota_handle_t https_ota_handle = NULL ;
165
168
esp_err_t err = esp_https_ota_begin (& ota_config , & https_ota_handle );
@@ -174,9 +177,15 @@ static esp_err_t esp_rmaker_ota_default_cb(esp_rmaker_ota_handle_t ota_handle, e
174
177
*/
175
178
wifi_ps_type_t ps_type ;
176
179
esp_wifi_get_ps (& ps_type );
177
- /* Disable Wi-Fi power save to speed up OTA
178
- */
180
+ /* Disable Wi-Fi power save to speed up OTA, iff BT is controller is idle/disabled.
181
+ * Co-ex requirement, device panics otherwise.*/
182
+ #if CONFIG_BT_ENABLED
183
+ if (esp_bt_controller_get_status () == ESP_BT_CONTROLLER_STATUS_IDLE ) {
184
+ esp_wifi_set_ps (WIFI_PS_NONE );
185
+ }
186
+ #else
179
187
esp_wifi_set_ps (WIFI_PS_NONE );
188
+ #endif /* CONFIG_BT_ENABLED */
180
189
181
190
esp_app_desc_t app_desc ;
182
191
err = esp_https_ota_get_img_desc (https_ota_handle , & app_desc );
@@ -222,8 +231,15 @@ static esp_err_t esp_rmaker_ota_default_cb(esp_rmaker_ota_handle_t ota_handle, e
222
231
} else {
223
232
esp_rmaker_ota_report_status (ota_handle , OTA_STATUS_IN_PROGRESS , "Firmware Image download complete" );
224
233
}
234
+
225
235
ota_end :
236
+ #ifdef CONFIG_BT_ENABLED
237
+ if (esp_bt_controller_get_status () == ESP_BT_CONTROLLER_STATUS_IDLE ) {
238
+ esp_wifi_set_ps (ps_type );
239
+ }
240
+ #else
226
241
esp_wifi_set_ps (ps_type );
242
+ #endif /* CONFIG_BT_ENABLED */
227
243
ota_finish_err = esp_https_ota_finish (https_ota_handle );
228
244
if ((err == ESP_OK ) && (ota_finish_err == ESP_OK )) {
229
245
ESP_LOGI (TAG , "OTA upgrade successful. Rebooting in %d seconds..." , OTA_REBOOT_TIMER_SEC );
0 commit comments