Moved dns announce related stuff into newsettings
This commit is contained in:
@ -96,7 +96,7 @@ set(BOBBYCAR_BUILDFLAGS
|
||||
-DLEDSTRIP_ANIMATION_DEFAULT=0
|
||||
-DLEDS_PER_METER=144
|
||||
-DOLD_NVS
|
||||
# -DFEATURE_DNS_NS
|
||||
-DFEATURE_DNS_NS
|
||||
# -DSWITCH_BLINK
|
||||
# -DFEATURE_ESPNOW
|
||||
)
|
||||
|
@ -10,80 +10,49 @@
|
||||
#include "cpputils.h"
|
||||
#include "lwip/dns.h"
|
||||
#include "globals.h"
|
||||
#include "newsettings.h"
|
||||
|
||||
std::string dns_lastIpAddress_v4;
|
||||
std::string dns_lastIpAddress_v6;
|
||||
std::string dns_lastIpAddress_v6_global;
|
||||
|
||||
void init_dns_announce()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void handle_dns_announce()
|
||||
{
|
||||
const auto staStatus = wifi_stack::get_sta_status();
|
||||
const auto randDNSName = cpputils::randomNumber<uint16_t>(espcpputils::esp_random_device{});
|
||||
if (staStatus == wifi_stack::WiFiStaStatus::CONNECTED)
|
||||
{
|
||||
EVERY_N_SECONDS ( 2 )
|
||||
{
|
||||
// Get IPv4
|
||||
if (const auto result = wifi_stack::get_ip_info(TCPIP_ADAPTER_IF_STA); result)
|
||||
{
|
||||
std::string curIpAddress = wifi_stack::toString(result->ip);
|
||||
if (curIpAddress != "0.0.0.0")
|
||||
{
|
||||
if (dns_lastIpAddress_v4 != curIpAddress)
|
||||
{
|
||||
dns_lastIpAddress_v4 = curIpAddress;
|
||||
ip_addr_t tmpIpResolved;
|
||||
std::string toLookup = fmt::format("{}__{}.{}.announce.bobbycar.cloud", randDNSName, curIpAddress, OTA_USERNAME);
|
||||
ESP_LOGI("BOBBY", "Trying to look up %s", toLookup.c_str());
|
||||
if (const auto err = dns_gethostbyname(toLookup.c_str(), &tmpIpResolved, NULL, NULL); err != ERR_OK && err != ERR_INPROGRESS)
|
||||
{
|
||||
ESP_LOGW("BOBBY", "There is a error in the matrix (dns ipv4 lookup failed) -> %d", err);
|
||||
dns_lastIpAddress_v4 = "-";
|
||||
dns_lastIpAddress_v6 = "-";
|
||||
dns_lastIpAddress_v6_global = "-";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP_LOGW("BOBBY", "get_ip_info() failed with %.*s", result.error().size(), result.error().data());
|
||||
}
|
||||
esp_ip6_addr_t tmpv6addr;
|
||||
if (const auto result = esp_netif_get_ip6_linklocal(wifi_stack::esp_netifs[ESP_IF_WIFI_STA], &tmpv6addr); result == ESP_OK)
|
||||
{
|
||||
std::string curIpV6Address = wifi_stack::toString(tmpv6addr);
|
||||
std::replace(curIpV6Address.begin(), curIpV6Address.end(), ':', '-');
|
||||
if (dns_lastIpAddress_v6 != curIpV6Address)
|
||||
{
|
||||
dns_lastIpAddress_v6 = curIpV6Address;
|
||||
ip_addr_t tmpIpResolved;
|
||||
std::string toLookup = fmt::format("{}__{}.{}.announce6.bobbycar.cloud", randDNSName, curIpV6Address, OTA_USERNAME);
|
||||
ESP_LOGI("BOBBY", "Trying to look up %s", toLookup.c_str());
|
||||
if (const auto err = dns_gethostbyname(toLookup.c_str(), &tmpIpResolved, NULL, NULL); err != ERR_OK && err != ERR_INPROGRESS)
|
||||
{
|
||||
ESP_LOGW("BOBBY", "There is a error in the matrix (dns ipv6 local lookup failed) -> %d", err);
|
||||
dns_lastIpAddress_v4 = "-";
|
||||
dns_lastIpAddress_v6 = "-";
|
||||
dns_lastIpAddress_v6_global = "-";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!configs.dns_announce_enabled.value)
|
||||
return;
|
||||
|
||||
if (const auto result = esp_netif_get_ip6_global(wifi_stack::esp_netifs[ESP_IF_WIFI_STA], &tmpv6addr); result == ESP_OK)
|
||||
if (wifi_stack::get_sta_status() != wifi_stack::WiFiStaStatus::CONNECTED)
|
||||
{
|
||||
dns_lastIpAddress_v4 = "-";
|
||||
dns_lastIpAddress_v6 = "-";
|
||||
dns_lastIpAddress_v6_global = "-";
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const auto randDNSName = cpputils::randomNumber<uint16_t>(espcpputils::esp_random_device{});
|
||||
|
||||
EVERY_N_SECONDS ( 2 )
|
||||
{
|
||||
// Get IPv4
|
||||
if (const auto result = wifi_stack::get_ip_info(TCPIP_ADAPTER_IF_STA); result)
|
||||
{
|
||||
std::string curIpAddress = wifi_stack::toString(result->ip);
|
||||
if (curIpAddress != "0.0.0.0")
|
||||
{
|
||||
std::string curIpV6Address = wifi_stack::toString(tmpv6addr);
|
||||
if (dns_lastIpAddress_v6_global != curIpV6Address)
|
||||
if (dns_lastIpAddress_v4 != curIpAddress)
|
||||
{
|
||||
dns_lastIpAddress_v6_global = curIpV6Address;
|
||||
std::replace(curIpV6Address.begin(), curIpV6Address.end(), ':', '-');
|
||||
dns_lastIpAddress_v4 = curIpAddress;
|
||||
ip_addr_t tmpIpResolved;
|
||||
std::string toLookup = fmt::format("{}global__{}.{}.announce6.bobbycar.cloud", randDNSName, curIpV6Address, OTA_USERNAME);
|
||||
std::string toLookup = fmt::format("{}__{}.{}.announce.bobbycar.cloud", randDNSName, curIpAddress, OTA_USERNAME);
|
||||
ESP_LOGI("BOBBY", "Trying to look up %s", toLookup.c_str());
|
||||
if (const auto err = dns_gethostbyname(toLookup.c_str(), &tmpIpResolved, NULL, NULL); err != ERR_OK && err != ERR_INPROGRESS)
|
||||
{
|
||||
ESP_LOGW("BOBBY", "There is a error in the matrix (dns ipv6 global lookup failed) -> %d", err);
|
||||
ESP_LOGW("BOBBY", "There is a error in the matrix (dns ipv4 lookup failed) -> %d", err);
|
||||
dns_lastIpAddress_v4 = "-";
|
||||
dns_lastIpAddress_v6 = "-";
|
||||
dns_lastIpAddress_v6_global = "-";
|
||||
@ -91,15 +60,54 @@ void handle_dns_announce()
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP_LOGW("BOBBY", "get_ip_info() failed with %.*s", result.error().size(), result.error().data());
|
||||
}
|
||||
|
||||
EVERY_N_SECONDS( 120 ) {
|
||||
dns_lastIpAddress_v4 = "-";
|
||||
dns_lastIpAddress_v6 = "-";
|
||||
dns_lastIpAddress_v6_global = "-";
|
||||
esp_ip6_addr_t tmpv6addr;
|
||||
if (const auto result = esp_netif_get_ip6_linklocal(wifi_stack::esp_netifs[ESP_IF_WIFI_STA], &tmpv6addr); result == ESP_OK)
|
||||
{
|
||||
std::string curIpV6Address = wifi_stack::toString(tmpv6addr);
|
||||
std::replace(curIpV6Address.begin(), curIpV6Address.end(), ':', '-');
|
||||
if (dns_lastIpAddress_v6 != curIpV6Address)
|
||||
{
|
||||
dns_lastIpAddress_v6 = curIpV6Address;
|
||||
ip_addr_t tmpIpResolved;
|
||||
std::string toLookup = fmt::format("{}__{}.{}.announce6.bobbycar.cloud", randDNSName, curIpV6Address, OTA_USERNAME);
|
||||
ESP_LOGI("BOBBY", "Trying to look up %s", toLookup.c_str());
|
||||
if (const auto err = dns_gethostbyname(toLookup.c_str(), &tmpIpResolved, NULL, NULL); err != ERR_OK && err != ERR_INPROGRESS)
|
||||
{
|
||||
ESP_LOGW("BOBBY", "There is a error in the matrix (dns ipv6 local lookup failed) -> %d", err);
|
||||
dns_lastIpAddress_v4 = "-";
|
||||
dns_lastIpAddress_v6 = "-";
|
||||
dns_lastIpAddress_v6_global = "-";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (const auto result = esp_netif_get_ip6_global(wifi_stack::esp_netifs[ESP_IF_WIFI_STA], &tmpv6addr); result == ESP_OK)
|
||||
{
|
||||
std::string curIpV6Address = wifi_stack::toString(tmpv6addr);
|
||||
if (dns_lastIpAddress_v6_global != curIpV6Address)
|
||||
{
|
||||
dns_lastIpAddress_v6_global = curIpV6Address;
|
||||
std::replace(curIpV6Address.begin(), curIpV6Address.end(), ':', '-');
|
||||
ip_addr_t tmpIpResolved;
|
||||
std::string toLookup = fmt::format("{}global__{}.{}.announce6.bobbycar.cloud", randDNSName, curIpV6Address, OTA_USERNAME);
|
||||
ESP_LOGI("BOBBY", "Trying to look up %s", toLookup.c_str());
|
||||
if (const auto err = dns_gethostbyname(toLookup.c_str(), &tmpIpResolved, NULL, NULL); err != ERR_OK && err != ERR_INPROGRESS)
|
||||
{
|
||||
ESP_LOGW("BOBBY", "There is a error in the matrix (dns ipv6 global lookup failed) -> %d", err);
|
||||
dns_lastIpAddress_v4 = "-";
|
||||
dns_lastIpAddress_v6 = "-";
|
||||
dns_lastIpAddress_v6_global = "-";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
EVERY_N_SECONDS( 120 ) {
|
||||
dns_lastIpAddress_v4 = "-";
|
||||
dns_lastIpAddress_v6 = "-";
|
||||
dns_lastIpAddress_v6_global = "-";
|
||||
|
@ -1,4 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
// system includes
|
||||
#include <string>
|
||||
|
||||
#ifdef FEATURE_DNS_NS
|
||||
extern std::string dns_lastIpAddress_v4;
|
||||
extern std::string dns_lastIpAddress_v6;
|
||||
extern std::string dns_lastIpAddress_v6_global;
|
||||
|
||||
void init_dns_announce();
|
||||
void handle_dns_announce();
|
||||
#endif
|
||||
|
@ -24,12 +24,6 @@ bool simplified =
|
||||
#endif
|
||||
;
|
||||
|
||||
#ifdef FEATURE_DNS_NS
|
||||
std::string dns_lastIpAddress_v4 = "";
|
||||
std::string dns_lastIpAddress_v6 = "";
|
||||
std::string dns_lastIpAddress_v6_global = "";
|
||||
#endif
|
||||
|
||||
Settings settings;
|
||||
StringSettings stringSettings;
|
||||
SettingsPersister settingsPersister;
|
||||
|
@ -48,12 +48,6 @@ extern bool isLocked;
|
||||
#include GLOBALS_PLUGIN
|
||||
#endif
|
||||
|
||||
#ifdef FEATURE_DNS_NS
|
||||
extern std::string dns_lastIpAddress_v4;
|
||||
extern std::string dns_lastIpAddress_v6;
|
||||
extern std::string dns_lastIpAddress_v6_global;
|
||||
#endif
|
||||
|
||||
extern bool simplified;
|
||||
|
||||
extern Settings settings;
|
||||
|
@ -111,7 +111,8 @@ public:
|
||||
ConfigWrapper<std::string> cloudUrl {std::string{}, DoReset, StringOr<StringEmpty, StringValidUrl>, "cloudUrl" };
|
||||
ConfigWrapper<std::string> udpCloudHost {std::string{}, DoReset, {}, "udpCloudHost" };
|
||||
ConfigWrapper<std::string> otaUrl {std::string{}, DoReset, StringOr<StringEmpty, StringValidUrl>, "otaUrl" };
|
||||
|
||||
ConfigWrapper<bool> dns_announce_enabled{true, DoReset, {}, "dnsAnnounceEnab" };
|
||||
ConfigWrapper<std::string> dns_announce_key {std::string{}, DoReset, {}, "dnsAnnounceKey" };
|
||||
ConfigWrapper<std::string> webserverPassword {std::string{}, DoReset, {}, "websPassword" };
|
||||
|
||||
#define NEW_SETTINGS(x) \
|
||||
@ -252,7 +253,8 @@ public:
|
||||
x(cloudUrl) \
|
||||
x(udpCloudHost) \
|
||||
x(otaUrl) \
|
||||
\
|
||||
x(dns_announce_enabled) \
|
||||
x(dns_announce_key) \
|
||||
// x(webserverPassword)
|
||||
|
||||
template<typename T>
|
||||
|
@ -25,9 +25,6 @@ struct StringSettings
|
||||
std::array<ConfiguredOtaServer, 5> otaServers;
|
||||
std::string otaServerUrl;
|
||||
#endif
|
||||
#ifdef FEATURE_DNS_NS
|
||||
std::string dns_key;
|
||||
#endif
|
||||
#ifdef FEATURE_OTA
|
||||
std::string otaServerBranch;
|
||||
#endif
|
||||
@ -64,9 +61,6 @@ void StringSettings::executeForEveryCommonSetting(T &&callable)
|
||||
callable("otaserver", otaServerUrl);
|
||||
callable("otaBranch", otaServerBranch);
|
||||
#endif
|
||||
#ifdef FEATURE_DNS_NS
|
||||
callable("dnskey", dns_key);
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
Reference in New Issue
Block a user