From 260fcc54fef91fbab6513cb8ec2cdae3daf1b201 Mon Sep 17 00:00:00 2001 From: Sebastien Date: Mon, 4 Nov 2019 13:19:24 -0500 Subject: [PATCH] Add more logging --- components/wifi-manager/http_server.c | 19 ++++--------------- main/esp_app_main.c | 10 +++++++++- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/components/wifi-manager/http_server.c b/components/wifi-manager/http_server.c index 2527f937..41d2807f 100644 --- a/components/wifi-manager/http_server.c +++ b/components/wifi-manager/http_server.c @@ -354,23 +354,22 @@ void http_server_netconn_serve(struct netconn *conn) { err_t err; ip_addr_t remote_add; u16_t port; - + ESP_LOGD(TAG,"Serving page. Getting device AP address."); const char new_line[2] = "\n"; char * ap_ip_address= get_nvs_value_alloc_default(NVS_TYPE_STR, "ap_ip_address", DEFAULT_AP_IP, 0); if(ap_ip_address==NULL){ ESP_LOGE(TAG,"Unable to retrieve default AP IP Address"); netconn_write(conn, http_503_hdr, sizeof(http_503_hdr) - 1, NETCONN_NOCOPY); netconn_close(conn); - netbuf_delete(inbuf); return; } - + ESP_LOGD(TAG,"Getting remote device IP address."); netconn_getaddr(conn, &remote_add, &port, 0); char * remote_address = strdup(ip4addr_ntoa(ip_2_ip4(&remote_add))); - + ESP_LOGD(TAG,"Local Access Point IP address is: %s. Remote device IP address is %s. Receiving request buffer", ap_ip_address, remote_address); err = netconn_recv(conn, &inbuf); if(err == ERR_OK) { - + ESP_LOGD(TAG,"Getting data buffer."); netbuf_data(inbuf, (void**)&buf, &buflen); dump_net_buffer(buf, buflen); int lenH = 0; @@ -388,7 +387,6 @@ void http_server_netconn_serve(struct netconn *conn) { if(line) { /* captive portal functionality: redirect to access point IP for HOST that are not the access point IP OR the STA IP */ - const char * host_name=NULL; if((err=tcpip_adapter_get_hostname(TCPIP_ADAPTER_IF_STA, &host_name )) !=ESP_OK) { ESP_LOGE(TAG,"Unable to get host name. Error: %s",esp_err_to_name(err)); @@ -400,7 +398,6 @@ void http_server_netconn_serve(struct netconn *conn) { wifi_manager_unlock_sta_ip_string(); bool access_from_host_name = (host_name!=NULL) && strstr(host, host_name); - //todo: if default IP address is changed for the AP mode in the nvs settings, then this will not work because comparison is done against default value only if(lenH > 0 && !strstr(host, ap_ip_address) && !(access_from_sta_ip || access_from_host_name)) { ESP_LOGI(TAG,"Redirecting host [%s] to AP IP Address : %s",remote_address, ap_ip_address); netconn_write(conn, http_redirect_hdr_start, sizeof(http_redirect_hdr_start) - 1, NETCONN_NOCOPY); @@ -609,14 +606,6 @@ void http_server_netconn_serve(struct netconn *conn) { free(host); } - //-1 if there is no next part - // 1 if moved to the next part but now there is no next part - // 0 if moved to the next part and there are still more parts - while(netbuf_next(inbuf) != -1) { - ESP_LOGD(TAG,"More data found from the connection!"); - netbuf_data(inbuf, (void**)&buf, &buflen); - dump_net_buffer(buf, buflen); - } free(ap_ip_address); free(remote_address); diff --git a/main/esp_app_main.c b/main/esp_app_main.c index 4d9d36ec..a0a0e05c 100644 --- a/main/esp_app_main.c +++ b/main/esp_app_main.c @@ -97,19 +97,26 @@ bool wait_for_wifi(){ return connected; } static void initialize_nvs() { + ESP_LOGI(TAG,"Initializing nvs from flash"); esp_err_t err = nvs_flash_init(); if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) { + ESP_LOGW(TAG,"Error %s. Erasing nvs flash", esp_err_to_name(err)); ESP_ERROR_CHECK(nvs_flash_erase()); err = nvs_flash_init(); } ESP_ERROR_CHECK(err); - + ESP_LOGI(TAG,"Initializing nvs from partition %s",settings_partition); err = nvs_flash_init_partition(settings_partition); if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) { + ESP_LOGW(TAG,"Error %s. Erasing nvs on partition %s",esp_err_to_name(err),settings_partition); ESP_ERROR_CHECK(nvs_flash_erase_partition(settings_partition)); err = nvs_flash_init_partition(settings_partition); } + if(err!=ESP_OK){ + ESP_LOGE(TAG,"nvs init completed with error %s",esp_err_to_name(err)); + } ESP_ERROR_CHECK(err); + ESP_LOGD(TAG,"nvs init completed"); } char * process_ota_url(){ @@ -206,6 +213,7 @@ void register_default_nvs(){ void app_main() { char * fwurl = NULL; + ESP_LOGI(TAG,"Starting app_main"); initialize_nvs(); register_default_nvs(); led_config(LED_GREEN, LED_GREEN_GPIO, 0);