Skip to content

Commit 3dd85b5

Browse files
committed
Add networkGetBroadcastIpAddress and networkGetSubnetMask
1 parent 4838f75 commit 3dd85b5

File tree

5 files changed

+51
-1
lines changed

5 files changed

+51
-1
lines changed

Firmware/RTK_Everywhere/Developer.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
void menuEthernet() {systemPrintln("**Ethernet not compiled**");}
1313
void ethernetBegin() {}
1414
IPAddress ethernetGetIpAddress() {return IPAddress((uint32_t)0);}
15+
IPAddress ethernetGetSubnetMask() {return IPAddress((uint32_t)0);}
1516
void ethernetUpdate() {}
1617
void ethernetVerifyTables() {}
1718

@@ -154,6 +155,7 @@ void menuWiFi() {systemPrintln("**WiFi not compiled**");}
154155
bool wifiConnect(unsigned long timeout) {return false;}
155156
IPAddress wifiGetGatewayIpAddress() {return IPAddress((uint32_t)0);}
156157
IPAddress wifiGetIpAddress() {return IPAddress((uint32_t)0);}
158+
IPAddress wifiGetSubnetMask() {return IPAddress((uint32_t)0);}
157159
int wifiGetRssi() {return -999;}
158160
String wifiGetSsid() {return "**WiFi Not compiled**";}
159161
bool wifiIsConnected() {return false;}

Firmware/RTK_Everywhere/Ethernet.ino

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,12 @@ IPAddress ethernetGetIpAddress()
162162
return ETH.localIP();
163163
}
164164

165+
// Return the subnet mask for the Ethernet controller
166+
IPAddress ethernetGetSubnetMask()
167+
{
168+
return ETH.subnetMask();
169+
}
170+
165171
// Determine if Ethernet is needed. Saves RAM...
166172
bool ethernetIsNeeded()
167173
{

Firmware/RTK_Everywhere/Network.ino

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,23 @@ NETWORK_DATA *networkGet(uint8_t networkType, bool updateRequestedNetwork)
433433
return network;
434434
}
435435

436+
//----------------------------------------
437+
// Get the broadast IP address
438+
//----------------------------------------
439+
IPAddress networkGetBroadcastIpAddress(uint8_t networkType)
440+
{
441+
IPAddress ip;
442+
IPAddress mask;
443+
IPAddress temp;
444+
445+
// Get the local network address and subnet mask
446+
ip = networkGetIpAddress(networkType);
447+
mask = networkGetSubnetMask(networkType);
448+
449+
// Return the local network broadcast IP address
450+
return IPAddress((uint32_t)ip | (~(uint32_t)mask));
451+
}
452+
436453
//----------------------------------------
437454
// Get the IP address
438455
//----------------------------------------
@@ -445,6 +462,19 @@ IPAddress networkGetIpAddress(uint8_t networkType)
445462
return IPAddress((uint32_t)0);
446463
}
447464

465+
//----------------------------------------
466+
// Get the subnet mask
467+
//----------------------------------------
468+
IPAddress networkGetSubnetMask(uint8_t networkType)
469+
{
470+
// Determine the network address
471+
if (networkType == NETWORK_TYPE_ETHERNET)
472+
return ethernetGetSubnetMask();
473+
else if (networkType == NETWORK_TYPE_WIFI)
474+
return wifiGetSubnetMask();
475+
return IPAddress((uint32_t)0);
476+
}
477+
448478
//----------------------------------------
449479
// Get the network type
450480
//----------------------------------------

Firmware/RTK_Everywhere/UdpServer.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ int32_t udpServerSendDataBroadcast(uint8_t *data, uint16_t length)
107107
// Send the data as broadcast
108108
if (settings.enableUdpServer && online.udpServer && wifiIsConnected())
109109
{
110-
udpServer->beginPacket(WiFi.broadcastIP(), settings.udpServerPort);
110+
udpServer->beginPacket(networkGetBroadcastIpAddress(networkGetType(NETWORK_USER_UDP_SERVER)),
111+
settings.udpServerPort);
111112
udpServer->write(data, length);
112113
if (udpServer->endPacket())
113114
{

Firmware/RTK_Everywhere/WiFi.ino

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@ bool wifiConnect(unsigned long timeout)
489489
{
490490
return wifiConnect(timeout, false, nullptr);
491491
}
492+
492493
bool wifiConnect(unsigned long timeout, bool useAPSTAMode, bool *wasInAPmode)
493494
{
494495
if (wifiIsConnected())
@@ -698,21 +699,31 @@ void wifiPrintNetworkInfo()
698699
systemPrintln();
699700
}
700701

702+
// Return the gateway IP address for the WiFi controller
701703
IPAddress wifiGetGatewayIpAddress()
702704
{
703705
return WiFi.gatewayIP();
704706
}
705707

708+
// Return the IP address for the WiFi controller
706709
IPAddress wifiGetIpAddress()
707710
{
708711
return WiFi.localIP();
709712
}
710713

714+
// Return the subnet mask for the WiFi controller
715+
IPAddress wifiGetSubnetMask()
716+
{
717+
return WiFi.subnetMask();
718+
}
719+
720+
// Return the WiFi signal signal strength
711721
int wifiGetRssi()
712722
{
713723
return WiFi.RSSI();
714724
}
715725

726+
// Return the Wifi station ID
716727
String wifiGetSsid()
717728
{
718729
return WiFi.SSID();

0 commit comments

Comments
 (0)