Skip to content

Commit

Permalink
Add helper to convert from IPAddress to SocketAddress
Browse files Browse the repository at this point in the history
  • Loading branch information
sebromero committed Aug 11, 2020
1 parent 0cb4082 commit e1e58b1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions libraries/WiFi/src/WiFi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ arduino::IPAddress arduino::WiFiClass::ipAddressFromSocketAddress(SocketAddress
return IPAddress(address.bytes[0], address.bytes[1], address.bytes[2], address.bytes[3]);
}

SocketAddress arduino::WiFiClass::socketAddressFromIpAddress(arduino::IPAddress ipAddress, uint16_t port) {
nsapi_addr_t convertedIP = {NSAPI_IPv4, {ip[0], ip[1], ip[2], ip[3]}};
return SocketAddress(convertedIP, port);
}

int arduino::WiFiClass::begin(const char* ssid, const char *passphrase) {
if (_ssid) free(_ssid);

Expand Down
1 change: 1 addition & 0 deletions libraries/WiFi/src/WiFi.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ class WiFiClass
void ensureDefaultAPNetworkConfiguration();
bool isVisible(const char* ssid);
arduino::IPAddress ipAddressFromSocketAddress(SocketAddress socketAddress);
SocketAddress socketAddressFromIpAddress(arduino::IPAddress ipAddress, uint16_t port);
};

}
Expand Down

0 comments on commit e1e58b1

Please sign in to comment.