fixed static IP on ethernet adapter

This commit is contained in:
Bogdan Pilyugin 2023-07-02 11:39:56 +02:00
parent 6369135131
commit 5bb8d49c7f
2 changed files with 37 additions and 18 deletions

View File

@ -202,6 +202,7 @@ static void eth_init(void *pvParameter)
esp_netif_config.if_desc = if_desc_str; esp_netif_config.if_desc = if_desc_str;
esp_netif_config.route_prio = ETH_PRIO - i; esp_netif_config.route_prio = ETH_PRIO - i;
eth_netif_spi[i] = esp_netif_new(&cfg_spi); eth_netif_spi[i] = esp_netif_new(&cfg_spi);
} }
// Init MAC and PHY configs to default // Init MAC and PHY configs to default
@ -325,10 +326,31 @@ static void eth_init(void *pvParameter)
} }
// attach Ethernet driver to TCP/IP stack // attach Ethernet driver to TCP/IP stack
ESP_ERROR_CHECK(esp_netif_attach(eth_netif_spi[i], esp_eth_new_netif_glue(eth_handle_spi[i]))); ESP_ERROR_CHECK(esp_netif_attach(eth_netif_spi[i], esp_eth_new_netif_glue(eth_handle_spi[i])));
esp_netif_dns_info_t fldns;
//esp_netif_dns_info_t fldns;
//esp_netif_str_to_ip4(&GetAppConf()->ethSettings.DNSAddr3, (esp_ip4_addr_t*) (&fldns.ip)); //esp_netif_str_to_ip4(&GetAppConf()->ethSettings.DNSAddr3, (esp_ip4_addr_t*) (&fldns.ip));
memcpy(&fldns.ip, &GetSysConf()->ethSettings.DNSAddr3, sizeof(esp_ip4_addr_t)); //memcpy(&fldns.ip, &GetSysConf()->ethSettings.DNSAddr3, sizeof(esp_ip4_addr_t));
esp_netif_set_dns_info(eth_netif_spi[i], ESP_NETIF_DNS_FALLBACK, &fldns); //esp_netif_set_dns_info(eth_netif_spi[i], ESP_NETIF_DNS_FALLBACK, &fldns);
//DHCP & DNS
esp_netif_ip_info_t ip_info;
memcpy(&ip_info.ip, &GetSysConf()->ethSettings.IPAddr, 4);
memcpy(&ip_info.gw, &GetSysConf()->ethSettings.Gateway, 4);
memcpy(&ip_info.netmask, &GetSysConf()->ethSettings.Mask, 4);
esp_netif_dns_info_t dns_info;
memcpy(&dns_info, &GetSysConf()->ethSettings.DNSAddr1, 4);
esp_netif_dhcpc_stop(eth_netif_spi[i]);
esp_netif_set_ip_info(eth_netif_spi[i], &ip_info);
esp_netif_set_dns_info(eth_netif_spi[i], ESP_NETIF_DNS_MAIN, &dns_info);
//esp_netif_str_to_ip4(&GetSysConf()->wifiSettings.DNSAddr3, (esp_ip4_addr_t*)(&dns_info.ip));
memcpy(&dns_info.ip, &GetSysConf()->wifiSettings.DNSAddr3, sizeof(esp_ip4_addr_t));
esp_netif_set_dns_info(eth_netif_spi[i], ESP_NETIF_DNS_FALLBACK, &dns_info);
if (GetSysConf()->ethSettings.Flags1.bIsDHCPEnabled)
esp_netif_dhcpc_start(eth_netif_spi[i]);
} }
#endif // CONFIG_ETH_USE_SPI_ETHERNET #endif // CONFIG_ETH_USE_SPI_ETHERNET

View File

@ -52,7 +52,6 @@ void regAfterPostHandlerCustom(HTTP_IO_RESULT (*post_handler)(httpd_req_t *req,
AfterPostHandlerCust = post_handler; AfterPostHandlerCust = post_handler;
} }
HTTP_IO_RESULT HTTPPostApp(httpd_req_t *req, const char *filename, char *PostData) HTTP_IO_RESULT HTTPPostApp(httpd_req_t *req, const char *filename, char *PostData)
{ {
const char *pt = filename + 1; const char *pt = filename + 1;
@ -99,7 +98,6 @@ static HTTP_IO_RESULT AfterPostHandler(httpd_req_t *req, const char *filename, c
if (!memcmp(filename, url_reboot, sizeof(url_reboot))) if (!memcmp(filename, url_reboot, sizeof(url_reboot)))
return HTTPPostReboot(req, PostData); return HTTPPostReboot(req, PostData);
// If not found target URL here, try to call custom code // If not found target URL here, try to call custom code
if (AfterPostHandlerCust != NULL) if (AfterPostHandlerCust != NULL)
return AfterPostHandlerCust(req, filename, PostData); return AfterPostHandlerCust(req, filename, PostData);
@ -107,9 +105,6 @@ static HTTP_IO_RESULT AfterPostHandler(httpd_req_t *req, const char *filename, c
return HTTP_IO_DONE; return HTTP_IO_DONE;
} }
static HTTP_IO_RESULT HTTPPostAdaptersSettings(httpd_req_t *req, char *PostData) static HTTP_IO_RESULT HTTPPostAdaptersSettings(httpd_req_t *req, char *PostData)
{ {
char tmp[33]; char tmp[33];
@ -193,7 +188,10 @@ static HTTP_IO_RESULT HTTPPostAdaptersSettings(httpd_req_t *req, char *PostData)
TempIsWIFIDHCPEnabled = true; TempIsWIFIDHCPEnabled = true;
} }
if (httpd_query_key_value(PostData, "ipa", tmp, 15) == ESP_OK) if (httpd_query_key_value(PostData, "ipa", tmp, 15) == ESP_OK)
esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->wifiSettings.InfIPAddr); {
esp_err_t err = esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->wifiSettings.InfIPAddr);
ESP_LOGI(TAG, "WRITE IP:%s", esp_err_to_name(err));
}
if (httpd_query_key_value(PostData, "mas", tmp, 15) == ESP_OK) if (httpd_query_key_value(PostData, "mas", tmp, 15) == ESP_OK)
esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->wifiSettings.InfMask); esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->wifiSettings.InfMask);
if (httpd_query_key_value(PostData, "gte", tmp, 15) == ESP_OK) if (httpd_query_key_value(PostData, "gte", tmp, 15) == ESP_OK)
@ -287,7 +285,6 @@ static HTTP_IO_RESULT HTTPPostAdaptersSettings(httpd_req_t *req, char *PostData)
} }
} }
if (httpd_query_key_value(PostData, "wifisave", tmp, 4) == ESP_OK) if (httpd_query_key_value(PostData, "wifisave", tmp, 4) == ESP_OK)
{ {
if (!strcmp(tmp, (const char*) "prs")) if (!strcmp(tmp, (const char*) "prs"))