Skip to content

Commit 4eb0d8f

Browse files
committed
Increased connections. Fixed static IP settings
1 parent a5aac31 commit 4eb0d8f

File tree

2 files changed

+34
-27
lines changed

2 files changed

+34
-27
lines changed

platformio.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ board_build.embed_txtfiles =
3434
src/pages/jquery-8a1045d9cbf50b52a0805c111ba08e94.js
3535

3636
platform = espressif32
37-
platform_packages =
38-
framework-espidf @ https://github.com/tasmota/esp-idf/releases/download/v5.1.2-org/esp-idf-v5.1.2-org.zip
37+
; platform_packages =
38+
; framework-espidf @ https://github.com/tasmota/esp-idf/releases/download/v5.1.2-org/esp-idf-v5.1.2-org.zip
3939

4040
[env:esp32]
4141
board = esp32dev

src/esp32_nat_router.c

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,22 @@ httpd_handle_t start_webserver(void);
7575

7676
static const char *TAG = "ESP32NRE";
7777

78+
79+
char *ssid = NULL;
80+
char *passwd = NULL;
81+
char *static_ip = NULL;
82+
char *subnet_mask = NULL;
83+
char *gateway_addr = NULL;
84+
char *ap_ssid = NULL;
85+
char *lock_pass = NULL;
86+
87+
char *ap_passwd = NULL;
88+
char *ap_ip = NULL;
89+
90+
/* WPA2 settings */
91+
char *sta_identity = NULL;
92+
char *sta_user = NULL;
93+
7894
static void initialize_nvs(void)
7995
{
8096
esp_err_t err = nvs_flash_init();
@@ -407,18 +423,20 @@ void fillMac()
407423

408424
void setDnsServer(esp_netif_t *network, esp_ip_addr_t *dnsIP)
409425
{
426+
if ((strlen(static_ip) == 0) && (strlen(subnet_mask) == 0) && (strlen(gateway_addr) == 0))
427+
{
428+
esp_netif_dns_info_t dns_info = {0};
429+
memset(&dns_info, 8, sizeof(dns_info));
430+
dns_info.ip = *dnsIP;
431+
dns_info.ip.type = IPADDR_TYPE_V4;
410432

411-
esp_netif_dns_info_t dns_info = {0};
412-
memset(&dns_info, 8, sizeof(dns_info));
413-
dns_info.ip = *dnsIP;
414-
dns_info.ip.type = IPADDR_TYPE_V4;
415-
416-
esp_netif_dhcps_stop(network);
417-
ESP_ERROR_CHECK(esp_netif_set_dns_info(wifiAP, ESP_NETIF_DNS_MAIN, &dns_info));
418-
dhcps_offer_t opt_val = OFFER_DNS; // supply a dns server via dhcps
419-
esp_netif_dhcps_option(network, ESP_NETIF_OP_SET, ESP_NETIF_DOMAIN_NAME_SERVER, &opt_val, sizeof(opt_val));
420-
esp_netif_dhcps_start(network);
421-
ESP_LOGI(TAG, "set dns to: " IPSTR, IP2STR(&(dns_info.ip.u_addr.ip4)));
433+
esp_netif_dhcps_stop(network);
434+
ESP_ERROR_CHECK(esp_netif_set_dns_info(wifiAP, ESP_NETIF_DNS_MAIN, &dns_info));
435+
dhcps_offer_t opt_val = OFFER_DNS; // supply a dns server via dhcps
436+
esp_netif_dhcps_option(network, ESP_NETIF_OP_SET, ESP_NETIF_DOMAIN_NAME_SERVER, &opt_val, sizeof(opt_val));
437+
esp_netif_dhcps_start(network);
438+
ESP_LOGI(TAG, "set dns to: " IPSTR, IP2STR(&(dns_info.ip.u_addr.ip4)));
439+
}
422440
}
423441

424442
static void wifi_event_handler(void *arg, esp_event_base_t event_base,
@@ -583,7 +601,7 @@ void wifi_init(const char *ssid, const char *passwd, const char *static_ip, cons
583601
.ap = {
584602
.authmode = WIFI_AUTH_WPA2_WPA3_PSK,
585603
.ssid_hidden = hiddenSSID,
586-
.max_connection = 10,
604+
.max_connection = 15,
587605
.beacon_interval = 100,
588606
.pairwise_cipher = WIFI_CIPHER_TYPE_CCMP}};
589607

@@ -624,7 +642,9 @@ void wifi_init(const char *ssid, const char *passwd, const char *static_ip, cons
624642
esp_ip_addr_t dnsserver;
625643
char *defaultIP = getDefaultIPByNetmask();
626644
dnsserver.u_addr.ip4.addr = esp_ip4addr_aton(defaultIP);
645+
627646
setDnsServer(wifiAP, &dnsserver);
647+
628648
free(defaultIP);
629649

630650
xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT,
@@ -644,20 +664,7 @@ void wifi_init(const char *ssid, const char *passwd, const char *static_ip, cons
644664
start_dns_server();
645665
}
646666

647-
char *ssid = NULL;
648-
char *passwd = NULL;
649-
char *static_ip = NULL;
650-
char *subnet_mask = NULL;
651-
char *gateway_addr = NULL;
652-
char *ap_ssid = NULL;
653-
char *lock_pass = NULL;
654-
655-
char *ap_passwd = NULL;
656-
char *ap_ip = NULL;
657667

658-
/* WPA2 settings */
659-
char *sta_identity = NULL;
660-
char *sta_user = NULL;
661668

662669
char *param_set_default(const char *def_val)
663670
{

0 commit comments

Comments
 (0)