Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating the function setStaticIP #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions libraries/Ethernet/Ethernet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,21 @@ int EthernetClass::maintain()
return 0;
}

int EthernetClass::setStaticIP(IPAddress local_ip, IPAddress gateway, IPAddress subnet)
{
struct ip_addr ipaddr;
struct ip_addr net_mask;
struct ip_addr gw_addr;

IP4_ADDR(&ipaddr, local_ip[0], local_ip[1], local_ip[2], local_ip[3]);
IP4_ADDR(&net_mask, subnet[0], subnet[1], subnet[2], subnet[3]);
IP4_ADDR(&gw_addr, gateway[0], gateway[1], gateway[2], gateway[3]);

lwIPNetworkConfigChange(htonl(ipaddr.addr),htonl(net_mask.addr),htonl(gw_addr.addr),IPADDR_USE_STATIC);

return 0;
}

IPAddress EthernetClass::localIP()
{
return lwIPLocalIPAddrGet();
Expand Down
2 changes: 2 additions & 0 deletions libraries/Ethernet/Ethernet.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class EthernetClass {

/* For Arduino compatibility */
int maintain();

int setStaticIP(IPAddress local_ip, IPAddress gateway, IPAddress subnet);

/* IP Address related functions */
IPAddress localIP();
Expand Down