mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-08 04:27:12 +03:00
Add more logging
This commit is contained in:
@@ -354,23 +354,22 @@ void http_server_netconn_serve(struct netconn *conn) {
|
|||||||
err_t err;
|
err_t err;
|
||||||
ip_addr_t remote_add;
|
ip_addr_t remote_add;
|
||||||
u16_t port;
|
u16_t port;
|
||||||
|
ESP_LOGD(TAG,"Serving page. Getting device AP address.");
|
||||||
const char new_line[2] = "\n";
|
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);
|
char * ap_ip_address= get_nvs_value_alloc_default(NVS_TYPE_STR, "ap_ip_address", DEFAULT_AP_IP, 0);
|
||||||
if(ap_ip_address==NULL){
|
if(ap_ip_address==NULL){
|
||||||
ESP_LOGE(TAG,"Unable to retrieve default AP IP Address");
|
ESP_LOGE(TAG,"Unable to retrieve default AP IP Address");
|
||||||
netconn_write(conn, http_503_hdr, sizeof(http_503_hdr) - 1, NETCONN_NOCOPY);
|
netconn_write(conn, http_503_hdr, sizeof(http_503_hdr) - 1, NETCONN_NOCOPY);
|
||||||
netconn_close(conn);
|
netconn_close(conn);
|
||||||
netbuf_delete(inbuf);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
ESP_LOGD(TAG,"Getting remote device IP address.");
|
||||||
netconn_getaddr(conn, &remote_add, &port, 0);
|
netconn_getaddr(conn, &remote_add, &port, 0);
|
||||||
char * remote_address = strdup(ip4addr_ntoa(ip_2_ip4(&remote_add)));
|
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);
|
err = netconn_recv(conn, &inbuf);
|
||||||
if(err == ERR_OK) {
|
if(err == ERR_OK) {
|
||||||
|
ESP_LOGD(TAG,"Getting data buffer.");
|
||||||
netbuf_data(inbuf, (void**)&buf, &buflen);
|
netbuf_data(inbuf, (void**)&buf, &buflen);
|
||||||
dump_net_buffer(buf, buflen);
|
dump_net_buffer(buf, buflen);
|
||||||
int lenH = 0;
|
int lenH = 0;
|
||||||
@@ -388,7 +387,6 @@ void http_server_netconn_serve(struct netconn *conn) {
|
|||||||
if(line) {
|
if(line) {
|
||||||
|
|
||||||
/* captive portal functionality: redirect to access point IP for HOST that are not the access point IP OR the STA IP */
|
/* 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;
|
const char * host_name=NULL;
|
||||||
if((err=tcpip_adapter_get_hostname(TCPIP_ADAPTER_IF_STA, &host_name )) !=ESP_OK) {
|
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));
|
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();
|
wifi_manager_unlock_sta_ip_string();
|
||||||
bool access_from_host_name = (host_name!=NULL) && strstr(host, host_name);
|
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)) {
|
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);
|
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);
|
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);
|
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(ap_ip_address);
|
||||||
free(remote_address);
|
free(remote_address);
|
||||||
|
|||||||
@@ -97,19 +97,26 @@ bool wait_for_wifi(){
|
|||||||
return connected;
|
return connected;
|
||||||
}
|
}
|
||||||
static void initialize_nvs() {
|
static void initialize_nvs() {
|
||||||
|
ESP_LOGI(TAG,"Initializing nvs from flash");
|
||||||
esp_err_t err = nvs_flash_init();
|
esp_err_t err = nvs_flash_init();
|
||||||
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
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());
|
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||||
err = nvs_flash_init();
|
err = nvs_flash_init();
|
||||||
}
|
}
|
||||||
ESP_ERROR_CHECK(err);
|
ESP_ERROR_CHECK(err);
|
||||||
|
ESP_LOGI(TAG,"Initializing nvs from partition %s",settings_partition);
|
||||||
err = nvs_flash_init_partition(settings_partition);
|
err = nvs_flash_init_partition(settings_partition);
|
||||||
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
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));
|
ESP_ERROR_CHECK(nvs_flash_erase_partition(settings_partition));
|
||||||
err = nvs_flash_init_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_ERROR_CHECK(err);
|
||||||
|
ESP_LOGD(TAG,"nvs init completed");
|
||||||
|
|
||||||
}
|
}
|
||||||
char * process_ota_url(){
|
char * process_ota_url(){
|
||||||
@@ -206,6 +213,7 @@ void register_default_nvs(){
|
|||||||
void app_main()
|
void app_main()
|
||||||
{
|
{
|
||||||
char * fwurl = NULL;
|
char * fwurl = NULL;
|
||||||
|
ESP_LOGI(TAG,"Starting app_main");
|
||||||
initialize_nvs();
|
initialize_nvs();
|
||||||
register_default_nvs();
|
register_default_nvs();
|
||||||
led_config(LED_GREEN, LED_GREEN_GPIO, 0);
|
led_config(LED_GREEN, LED_GREEN_GPIO, 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user