esp_app_main.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. /*
  2. * Squeezelite for esp32
  3. *
  4. * (c) Sebastien 2019
  5. * Philippe G. 2019, philippe_44@outlook.com
  6. *
  7. * This software is released under the MIT License.
  8. * https://opensource.org/licenses/MIT
  9. *
  10. */
  11. #define LOG_LOCAL_LEVEL ESP_LOG_DEBUG
  12. #include "platform_esp32.h"
  13. #include "led.h"
  14. #include <stdio.h>
  15. #include <string.h>
  16. #include "freertos/FreeRTOS.h"
  17. #include "driver/gpio.h"
  18. #include "driver/spi_master.h"
  19. #include "freertos/task.h"
  20. #include "esp_system.h"
  21. #include "esp_spi_flash.h"
  22. #include "esp_wifi.h"
  23. #include "esp_system.h"
  24. #include "esp_event_loop.h"
  25. #include "nvs_flash.h"
  26. #include "esp_log.h"
  27. #include "freertos/event_groups.h"
  28. #include "mdns.h"
  29. #include "lwip/api.h"
  30. #include "lwip/err.h"
  31. #include "lwip/netdb.h"
  32. #include "nvs_utilities.h"
  33. #include "http_server.h"
  34. #include "trace.h"
  35. #include "wifi_manager.h"
  36. #include "squeezelite-ota.h"
  37. #include <math.h>
  38. #include "config.h"
  39. #include "audio_controls.h"
  40. #include "telnet.h"
  41. static const char certs_namespace[] = "certificates";
  42. static const char certs_key[] = "blob";
  43. static const char certs_version[] = "version";
  44. EventGroupHandle_t wifi_event_group;
  45. bool bypass_wifi_manager=false;
  46. const int CONNECTED_BIT = BIT0;
  47. #define JOIN_TIMEOUT_MS (10000)
  48. #define LOCAL_MAC_SIZE 20
  49. static const char TAG[] = "esp_app_main";
  50. #define DEFAULT_HOST_NAME "squeezelite"
  51. char * fwurl = NULL;
  52. static bool bWifiConnected=false;
  53. extern const uint8_t server_cert_pem_start[] asm("_binary_github_pem_start");
  54. extern const uint8_t server_cert_pem_end[] asm("_binary_github_pem_end");
  55. // as an exception _init function don't need include
  56. extern void services_init(void);
  57. extern void display_init(char *welcome);
  58. /* brief this is an exemple of a callback that you can setup in your own app to get notified of wifi manager event */
  59. void cb_connection_got_ip(void *pvParameter){
  60. static ip4_addr_t ip;
  61. tcpip_adapter_ip_info_t ipInfo;
  62. tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ipInfo);
  63. if (ip.addr && ipInfo.ip.addr != ip.addr) {
  64. ESP_LOGW(TAG, "IP change, need to reboot");
  65. if(!wait_for_commit()){
  66. ESP_LOGW(TAG,"Unable to commit configuration. ");
  67. }
  68. esp_restart();
  69. }
  70. ip.addr = ipInfo.ip.addr;
  71. ESP_LOGI(TAG, "I have a connection!");
  72. xEventGroupSetBits(wifi_event_group, CONNECTED_BIT);
  73. bWifiConnected=true;
  74. led_unpush(LED_GREEN);
  75. }
  76. void cb_connection_sta_disconnected(void *pvParameter){
  77. led_blink_pushed(LED_GREEN, 250, 250);
  78. bWifiConnected=false;
  79. xEventGroupClearBits(wifi_event_group, CONNECTED_BIT);
  80. }
  81. bool wait_for_wifi(){
  82. bool connected=(xEventGroupGetBits(wifi_event_group) & CONNECTED_BIT)!=0;
  83. if(!connected){
  84. ESP_LOGD(TAG,"Waiting for WiFi...");
  85. connected = (xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT,
  86. pdFALSE, pdTRUE, JOIN_TIMEOUT_MS / portTICK_PERIOD_MS)& CONNECTED_BIT)!=0;
  87. if(!connected){
  88. ESP_LOGW(TAG,"wifi timeout.");
  89. }
  90. else
  91. {
  92. ESP_LOGI(TAG,"WiFi Connected!");
  93. }
  94. }
  95. return connected;
  96. }
  97. char * process_ota_url(){
  98. ESP_LOGI(TAG,"Checking for update url");
  99. char * fwurl=config_alloc_get(NVS_TYPE_STR, "fwurl");
  100. if(fwurl!=NULL)
  101. {
  102. ESP_LOGD(TAG,"Deleting nvs entry for Firmware URL %s", fwurl);
  103. config_delete_key("fwurl");
  104. }
  105. return fwurl;
  106. }
  107. esp_log_level_t get_log_level_from_char(char * level){
  108. if(!strcasecmp(level, "NONE" )) { return ESP_LOG_NONE ;}
  109. if(!strcasecmp(level, "ERROR" )) { return ESP_LOG_ERROR ;}
  110. if(!strcasecmp(level, "WARN" )) { return ESP_LOG_WARN ;}
  111. if(!strcasecmp(level, "INFO" )) { return ESP_LOG_INFO ;}
  112. if(!strcasecmp(level, "DEBUG" )) { return ESP_LOG_DEBUG ;}
  113. if(!strcasecmp(level, "VERBOSE" )) { return ESP_LOG_VERBOSE;}
  114. return ESP_LOG_WARN;
  115. }
  116. void set_log_level(char * tag, char * level){
  117. esp_log_level_set(tag, get_log_level_from_char(level));
  118. }
  119. esp_err_t update_certificates(){
  120. // server_cert_pem_start
  121. // server_cert_pem_end
  122. nvs_handle handle;
  123. esp_err_t esp_err;
  124. esp_app_desc_t running_app_info;
  125. ESP_LOGI(TAG, "About to check if certificates need to be updated in flash");
  126. esp_err = nvs_open_from_partition(settings_partition, certs_namespace, NVS_READWRITE, &handle);
  127. if (esp_err != ESP_OK) {
  128. ESP_LOGE(TAG, "Unable to open name namespace %s. Error %s", certs_namespace, esp_err_to_name(esp_err));
  129. return esp_err;
  130. }
  131. const esp_partition_t *running = esp_ota_get_running_partition();
  132. if(running->subtype !=ESP_PARTITION_SUBTYPE_APP_FACTORY ){
  133. ESP_LOGI(TAG, "Running partition [%s] type %d subtype %d (offset 0x%08x)", running->label, running->type, running->subtype, running->address);
  134. }
  135. if (esp_ota_get_partition_description(running, &running_app_info) == ESP_OK) {
  136. ESP_LOGI(TAG, "Running version: %s", running_app_info.version);
  137. }
  138. size_t len=0;
  139. char *str=NULL;
  140. bool changed=false;
  141. if ( (esp_err= nvs_get_str(handle, certs_version, NULL, &len)) == ESP_OK) {
  142. str=(char *)malloc(len);
  143. if ( (esp_err = nvs_get_str(handle, certs_version, str, &len)) == ESP_OK) {
  144. printf("String associated with key '%s' is %s \n", certs_version, str);
  145. }
  146. }
  147. if(str!=NULL){
  148. if(strcmp((char *)running_app_info.version,(char *)str )){
  149. // Versions are different
  150. ESP_LOGW(TAG,"Found a different software version. Updating certificates");
  151. changed=true;
  152. }
  153. free(str);
  154. }
  155. else {
  156. ESP_LOGW(TAG,"No certificate found. Adding certificates");
  157. changed=true;
  158. }
  159. if(changed){
  160. esp_err = nvs_set_blob(handle, certs_key, server_cert_pem_start, (server_cert_pem_end-server_cert_pem_start));
  161. if(esp_err!=ESP_OK){
  162. ESP_LOGE(TAG, "Failed to store certificate data: %s", esp_err_to_name(esp_err));
  163. }
  164. else {
  165. ESP_LOGI(TAG,"Updated stored https certificates");
  166. esp_err = nvs_set_str(handle, certs_version, running_app_info.version);
  167. if(esp_err!=ESP_OK){
  168. ESP_LOGE(TAG, "Failed to store app version: %s", esp_err_to_name(esp_err));
  169. }
  170. else {
  171. esp_err = nvs_commit(handle);
  172. if(esp_err!=ESP_OK){
  173. ESP_LOGE(TAG, "Failed to commit certificate changes: %s", esp_err_to_name(esp_err));
  174. }
  175. }
  176. }
  177. }
  178. nvs_close(handle);
  179. return ESP_OK;
  180. }
  181. const char * get_certificate(){
  182. nvs_handle handle;
  183. esp_err_t esp_err;
  184. char *blob =NULL;
  185. //
  186. ESP_LOGD(TAG, "Fetching certificate.");
  187. esp_err = nvs_open_from_partition(settings_partition, certs_namespace, NVS_READONLY, &handle);
  188. if(esp_err == ESP_OK){
  189. size_t len;
  190. esp_err = nvs_get_blob(handle, certs_key, NULL, &len);
  191. if( esp_err == ESP_OK) {
  192. blob = (char *)malloc(len);
  193. esp_err = nvs_get_blob(handle, certs_key, blob, &len);
  194. if ( esp_err == ESP_OK) {
  195. printf("Blob associated with key '%s' is %d bytes long: \n", certs_key, len);
  196. }
  197. }
  198. else{
  199. ESP_LOGE(TAG, "Unable to get the existing blob from namespace %s. [%s]", certs_namespace, esp_err_to_name(esp_err));
  200. }
  201. nvs_close(handle);
  202. }
  203. else{
  204. ESP_LOGE(TAG, "Unable to open name namespace %s. [%s]", certs_namespace, esp_err_to_name(esp_err));
  205. }
  206. return blob;
  207. }
  208. #define DEFAULT_NAME_WITH_MAC(var,defval) char var[strlen(defval)+sizeof(macStr)]; strcpy(var,defval); strcat(var,macStr)
  209. void register_default_nvs(){
  210. uint8_t mac[6];
  211. char macStr[LOCAL_MAC_SIZE+1];
  212. char default_command_line[strlen(CONFIG_DEFAULT_COMMAND_LINE)+sizeof(macStr)];
  213. esp_read_mac((uint8_t *)&mac, ESP_MAC_WIFI_STA);
  214. snprintf(macStr, LOCAL_MAC_SIZE-1,"-%x%x%x", mac[3], mac[4], mac[5]);
  215. DEFAULT_NAME_WITH_MAC(default_bt_name,CONFIG_BT_NAME);
  216. ESP_LOGD(TAG,"Registering default value for key %s, value %s", "bt_name", default_bt_name);
  217. config_set_default(NVS_TYPE_STR, "bt_name", default_bt_name, 0);
  218. DEFAULT_NAME_WITH_MAC(default_host_name,DEFAULT_HOST_NAME);
  219. ESP_LOGD(TAG,"Registering default value for key %s, value %s", "host_name", default_host_name);
  220. config_set_default(NVS_TYPE_STR, "host_name", default_host_name, 0);
  221. DEFAULT_NAME_WITH_MAC(default_airplay_name,CONFIG_AIRPLAY_NAME);
  222. ESP_LOGD(TAG,"Registering default value for key %s, value %s", "airplay_name",default_airplay_name);
  223. config_set_default(NVS_TYPE_STR, "airplay_name",default_airplay_name , 0);
  224. DEFAULT_NAME_WITH_MAC(default_ap_name,CONFIG_DEFAULT_AP_SSID);
  225. ESP_LOGD(TAG,"Registering default value for key %s, value %s", "ap_ssid", default_ap_name);
  226. config_set_default(NVS_TYPE_STR, "ap_ssid",default_ap_name , 0);
  227. strncpy(default_command_line, CONFIG_DEFAULT_COMMAND_LINE,sizeof(default_command_line)-1);
  228. strncat(default_command_line, " -n ",sizeof(default_command_line)-1);
  229. strncat(default_command_line, default_host_name,sizeof(default_command_line)-1);
  230. ESP_LOGD(TAG,"Registering default value for key %s, value %s", "autoexec", "1");
  231. config_set_default(NVS_TYPE_STR,"autoexec","1", 0);
  232. ESP_LOGD(TAG,"Registering default value for key %s, value %s", "autoexec1",default_command_line);
  233. config_set_default(NVS_TYPE_STR,"autoexec1",default_command_line,0);
  234. ESP_LOGD(TAG,"Registering default value for key %s, value %s", "a2dp_sink_name", CONFIG_A2DP_SINK_NAME);
  235. config_set_default(NVS_TYPE_STR, "a2dp_sink_name", CONFIG_A2DP_SINK_NAME, 0);
  236. ESP_LOGD(TAG,"Registering default value for key %s, value %s", "bt_sink_pin", STR(CONFIG_BT_SINK_PIN));
  237. config_set_default(NVS_TYPE_STR, "bt_sink_pin", STR(CONFIG_BT_SINK_PIN), 0);
  238. ESP_LOGD(TAG,"Registering default value for key %s, value %s", "release_url", SQUEEZELITE_ESP32_RELEASE_URL);
  239. config_set_default(NVS_TYPE_STR, "release_url", SQUEEZELITE_ESP32_RELEASE_URL, 0);
  240. ESP_LOGD(TAG,"Registering default value for key %s, value %s","ap_ip_address",CONFIG_DEFAULT_AP_IP );
  241. config_set_default(NVS_TYPE_STR, "ap_ip_address",CONFIG_DEFAULT_AP_IP , 0);
  242. ESP_LOGD(TAG,"Registering default value for key %s, value %s", "ap_ip_gateway",CONFIG_DEFAULT_AP_GATEWAY );
  243. config_set_default(NVS_TYPE_STR, "ap_ip_gateway",CONFIG_DEFAULT_AP_GATEWAY , 0);
  244. ESP_LOGD(TAG,"Registering default value for key %s, value %s","ap_ip_netmask",CONFIG_DEFAULT_AP_NETMASK );
  245. config_set_default(NVS_TYPE_STR, "ap_ip_netmask",CONFIG_DEFAULT_AP_NETMASK , 0);
  246. ESP_LOGD(TAG,"Registering default value for key %s, value %s", "ap_channel",STR(CONFIG_DEFAULT_AP_CHANNEL));
  247. config_set_default(NVS_TYPE_STR, "ap_channel",STR(CONFIG_DEFAULT_AP_CHANNEL) , 0);
  248. ESP_LOGD(TAG,"Registering default value for key %s, value %s", "ap_pwd", CONFIG_DEFAULT_AP_PASSWORD);
  249. config_set_default(NVS_TYPE_STR, "ap_pwd", CONFIG_DEFAULT_AP_PASSWORD, 0);
  250. ESP_LOGD(TAG,"Registering default value for key %s, value %s", "airplay_port", CONFIG_AIRPLAY_PORT);
  251. config_set_default(NVS_TYPE_STR, "airplay_port", CONFIG_AIRPLAY_PORT, 0);
  252. ESP_LOGD(TAG,"Registering default value for key %s, value %s", "a2dp_dev_name", CONFIG_A2DP_DEV_NAME);
  253. config_set_default(NVS_TYPE_STR, "a2dp_dev_name", CONFIG_A2DP_DEV_NAME, 0);
  254. ESP_LOGD(TAG,"Registering default value for key %s, value %s", "bypass_wm", "0");
  255. config_set_default(NVS_TYPE_STR, "bypass_wm", "0", 0);
  256. ESP_LOGD(TAG,"Registering default Audio control board type %s, value ","actrls_config");
  257. config_set_default(NVS_TYPE_STR, "actrls_config", "", 0);
  258. ESP_LOGD(TAG,"Registering default value for key %s", "lms_ctrls_raw");
  259. config_set_default(NVS_TYPE_STR, "lms_ctrls_raw", "n", 0);
  260. ESP_LOGD(TAG,"Registering default Audio control board type %s, value %s", "rotary_config", CONFIG_ROTARY_ENCODER);
  261. config_set_default(NVS_TYPE_STR, "rotary_config", CONFIG_ROTARY_ENCODER, 0);
  262. char number_buffer[101] = {};
  263. snprintf(number_buffer,sizeof(number_buffer)-1,"%u",OTA_FLASH_ERASE_BLOCK);
  264. ESP_LOGD(TAG,"Registering default value for key %s, value %s", "ota_erase_blk", number_buffer);
  265. config_set_default(NVS_TYPE_STR, "ota_erase_blk", number_buffer, 0);
  266. snprintf(number_buffer,sizeof(number_buffer)-1,"%u",OTA_STACK_SIZE);
  267. ESP_LOGD(TAG,"Registering default value for key %s, value %s", "ota_stack", number_buffer);
  268. config_set_default(NVS_TYPE_STR, "ota_stack", number_buffer, 0);
  269. snprintf(number_buffer,sizeof(number_buffer)-1,"%d",OTA_TASK_PRIOTITY);
  270. ESP_LOGD(TAG,"Registering default value for key %s, value %s", "ota_prio", number_buffer);
  271. config_set_default(NVS_TYPE_STR, "ota_prio", number_buffer, 0);
  272. ESP_LOGD(TAG,"Registering default value for key %s, value %s", "enable_bt_sink", STR(CONFIG_BT_SINK));
  273. config_set_default(NVS_TYPE_STR, "enable_bt_sink", STR(CONFIG_BT_SINK), 0);
  274. ESP_LOGD(TAG,"Registering default value for key %s, value %s", "enable_airplay", STR(CONFIG_AIRPLAY_SINK));
  275. config_set_default(NVS_TYPE_STR, "enable_airplay", STR(CONFIG_AIRPLAY_SINK), 0);
  276. ESP_LOGD(TAG,"Registering default value for key %s, value %s", "display_config", CONFIG_DISPLAY_CONFIG);
  277. config_set_default(NVS_TYPE_STR, "display_config", CONFIG_DISPLAY_CONFIG, 0);
  278. ESP_LOGD(TAG,"Registering default value for key %s, value %s", "i2c_config", CONFIG_I2C_CONFIG);
  279. config_set_default(NVS_TYPE_STR, "i2c_config", CONFIG_I2C_CONFIG, 0);
  280. ESP_LOGD(TAG,"Registering default value for key %s, value %s", "spi_config", CONFIG_SPI_CONFIG);
  281. config_set_default(NVS_TYPE_STR, "spi_config", CONFIG_SPI_CONFIG, 0);
  282. ESP_LOGD(TAG,"Registering default value for key %s, value %s", "set_GPIO", CONFIG_SET_GPIO);
  283. config_set_default(NVS_TYPE_STR, "set_GPIO", CONFIG_SET_GPIO, 0);
  284. ESP_LOGD(TAG,"Registering default value for key %s", "led_brightness");
  285. config_set_default(NVS_TYPE_STR, "led_brightness", "", 0);
  286. ESP_LOGD(TAG,"Registering default value for key %s", "spdif_config");
  287. config_set_default(NVS_TYPE_STR, "spdif_config", "", 0);
  288. ESP_LOGD(TAG,"Registering default value for key %s", "dac_config");
  289. config_set_default(NVS_TYPE_STR, "dac_config", "", 0);
  290. ESP_LOGD(TAG,"Registering default value for key %s", "dac_controlset");
  291. config_set_default(NVS_TYPE_STR, "dac_controlset", "", 0);
  292. ESP_LOGD(TAG,"Registering default value for key %s", "jack_mutes_amp");
  293. config_set_default(NVS_TYPE_STR, "jack_mutes_amp", "n", 0);
  294. ESP_LOGD(TAG,"Registering default value for key %s", "bat_config");
  295. config_set_default(NVS_TYPE_STR, "bat_config", "", 0);
  296. ESP_LOGD(TAG,"Registering default value for key %s", "metadata_config");
  297. config_set_default(NVS_TYPE_STR, "metadata_config", "", 0);
  298. ESP_LOGD(TAG,"Registering default value for key %s", "telnet_enable");
  299. config_set_default(NVS_TYPE_STR, "telnet_enable", "", 0);
  300. ESP_LOGD(TAG,"Registering default value for key %s", "telnet_buffer");
  301. config_set_default(NVS_TYPE_STR, "telnet_buffer", "40000", 0);
  302. ESP_LOGD(TAG,"Registering default value for key %s", "telnet_block");
  303. config_set_default(NVS_TYPE_STR, "telnet_block", "500", 0);
  304. ESP_LOGD(TAG,"Registering default value for key %s", "stats");
  305. config_set_default(NVS_TYPE_STR, "stats", "n", 0);
  306. ESP_LOGD(TAG,"Done setting default values in nvs.");
  307. }
  308. void app_main()
  309. {
  310. char * fwurl = NULL;
  311. ESP_LOGI(TAG,"Starting app_main");
  312. initialize_nvs();
  313. ESP_LOGI(TAG,"Setting up telnet.");
  314. init_telnet(); // align on 32 bits boundaries
  315. ESP_LOGI(TAG,"Setting up config subsystem.");
  316. config_init();
  317. ESP_LOGD(TAG,"Creating event group for wifi");
  318. wifi_event_group = xEventGroupCreate();
  319. ESP_LOGD(TAG,"Clearing CONNECTED_BIT from wifi group");
  320. xEventGroupClearBits(wifi_event_group, CONNECTED_BIT);
  321. ESP_LOGI(TAG,"Registering default values");
  322. register_default_nvs();
  323. ESP_LOGD(TAG,"Configuring services");
  324. services_init();
  325. ESP_LOGD(TAG,"Initializing display");
  326. display_init("SqueezeESP32");
  327. #if !RECOVERY_APPLICATION
  328. ESP_LOGI(TAG,"Checking if certificates need to be updated");
  329. update_certificates();
  330. #endif
  331. ESP_LOGD(TAG,"Getting firmware OTA URL (if any)");
  332. fwurl = process_ota_url();
  333. ESP_LOGD(TAG,"Getting value for WM bypass, nvs 'bypass_wm'");
  334. char * bypass_wm = config_alloc_get_default(NVS_TYPE_STR, "bypass_wm", "0", 0);
  335. if(bypass_wm==NULL)
  336. {
  337. ESP_LOGE(TAG, "Unable to retrieve the Wifi Manager bypass flag");
  338. bypass_wifi_manager = false;
  339. }
  340. else {
  341. bypass_wifi_manager=(strcmp(bypass_wm,"1")==0 ||strcasecmp(bypass_wm,"y")==0);
  342. }
  343. ESP_LOGD(TAG,"Getting audio control mapping ");
  344. char *actrls_config = config_alloc_get_default(NVS_TYPE_STR, "actrls_config", NULL, 0);
  345. if (actrls_init(actrls_config) == ESP_OK) {
  346. ESP_LOGD(TAG,"Initializing audio control buttons type %s", actrls_config);
  347. } else {
  348. ESP_LOGD(TAG,"No audio control buttons");
  349. }
  350. if (actrls_config) free(actrls_config);
  351. /* start the wifi manager */
  352. ESP_LOGD(TAG,"Blinking led");
  353. led_blink_pushed(LED_GREEN, 250, 250);
  354. if(bypass_wifi_manager){
  355. ESP_LOGW(TAG,"\n\nwifi manager is disabled. Please use wifi commands to connect to your wifi access point.\n\n");
  356. }
  357. else {
  358. ESP_LOGW(TAG,"\n\nwifi manager is ENABLED. Starting...\n\n");
  359. wifi_manager_start();
  360. wifi_manager_set_callback(EVENT_STA_GOT_IP, &cb_connection_got_ip);
  361. wifi_manager_set_callback(EVENT_STA_DISCONNECTED, &cb_connection_sta_disconnected);
  362. /* Start the telnet service after we are certain that the network stack has been properly initialized.
  363. * This can be either after we're started the AP mode, or after we've started the STA mode */
  364. wifi_manager_set_callback(ORDER_START_AP, &start_telnet);
  365. wifi_manager_set_callback(ORDER_CONNECT_STA, &start_telnet);
  366. }
  367. console_start();
  368. if(fwurl && strlen(fwurl)>0){
  369. #if RECOVERY_APPLICATION
  370. while(!bWifiConnected){
  371. wait_for_wifi();
  372. taskYIELD();
  373. }
  374. ESP_LOGI(TAG,"Updating firmware from link: %s",fwurl);
  375. start_ota(fwurl);
  376. #else
  377. ESP_LOGE(TAG,"Restarted to application partition. We're not going to perform OTA!");
  378. #endif
  379. free(fwurl);
  380. }
  381. }