mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-23 10:46:31 +00:00
Merge pull request #10616 from polarduck-dev/development
fixed IPv6 address acquisition
This commit is contained in:
commit
4c59007cc7
@ -497,7 +497,7 @@ struct {
|
||||
uint8_t ina219_mode; // 531
|
||||
uint16_t pulse_timer[MAX_PULSETIMERS]; // 532
|
||||
uint16_t button_debounce; // 542
|
||||
uint32_t ip_address[4]; // 544
|
||||
uint32_t ipv4_address[4]; // 544
|
||||
unsigned long energy_kWhtotal; // 554
|
||||
|
||||
char ex_mqtt_fulltopic[100]; // 558 Free since 8.0.0.1
|
||||
|
@ -812,10 +812,10 @@ void SettingsDefaultSet2(void)
|
||||
flag3.use_wifi_rescan |= WIFI_SCAN_REGULARLY;
|
||||
Settings.wifi_output_power = 170;
|
||||
Settings.param[P_ARP_GRATUITOUS] = WIFI_ARP_INTERVAL;
|
||||
ParseIp(&Settings.ip_address[0], PSTR(WIFI_IP_ADDRESS));
|
||||
ParseIp(&Settings.ip_address[1], PSTR(WIFI_GATEWAY));
|
||||
ParseIp(&Settings.ip_address[2], PSTR(WIFI_SUBNETMASK));
|
||||
ParseIp(&Settings.ip_address[3], PSTR(WIFI_DNS));
|
||||
ParseIPv4(&Settings.ipv4_address[0], PSTR(WIFI_IP_ADDRESS));
|
||||
ParseIPv4(&Settings.ipv4_address[1], PSTR(WIFI_GATEWAY));
|
||||
ParseIPv4(&Settings.ipv4_address[2], PSTR(WIFI_SUBNETMASK));
|
||||
ParseIPv4(&Settings.ipv4_address[3], PSTR(WIFI_DNS));
|
||||
Settings.sta_config = WIFI_CONFIG_TOOL;
|
||||
// Settings.sta_active = 0;
|
||||
SettingsUpdateText(SET_STASSID1, PSTR(STA_SSID1));
|
||||
|
@ -655,13 +655,12 @@ uint8_t Shortcut(void)
|
||||
|
||||
bool ValidIpAddress(const char* str)
|
||||
{
|
||||
const char* p = str;
|
||||
|
||||
while (*p && ((*p == '.') || ((*p >= '0') && (*p <= '9')))) { p++; }
|
||||
return (*p == '\0');
|
||||
IPAddress ip_address;
|
||||
return ip_address.fromString(str);
|
||||
}
|
||||
|
||||
bool ParseIp(uint32_t* addr, const char* str_p)
|
||||
|
||||
bool ParseIPv4(uint32_t* addr, const char* str_p)
|
||||
{
|
||||
uint8_t *part = (uint8_t*)addr;
|
||||
uint8_t i;
|
||||
|
@ -510,8 +510,8 @@ void CmndStatus(void)
|
||||
Response_P(PSTR("{\"" D_CMND_STATUS D_STATUS5_NETWORK "\":{\"" D_CMND_HOSTNAME "\":\"%s\",\"" D_CMND_IPADDRESS "\":\"%s\",\"" D_JSON_GATEWAY "\":\"%s\",\""
|
||||
D_JSON_SUBNETMASK "\":\"%s\",\"" D_JSON_DNSSERVER "\":\"%s\",\"" D_JSON_MAC "\":\"%s\",\""
|
||||
D_CMND_WEBSERVER "\":%d,\"" D_CMND_WIFICONFIG "\":%d,\"" D_CMND_WIFIPOWER "\":%s}}"),
|
||||
NetworkHostname(), NetworkAddress().toString().c_str(), IPAddress(Settings.ip_address[1]).toString().c_str(),
|
||||
IPAddress(Settings.ip_address[2]).toString().c_str(), IPAddress(Settings.ip_address[3]).toString().c_str(), NetworkMacAddress().c_str(),
|
||||
NetworkHostname(), NetworkAddress().toString().c_str(), IPAddress(Settings.ipv4_address[1]).toString().c_str(),
|
||||
IPAddress(Settings.ipv4_address[2]).toString().c_str(), IPAddress(Settings.ipv4_address[3]).toString().c_str(), NetworkMacAddress().c_str(),
|
||||
Settings.webserver, Settings.sta_config, WifiGetOutputPower().c_str());
|
||||
MqttPublishPrefixTopic_P(STAT, PSTR(D_CMND_STATUS "5"));
|
||||
}
|
||||
@ -1497,18 +1497,18 @@ void CmndIpAddress(void)
|
||||
snprintf_P(stemp1, sizeof(stemp1), PSTR(" %s"), NetworkAddress().toString().c_str());
|
||||
ResponseClear();
|
||||
for (uint32_t i = 0; i < 4; i++) {
|
||||
ResponseAppend_P(PSTR("%c\"%s%d\":\"%s%s\""), (i) ? ',' : '{', XdrvMailbox.command, i +1, IPAddress(Settings.ip_address[i]).toString().c_str(), (0 == i) ? stemp1:"");
|
||||
ResponseAppend_P(PSTR("%c\"%s%d\":\"%s%s\""), (i) ? ',' : '{', XdrvMailbox.command, i +1, IPAddress(Settings.ipv4_address[i]).toString().c_str(), (0 == i) ? stemp1:"");
|
||||
}
|
||||
ResponseJsonEnd();
|
||||
} else {
|
||||
uint32_t address;
|
||||
if (ParseIp(&address, XdrvMailbox.data)) {
|
||||
Settings.ip_address[XdrvMailbox.index -1] = address;
|
||||
uint32_t ipv4_address;
|
||||
if (ParseIPv4(&ipv4_address, XdrvMailbox.data)) {
|
||||
Settings.ipv4_address[XdrvMailbox.index -1] = ipv4_address;
|
||||
// TasmotaGlobal.restart_flag = 2;
|
||||
}
|
||||
char stemp1[TOPSZ];
|
||||
snprintf_P(stemp1, sizeof(stemp1), PSTR(" %s"), NetworkAddress().toString().c_str());
|
||||
Response_P(S_JSON_COMMAND_INDEX_SVALUE_SVALUE, XdrvMailbox.command, XdrvMailbox.index, IPAddress(Settings.ip_address[XdrvMailbox.index -1]).toString().c_str(), (1 == XdrvMailbox.index) ? stemp1:"");
|
||||
Response_P(S_JSON_COMMAND_INDEX_SVALUE_SVALUE, XdrvMailbox.command, XdrvMailbox.index, IPAddress(Settings.ipv4_address[XdrvMailbox.index -1]).toString().c_str(), (1 == XdrvMailbox.index) ? stemp1:"");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -66,13 +66,6 @@ bool device_groups_up = false;
|
||||
bool building_status_message = false;
|
||||
bool ignore_dgr_sends = false;
|
||||
|
||||
char * IPAddressToString(const IPAddress& ip_address)
|
||||
{
|
||||
static char buffer[16];
|
||||
sprintf_P(buffer, PSTR("%u.%u.%u.%u"), ip_address[0], ip_address[1], ip_address[2], ip_address[3]);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
uint8_t * BeginDeviceGroupMessage(struct device_group * device_group, uint16_t flags, bool hold_sequence = false)
|
||||
{
|
||||
uint8_t * message_ptr = &device_group->message[device_group->message_header_length];
|
||||
@ -225,7 +218,7 @@ void SendReceiveDeviceGroupMessage(struct device_group * device_group, struct de
|
||||
flags |= *message_ptr++ << 8;
|
||||
|
||||
// Initialize the log buffer.
|
||||
log_length = sprintf(log_buffer, PSTR("DGR: %s %s message %s %s: seq=%u, flags=%u"), (received ? PSTR("Received") : PSTR("Sending")), device_group->group_name, (received ? PSTR("from") : PSTR("to")), (device_group_member ? IPAddressToString(device_group_member->ip_address) : received ? PSTR("local") : PSTR("network")), message_sequence, flags);
|
||||
log_length = sprintf(log_buffer, PSTR("DGR: %s %s message %s %s: seq=%u, flags=%u"), (received ? PSTR("Received") : PSTR("Sending")), device_group->group_name, (received ? PSTR("from") : PSTR("to")), (device_group_member ? device_group_member->ip_address.toString().c_str() : received ? PSTR("local") : PSTR("network")), message_sequence, flags);
|
||||
log_ptr = log_buffer + log_length;
|
||||
log_remaining = sizeof(log_buffer) - log_length;
|
||||
|
||||
@ -777,7 +770,7 @@ void ProcessDeviceGroupMessage(uint8_t * message, int message_length)
|
||||
}
|
||||
device_group_member->ip_address = remote_ip;
|
||||
*flink = device_group_member;
|
||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR("DGR: Member %s added"), IPAddressToString(remote_ip));
|
||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR("DGR: Member %s added"), remote_ip.toString().c_str());
|
||||
break;
|
||||
}
|
||||
else if (device_group_member->ip_address == remote_ip) {
|
||||
@ -797,7 +790,7 @@ void DeviceGroupStatus(uint8_t device_group_index)
|
||||
struct device_group * device_group = &device_groups[device_group_index];
|
||||
buffer[0] = buffer[1] = 0;
|
||||
for (struct device_group_member * device_group_member = device_group->device_group_members; device_group_member; device_group_member = device_group_member->flink) {
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("%s,{\"IPAddress\":\"%s\",\"ResendCount\":%u,\"LastRcvdSeq\":%u,\"LastAckedSeq\":%u}"), buffer, IPAddressToString(device_group_member->ip_address), device_group_member->unicast_count, device_group_member->received_sequence, device_group_member->acked_sequence);
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("%s,{\"IPAddress\":\"%s\",\"ResendCount\":%u,\"LastRcvdSeq\":%u,\"LastAckedSeq\":%u}"), buffer, device_group_member->ip_address.toString().c_str(), device_group_member->unicast_count, device_group_member->received_sequence, device_group_member->acked_sequence);
|
||||
member_count++;
|
||||
}
|
||||
Response_P(PSTR("{\"" D_CMND_DEVGROUPSTATUS "\":{\"Index\":%u,\"GroupName\":\"%s\",\"MessageSeq\":%u,\"MemberCount\":%d,\"Members\":[%s]}}"), device_group_index, device_group->group_name, device_group->outgoing_sequence, member_count, &buffer[1]);
|
||||
@ -874,7 +867,7 @@ AddLog_P(LOG_LEVEL_DEBUG, PSTR("DGR: Checking next_check_time=%u, now=%u"), next
|
||||
if ((long)(now - device_group->member_timeout_time) >= 0) {
|
||||
*flink = device_group_member->flink;
|
||||
free(device_group_member);
|
||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR("DGR: Member %s removed"), IPAddressToString(device_group_member->ip_address));
|
||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR("DGR: Member %s removed"), device_group_member->ip_address.toString().c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -203,8 +203,8 @@ void WifiBegin(uint8_t flag, uint8_t channel)
|
||||
if (!strlen(SettingsText(SET_STASSID1 + Settings.sta_active))) {
|
||||
Settings.sta_active ^= 1; // Skip empty SSID
|
||||
}
|
||||
if (Settings.ip_address[0]) {
|
||||
WiFi.config(Settings.ip_address[0], Settings.ip_address[1], Settings.ip_address[2], Settings.ip_address[3]); // Set static IP
|
||||
if (Settings.ipv4_address[0]) {
|
||||
WiFi.config(Settings.ipv4_address[0], Settings.ipv4_address[1], Settings.ipv4_address[2], Settings.ipv4_address[3]); // Set static IP
|
||||
}
|
||||
WiFi.hostname(TasmotaGlobal.hostname);
|
||||
|
||||
@ -361,16 +361,6 @@ void WifiSetState(uint8_t state)
|
||||
}
|
||||
|
||||
#if LWIP_IPV6
|
||||
bool WifiCheckIPv6(void)
|
||||
{
|
||||
bool ipv6_global=false;
|
||||
|
||||
for (auto a : addrList) {
|
||||
if(!a.isLocal() && a.isV6()) ipv6_global=true;
|
||||
}
|
||||
return ipv6_global;
|
||||
}
|
||||
|
||||
String WifiGetIPv6(void)
|
||||
{
|
||||
for (auto a : addrList) {
|
||||
@ -378,35 +368,30 @@ String WifiGetIPv6(void)
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
bool WifiCheckIPAddrStatus(void) // Return false for 169.254.x.x or fe80::/64
|
||||
{
|
||||
bool ip_global=false;
|
||||
|
||||
for (auto a : addrList) {
|
||||
if(!a.isLocal()) ip_global=true;
|
||||
}
|
||||
return ip_global;
|
||||
}
|
||||
#endif // LWIP_IPV6=1
|
||||
|
||||
// Check to see if we have any routable IP address
|
||||
inline bool WifiCheck_hasIP(IPAddress const & ip_address)
|
||||
{
|
||||
#ifdef LWIP2_IPV6
|
||||
return !a.isLocal();
|
||||
#else
|
||||
return static_cast<uint32_t>(ip_address) != 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void WifiCheckIp(void)
|
||||
{
|
||||
#if LWIP_IPV6
|
||||
if(WifiCheckIPAddrStatus()) {
|
||||
Wifi.status = WL_CONNECTED;
|
||||
#else
|
||||
if ((WL_CONNECTED == WiFi.status()) && (static_cast<uint32_t>(WiFi.localIP()) != 0)) {
|
||||
#endif // LWIP_IPV6=1
|
||||
if ((WL_CONNECTED == WiFi.status()) && WifiCheck_hasIP(WiFi.localIP())) {
|
||||
WifiSetState(1);
|
||||
Wifi.counter = WIFI_CHECK_SEC;
|
||||
Wifi.retry = Wifi.retry_init;
|
||||
if (Wifi.status != WL_CONNECTED) {
|
||||
AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_WIFI D_CONNECTED));
|
||||
// AddLog_P(LOG_LEVEL_INFO, PSTR("Wifi: Set IP addresses"));
|
||||
Settings.ip_address[1] = (uint32_t)WiFi.gatewayIP();
|
||||
Settings.ip_address[2] = (uint32_t)WiFi.subnetMask();
|
||||
Settings.ip_address[3] = (uint32_t)WiFi.dnsIP();
|
||||
Settings.ipv4_address[1] = (uint32_t)WiFi.gatewayIP();
|
||||
Settings.ipv4_address[2] = (uint32_t)WiFi.subnetMask();
|
||||
Settings.ipv4_address[3] = (uint32_t)WiFi.dnsIP();
|
||||
|
||||
// Save current AP parameters for quick reconnect
|
||||
Settings.wifi_channel = WiFi.channel();
|
||||
@ -521,11 +506,7 @@ void WifiCheck(uint8_t param)
|
||||
Wifi.counter = WIFI_CHECK_SEC;
|
||||
WifiCheckIp();
|
||||
}
|
||||
#if LWIP_IPV6
|
||||
if (WifiCheckIPAddrStatus()) {
|
||||
#else
|
||||
if ((WL_CONNECTED == WiFi.status()) && (static_cast<uint32_t>(WiFi.localIP()) != 0) && !Wifi.config_type) {
|
||||
#endif // LWIP_IPV6=1
|
||||
if ((WL_CONNECTED == WiFi.status()) && WifiCheck_hasIP(WiFi.localIP()) && !Wifi.config_type) {
|
||||
WifiSetState(1);
|
||||
if (Settings.flag3.use_wifi_rescan) { // SetOption57 - Scan wifi network every 44 minutes for configured AP's
|
||||
if (!(TasmotaGlobal.uptime % (60 * WIFI_RESCAN_MINUTES))) {
|
||||
|
@ -69,17 +69,17 @@ Examples :
|
||||
|
||||
#ifdef MY_IP
|
||||
#undef WIFI_IP_ADDRESS
|
||||
#define WIFI_IP_ADDRESS MY_IP // Set to 0.0.0.0 for using DHCP or enter a static IP address
|
||||
#define WIFI_IP_ADDRESS MY_IP // Set to 0.0.0.0 for using DHCP or enter a static IP address
|
||||
#endif
|
||||
|
||||
#ifdef MY_GW
|
||||
#undef WIFI_GATEWAY
|
||||
#define WIFI_GATEWAY MY_GW // if not using DHCP set Gateway IP address
|
||||
#define WIFI_GATEWAY MY_GW // if not using DHCP set Gateway IP address
|
||||
#endif
|
||||
|
||||
#ifdef MY_DNS
|
||||
#undef WIFI_DNS
|
||||
#define WIFI_DNS MY_DNS // If not using DHCP set DNS IP address (might be equal to WIFI_GATEWAY)
|
||||
#define WIFI_DNS MY_DNS // If not using DHCP set DNS IP address (might be equal to WIFI_GATEWAY)
|
||||
#endif
|
||||
|
||||
*/
|
||||
|
@ -2111,9 +2111,9 @@ void HandleInformation(void)
|
||||
}
|
||||
}
|
||||
if (!TasmotaGlobal.global_state.network_down) {
|
||||
WSContentSend_P(PSTR("}1" D_GATEWAY "}2%s"), IPAddress(Settings.ip_address[1]).toString().c_str());
|
||||
WSContentSend_P(PSTR("}1" D_SUBNET_MASK "}2%s"), IPAddress(Settings.ip_address[2]).toString().c_str());
|
||||
WSContentSend_P(PSTR("}1" D_DNS_SERVER "}2%s"), IPAddress(Settings.ip_address[3]).toString().c_str());
|
||||
WSContentSend_P(PSTR("}1" D_GATEWAY "}2%s"), IPAddress(Settings.ipv4_address[1]).toString().c_str());
|
||||
WSContentSend_P(PSTR("}1" D_SUBNET_MASK "}2%s"), IPAddress(Settings.ipv4_address[2]).toString().c_str());
|
||||
WSContentSend_P(PSTR("}1" D_DNS_SERVER "}2%s"), IPAddress(Settings.ipv4_address[3]).toString().c_str());
|
||||
}
|
||||
if ((WiFi.getMode() >= WIFI_AP) && (static_cast<uint32_t>(WiFi.softAPIP()) != 0)) {
|
||||
WSContentSend_P(PSTR("}1<hr/>}2<hr/>"));
|
||||
|
@ -477,13 +477,6 @@ bool event_handeled = false;
|
||||
IPAddress last_udp_ip;
|
||||
WiFiUDP Script_PortUdp;
|
||||
|
||||
#ifndef USE_DEVICE_GROUPS
|
||||
char * IPAddressToString(const IPAddress& ip_address) {
|
||||
static char ipbuffer[16];
|
||||
sprintf_P(ipbuffer, PSTR("%u.%u.%u.%u"), ip_address[0], ip_address[1], ip_address[2], ip_address[3]);
|
||||
return ipbuffer;
|
||||
}
|
||||
#endif //USE_DEVICE_GROUPS
|
||||
#endif //USE_SCRIPT_GLOBVARS
|
||||
|
||||
int16_t last_findex;
|
||||
@ -2525,7 +2518,7 @@ chknext:
|
||||
}
|
||||
#ifdef USE_SCRIPT_GLOBVARS
|
||||
if (!strncmp(vname, "luip", 4)) {
|
||||
if (sp) strlcpy(sp, IPAddressToString(last_udp_ip), glob_script_mem.max_ssize);
|
||||
if (sp) strlcpy(sp, last_udp_ip.toString().c_str(), glob_script_mem.max_ssize);
|
||||
goto strexit;
|
||||
}
|
||||
#endif //USE_SCRIPT_GLOBVARS
|
||||
|
@ -95,9 +95,9 @@ void EthernetEvent(WiFiEvent_t event) {
|
||||
case SYSTEM_EVENT_ETH_GOT_IP:
|
||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR("ETH: Mac %s, IPAddress %s, Hostname %s"),
|
||||
ETH.macAddress().c_str(), ETH.localIP().toString().c_str(), eth_hostname);
|
||||
Settings.ip_address[1] = (uint32_t)ETH.gatewayIP();
|
||||
Settings.ip_address[2] = (uint32_t)ETH.subnetMask();
|
||||
Settings.ip_address[3] = (uint32_t)ETH.dnsIP();
|
||||
Settings.ipv4_address[1] = (uint32_t)ETH.gatewayIP();
|
||||
Settings.ipv4_address[2] = (uint32_t)ETH.subnetMask();
|
||||
Settings.ipv4_address[3] = (uint32_t)ETH.dnsIP();
|
||||
TasmotaGlobal.global_state.eth_down = 0;
|
||||
break;
|
||||
case SYSTEM_EVENT_ETH_DISCONNECTED:
|
||||
|
Loading…
x
Reference in New Issue
Block a user