Skip to content

Commit 7242a44

Browse files
committed
BUG fix
1. DNS error during Static ip settings 2. Incorrect IP reported on the INFO page #13
1 parent 7048472 commit 7242a44

File tree

8 files changed

+33
-25
lines changed

8 files changed

+33
-25
lines changed

components/utils/initialization.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ esp_err_t IRAM_ATTR parms_init()
6767
gateway_addr = (gateway_addr != NULL) ? gateway_addr : "";
6868

6969
ap_ip = (ap_ip != NULL) ? ap_ip : DEFAULT_AP_IP;
70-
customDNSip = (customDNSip != NULL) ? customDNSip : "default";
70+
customDNSip = (customDNSip != NULL) ? customDNSip : DEFAULT_DNS1;
7171

7272
authUsername = (authUsername != NULL) ? authUsername : DEFAULT_ADMIN_USERNAME;
7373
authPass = (authPass != NULL) ? authPass : DEFAULT_ADMIN_PASSWORD;
@@ -82,13 +82,13 @@ esp_err_t IRAM_ATTR parms_init()
8282
auth_info.username = authUsername;
8383
auth_info.password = authPass;
8484

85-
if (IsCustomDnsEnable)
86-
{
87-
if (strcmp(customDNSip, "default") == 0)
88-
{
89-
customDNSip = DEFAULT_DNS1;
90-
}
91-
}
85+
// if (IsCustomDnsEnable)
86+
// {
87+
// if (strcmp(customDNSip, "default") == 0)
88+
// {
89+
// customDNSip = DEFAULT_DNS1;
90+
// }
91+
// }
9292

9393
macAp = currentMAC; //(macAp != NULL) ? macAp : currentMAC;
9494

components/web_server/www/html/_i18n/english.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ info:
120120
table:
121121
A: "version"
122122
B: "Update"
123-
C: "IP / gateway"
123+
C: "IP / DNS"
124124
card-2:
125125
header: "Connected Users ($$)"
126126
table:

components/web_server/www/html/js/info.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
var versionCell = getE("version"),
44
ipGateway = getE("ipGatewayAddress"),
55
ipAddress,
6-
gateWay,
6+
dns,
77
connection = getE("connection"),
88
connectedUserCount = getE('clientsFound'),
99
connectedUsers = getE('users'),
@@ -28,7 +28,7 @@ function getData() {
2828
}
2929
// console.log(res.clients.length)
3030
ipAddress = res.ipAddress;
31-
gateWay = res.gatewayAddress;
31+
dns = res.dns;
3232
ap_rss = res.rss;
3333
wifiAuthFail = res.wifiAuthFail;
3434
clients = res.clients;
@@ -133,7 +133,7 @@ function ap_connection() {
133133
tr += '<td class=' + (state ? "green" : "red") + '><b>' + (state ? 'Connected' : (wifiAuthFail ? "wifi Auth Fail" : 'Disconnected')) + '<b></td><tr>';
134134
connection.innerHTML = tr;
135135

136-
tr = '<tr><td>{% t info.card-1.table.C %}</td><td><b>' + ipAddress + '</b></td><td>' + gateWay + '</td></tr>';
136+
tr = '<tr><td>{% t info.card-1.table.C %}</td><td><b>' + ipAddress + '</b></td><td>' + dns + '</td></tr>';
137137
ap_rss != 0 ? ipGateway.innerHTML = tr : "";
138138
}
139139
function users() {

components/web_server/www/html/sysinfo.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"ipAddress": "192.168.1.128",
3-
"gatewayAddress": "192.168.1.1",
4-
"rss": -70,
3+
"dns": "192.168.1.1",
4+
"rss": -70,
55
"wifiAuthFail" : false,
66
"clients": [
77
{
-5 Bytes
Binary file not shown.

components/wifi_handler/include/wifi_handler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ extern "C"
1515

1616
char *wifi_scan_handler(void);
1717
char *wifi_info_handler(void);
18+
bool has_static_ip;
1819

1920
#ifdef __cplusplus
2021
}

components/wifi_handler/wifi_event_handler.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "wifi_init.h"
2525
#include "wifi_event_handler.h"
2626
#include "router_handler.h"
27+
#include "wifi_handler.h"
2728

2829
static const char *TAG = "wifi_event_handler";
2930
EventGroupHandle_t wifi_event_group;
@@ -77,7 +78,7 @@ void set_dns_server(esp_netif_dns_info_t dnsIP)
7778
{
7879
dhcps_offer_t opt_val = OFFER_DNS;
7980
esp_netif_dhcps_stop(wifiAP);
80-
if (IsCustomDnsEnable)
81+
if (IsCustomDnsEnable || has_static_ip)
8182
{
8283
dnsIP.ip.u_addr.ip4.addr = ipaddr_addr(customDNSip);
8384
}

components/wifi_handler/wifi_handler.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,24 +87,29 @@ char* IRAM_ATTR wifi_info_handler(void)
8787
tcpip_adapter_ip_info_t ip_info;
8888
tcpip_adapter_dns_info_t dns_info;
8989
int8_t rssi = 0;
90-
char *dns = "";
91-
char *ip_address = "";
92-
memset(&ap_info, 0, sizeof(ap_info));
90+
char gateway_address[32];
91+
char ip_address[32];
92+
char dns[32];
9393
if (ap_connect)
9494
{
95+
memset(&ap_info, 0, sizeof(ap_info));
96+
memset(&ip_info, 0, sizeof(ip_info));
9597
if (esp_wifi_sta_get_ap_info(&ap_info) == ESP_OK)
9698
{
9799
rssi = ap_info.rssi;
98-
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ip_info);
99-
ip_address = ip4addr_ntoa(&ip_info.ip);
100-
tcpip_adapter_get_dns_info(TCPIP_ADAPTER_IF_STA, ESP_NETIF_DNS_MAIN, &dns_info);
101-
dns = ip4addr_ntoa((ip4_addr_t *)&dns_info.ip);
100+
ESP_ERROR_CHECK(tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ip_info));
101+
ESP_ERROR_CHECK(tcpip_adapter_get_dns_info(TCPIP_ADAPTER_IF_STA, ESP_NETIF_DNS_MAIN, &dns_info));
102+
103+
strlcpy(gateway_address, ip4addr_ntoa(&ip_info.gw), sizeof(gateway_address));
104+
strlcpy(ip_address, ip4addr_ntoa(&ip_info.ip), sizeof(ip_address));
105+
strlcpy(dns, ip4addr_ntoa((ip4_addr_t *)&dns_info.ip), sizeof(dns));
102106
}
103107
else
104108
{
105109
rssi = 0;
106-
dns = "";
107-
ip_address = "";
110+
strcpy(gateway_address, "");
111+
strcpy(ip_address, "");
112+
strcpy(dns, "");
108113
}
109114
}
110115
memset(&wifi_sta_list, 0, sizeof(wifi_sta_list));
@@ -113,8 +118,9 @@ char* IRAM_ATTR wifi_info_handler(void)
113118
ESP_ERROR_CHECK(tcpip_adapter_get_sta_list(&wifi_sta_list, &adapter_sta_list));
114119

115120
cJSON *root = cJSON_CreateObject();
121+
cJSON_AddStringToObject(root, "gatewayAddress", gateway_address);
116122
cJSON_AddStringToObject(root, "ipAddress", ip_address);
117-
cJSON_AddStringToObject(root, "gatewayAddress", dns);
123+
cJSON_AddStringToObject(root, "dns", (has_static_ip || IsCustomDnsEnable) ? customDNSip : dns);
118124
cJSON_AddNumberToObject(root, "rss", rssi);
119125
cJSON_AddBoolToObject(root, "wifiAuthFail", IsWifiAuthFail);
120126
cJSON *clients = cJSON_AddArrayToObject(root, "clients");

0 commit comments

Comments
 (0)