Skip to content

Commit 3a50d3a

Browse files
committed
Ethernet.end() added
1 parent ed0050a commit 3a50d3a

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/Ethernet.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,29 @@ UIPEthernetClass::begin(const uint8_t* mac, IPAddress ip, IPAddress dns, IPAddre
117117
configure(ip,dns,gateway,subnet);
118118
}
119119

120+
void UIPEthernetClass::end()
121+
{
122+
//close all clients
123+
for (int i = 0; i < UIP_CONNS; i++)
124+
{
125+
if (EthernetClient::all_data[i].state) {
126+
EthernetClient client(&EthernetClient::all_data[i]);
127+
client.stop();
128+
}
129+
}
130+
// handle clients closings
131+
uint32_t st = millis();
132+
while (millis() - st < 3000)
133+
{
134+
tick();
135+
}
136+
initialized = false;
137+
configure(INADDR_NONE, INADDR_NONE, INADDR_NONE, INADDR_NONE);
138+
}
139+
120140
int UIPEthernetClass::maintain(){
141+
if (!initialized)
142+
return 0;
121143
tick();
122144
int rc = DHCP_CHECK_NONE;
123145
#if UIP_UDP

src/Ethernet.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ class UIPEthernetClass
8585
void begin(const uint8_t* mac, IPAddress ip, IPAddress dns, IPAddress gateway);
8686
void begin(const uint8_t* mac, IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet);
8787

88+
void end();
89+
8890
// maintain() must be called at regular intervals to process the incoming serial
8991
// data and issue IP events to the sketch. It does not return until all IP
9092
// events have been processed. Renews dhcp-lease if required.

0 commit comments

Comments
 (0)