Skip to content

Commit

Permalink
Improved suppression of repeated log messages when WiFi is down
Browse files Browse the repository at this point in the history
More precise implementation that checks for a change in the interface
name and in the DNS server addresses.
  • Loading branch information
slcasner committed Jan 17, 2019
1 parent b9130f8 commit 1ea89da
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
31 changes: 22 additions & 9 deletions vehicle/OVMS.V3/main/ovms_netmanager.cpp
Expand Up @@ -190,8 +190,9 @@ OvmsNetManager::OvmsNetManager()
{
m_dns_modem[i] = (ip_addr_t)ip_addr_any;
m_dns_wifi[i] = (ip_addr_t)ip_addr_any;
m_previous_dns[i] = (ip_addr_t)ip_addr_any;
}
m_previous_priority = NULL;
m_previous_name[0] = m_previous_name[1] = 0;

#ifdef CONFIG_OVMS_SC_GPL_MONGOOSE
m_mongoose_task = 0;
Expand Down Expand Up @@ -445,9 +446,13 @@ void OvmsNetManager::SetDNSServer(ip_addr_t* dnsstore)
cserver = std::string(servers,sep,next-sep);
sep = next+1;
}
ESP_LOGI(TAG, "Set DNS#%d %s",spos,cserver.c_str());
ip4_addr_set_u32(ip_2_ip4(&serverip), ipaddr_addr(cserver.c_str()));
serverip.type = IPADDR_TYPE_V4;
if (!ip_addr_cmp(&serverip, &m_previous_dns[spos]))
{
m_previous_dns[spos] = serverip;
ESP_LOGI(TAG, "Set DNS#%d %s",spos,cserver.c_str());
}
dns_setserver(spos++, &serverip);
}
for (;spos<DNS_MAX_SERVERS;spos++)
Expand All @@ -460,7 +465,11 @@ void OvmsNetManager::SetDNSServer(ip_addr_t* dnsstore)
// Set stored DNS servers:
for (int i=0; i<DNS_MAX_SERVERS; i++)
{
ESP_LOGI(TAG, "Set DNS#%d %s", i, inet_ntoa(dnsstore[i]));
if (ip_addr_cmp(&dnsstore[i], &m_previous_dns[i]))
{
m_previous_dns[i] = dnsstore[i];
ESP_LOGI(TAG, "Set DNS#%d %s", i, inet_ntoa(dnsstore[i]));
}
dns_setserver(i, &dnsstore[i]);
}
}
Expand Down Expand Up @@ -528,12 +537,16 @@ void OvmsNetManager::PrioritiseAndIndicate()
if ((pri->name[0]==search[0])&&
(pri->name[1]==search[1]))
{
if (pri == m_previous_priority)
return;
m_previous_priority = pri;
ESP_LOGI(TAG, "Interface priority is %c%c%d (" IPSTR "/" IPSTR " gateway " IPSTR ")",
pri->name[0], pri->name[1], pri->num,
IP2STR(&pri->ip_addr.u_addr.ip4), IP2STR(&pri->netmask.u_addr.ip4), IP2STR(&pri->gw.u_addr.ip4));
if (search[0] != m_previous_name[0] || search[1] != m_previous_name[1])
{
ESP_LOGI(TAG, "Interface priority is %c%c%d (" IPSTR "/" IPSTR " gateway " IPSTR ")",
pri->name[0], pri->name[1], pri->num,
IP2STR(&pri->ip_addr.u_addr.ip4), IP2STR(&pri->netmask.u_addr.ip4), IP2STR(&pri->gw.u_addr.ip4));
m_previous_name[0] = search[0];
m_previous_name[1] = search[1];
for (int i=0; i<DNS_MAX_SERVERS; i++)
m_previous_dns[i] = (ip_addr_t)ip_addr_any;
}
netif_set_default(pri);
SetDNSServer(dns);
return;
Expand Down
3 changes: 2 additions & 1 deletion vehicle/OVMS.V3/main/ovms_netmanager.h
Expand Up @@ -112,7 +112,8 @@ class OvmsNetManager
bool m_network_any;
ip_addr_t m_dns_wifi[DNS_MAX_SERVERS];
ip_addr_t m_dns_modem[DNS_MAX_SERVERS];
struct netif* m_previous_priority;
ip_addr_t m_previous_dns[DNS_MAX_SERVERS];
char m_previous_name[2];

#ifdef CONFIG_OVMS_SC_GPL_MONGOOSE
protected:
Expand Down

0 comments on commit 1ea89da

Please sign in to comment.