You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: DHCP/README.md
+80-31Lines changed: 80 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,27 @@
1
1
# Wiznet 5500 DHCP #
2
2
3
-
This library class enables Dynamic Host Configuration Protocol (DHCP) functionality for the Wiznet W5500 chip[W5500](http://wizwiki.net/wiki/lib/exe/fetch.php?media=products:w5500:w5500_ds_v106e_141230.pdf). It also requires the Wiznet W5500 driver.
3
+
This library class enables Dynamic Host Configuration Protocol (DHCP) functionality for the [Wiznet W5500 chip](http://wizwiki.net/wiki/lib/exe/fetch.php?media=products:w5500:w5500_ds_v106e_141230.pdf). It depends on the Wiznet W5500 library, so be sure to include the DHCP library after the W5500 library.
4
4
5
-
**To add this code to your project, add**`#require W5500.DHCP.device.lib.nut:2.0.0`**after**`#require W5500.device.lib.nut:2.1.1`**at the top of your device code**
5
+
**To include this library in your project, add the following to the top of your device code**
6
6
7
-
## Class W5500.DHCP ##
7
+
```
8
+
#require "W5500.device.lib.nut:2.1.1"
9
+
#require "W5500.DHCP.device.lib.nut:2.0.0"
10
+
```
11
+
12
+
## Class Usage ##
8
13
9
14
### Constructor: W5500.DHCP(*wiz*) ###
10
15
11
-
Instantiates a new W5500.DHCP object and passes in the main Wiznet driver.
16
+
Instantiates a new W5500.DHCP object using the main Wiznet driver.
|*wiz*| Wiznet driver | Yes | The driver controlling the W5500 |
21
+
22
+
#### Returns ####
23
+
24
+
The instance.
12
25
13
26
#### Example ####
14
27
@@ -30,48 +43,68 @@ dhcp <- W5500.DHCP(wiz);
30
43
31
44
### onLease(*callback*) ###
32
45
33
-
This method sets the function to be called when an IP address is leased. The callback function, which is not optional, has an *error* parameter which informs the user of timeouts and errors, or will be `null`.
46
+
This method registers the function that will be called when an IP address is leased.
|*callback*| Function | Yes | The callback has one parameter of its own, *error*, which informs the user of timeouts and errors, or will be `null`|
34
53
35
54
#### Error Messages ####
36
55
37
-
| ErrorMessage | Description |
56
+
| Error Message | Description |
38
57
| --- | --- |
39
-
| Offer Timeout | Discovery message sent with no response |
40
-
| Ack Timeout | Request message sent with no response |
41
-
| Renewal Timeout |Max Renewal attempts reached before a restart |
42
-
| Renewal Failed | Lease renewal failed |
43
-
| Request Declined | Requested IP not able to be leased |
44
-
| IP in use | Offered IP is currently in use |
45
-
| All connections in use | All Wiznet sockets are in use |
58
+
|`"Offer Timeout"`| Discovery message sent with no response |
59
+
|`"Ack Timeout`"| Request message sent with no response |
60
+
|`"Renewal Timeout"`|Maximum Renewal attempts reached before a restart |
61
+
|`"Renewal Failed"`| Lease renewal failed |
62
+
|`"Request Declined"`| Requested IP not able to be leased |
63
+
|`"IP in use"`| Offered IP is currently in use |
64
+
|`"All connections in use"`| All Wiznet sockets are in use |
46
65
47
66
#### Example ####
48
67
49
68
```squirrel
50
69
dhcp.onLease(function(error) {
51
-
if (error) return server.error(error);
52
-
server.log("DHCP lease obtained");
70
+
if (error) return server.error(error);
71
+
server.log("DHCP lease obtained");
53
72
});
54
73
```
55
74
56
-
### renewLease() ###
75
+
### renewLease(*[timeout]*) ###
76
+
77
+
This method renews the lease or requests a new lease. When this is complete, the callback function registered with [*onLease()*](#onleasecallback) will be executed.
|*timeout*| Integer | No | The number of seconds to allow for the lease to try before giving up, if set to 0 the timeout will be infinite. Default: 0 |
84
+
85
+
#### Returns ####
57
86
58
-
This method renews the lease or requests a new lease. When this is complete, the *onLease()* callback will be executed.
87
+
The instance (*this*).
59
88
60
89
#### Example ####
61
90
62
91
```squirrel
63
92
dhcp.onLease(function(error) {
64
-
// Run this code when IP address is obtained
65
-
if (error) return server.error(error);
66
-
server.log("DHCP lease obtained");
93
+
// Run this code when IP address is obtained
94
+
if (error) return server.error(error);
95
+
server.log("DHCP lease obtained");
67
96
});
68
97
69
98
dhcp.renewLease();
70
99
```
71
100
72
101
### getIP() ###
73
102
74
-
This method returns the leased IP address as an array of four integers.
103
+
This method retrieves the leased IP address.
104
+
105
+
#### Returns ####
106
+
107
+
Array — The leased IP address as four integers.
0 commit comments