Skip to content

Commit 46eaf04

Browse files
author
betzrhodes
authored
Merge pull request #14 from electricimp/develop
v2.2.0
2 parents 8006751 + e63f694 commit 46eaf04

23 files changed

+1462
-739
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
.build_api_key.json*
55
.imptest*
66
settings.wrench*
7+
.impt.auth

.impt.test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"deviceGroupId": "9202e663-db1a-705d-95e1-63269327cdca",
3+
"timeout": 60,
4+
"stopOnFail": false,
5+
"allowDisconnect": false,
6+
"builderCache": false,
7+
"testFiles": [
8+
"tests/00.W5500.device.test.nut",
9+
"tests/01.W5500.DHCP.device.test.nut"
10+
],
11+
"deviceFile": "tests/BaseIncludes.device.nut"
12+
}

DHCP/README.md

Lines changed: 80 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
# Wiznet 5500 DHCP #
22

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.
44

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**
66

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 ##
813

914
### Constructor: W5500.DHCP(*wiz*) ###
1015

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.
17+
18+
| Parameter | Data Type | Required? | Description |
19+
| --- | --- | --- | --- |
20+
| *wiz* | Wiznet driver | Yes | The driver controlling the W5500 |
21+
22+
#### Returns ####
23+
24+
The instance.
1225

1326
#### Example ####
1427

@@ -30,48 +43,68 @@ dhcp <- W5500.DHCP(wiz);
3043

3144
### onLease(*callback*) ###
3245

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.
47+
48+
#### Parameters ####
49+
50+
| Parameter | Data&nbsp;Type | Required? | Description |
51+
| --- | --- | --- | --- |
52+
| *callback* | Function | Yes | The callback has one parameter of its own, *error*, which informs the user of timeouts and errors, or will be `null` |
3453

3554
#### Error Messages ####
3655

37-
| Error Message | Description |
56+
| Error&nbsp;Message | Description |
3857
| --- | --- |
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 |
4665

4766
#### Example ####
4867

4968
```squirrel
5069
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");
5372
});
5473
```
5574

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.
78+
79+
#### Parameters ####
80+
81+
| Parameter | Data&nbsp;Type | Required? | Description |
82+
| --- | --- | --- | --- |
83+
| *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 ####
5786

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*).
5988

6089
#### Example ####
6190

6291
```squirrel
6392
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");
6796
});
6897
6998
dhcp.renewLease();
7099
```
71100

72101
### getIP() ###
73102

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 &mdash; The leased IP address as four integers.
75108

76109
#### Example ####
77110

@@ -82,18 +115,26 @@ server.log(format("IP address = %d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]));
82115

83116
### getSubnetMask() ###
84117

85-
This method returns the subnet mask as an array of four integers.
118+
This method retrieves the network subnet mask.
119+
120+
#### Returns ####
121+
122+
Array &mdash; The subnet mask as four integers.
86123

87124
#### Example ####
88125

89126
```squirrel
90-
local subnet_mask = dhcp.getSubnetMask();
91-
server.log(format("Subnet mask = %d.%d.%d.%d", subnet_mask[0], subnet_mask[1], subnet_mask[2], subnet_mask[3]));
127+
local subnetMask = dhcp.getSubnetMask();
128+
server.log(format("Subnet mask = %d.%d.%d.%d", subnetMask[0], subnetMask[1], subnetMask[2], subnetMask[3]));
92129
```
93130

94131
### getRouterAddress() ###
95132

96-
This method returns the gateway address as an array of four integers.
133+
This method retrieves the network gateway address.
134+
135+
#### Returns ####
136+
137+
Array &mdash; The gateway address as four integers.
97138

98139
#### Example ####
99140

@@ -104,31 +145,39 @@ server.log(format("Router IP address = %d.%d.%d.%d", router[0], router[1], route
104145

105146
### getLeaseTime() ###
106147

107-
This method returns the lease duration, in seconds, as an integer.
148+
This method retrieves the lease duration in seconds.
108149

109-
#### Example Code:
150+
#### Returns ####
151+
152+
Integer &mdash; the lease duration (seconds).
153+
154+
#### Example ####
110155

111156
```squirrel
112157
local leaseTime = dhcp.getLeaseTime();
113-
server.log("IP address lease time: " + leaseTime);
158+
server.log("IP address lease time: " + leaseTime + "s");
114159
```
115160

116161
### getDNS() ###
117162

118-
This method returns an array of DNS entries, each of which is an an array of four integers.
163+
This method retrieves a set of DNS entries.
164+
165+
#### Returns ####
166+
167+
Array &mdash; The DNS entries, each of which is an array of four integers.
119168

120169
#### Example ####
121170

122171
```squirrel
123172
local dns = dhcp.getDNS();
124173
foreach (index, server in dns) {
125-
server.log(format("DNS #%d address = %d.%d.%d.%d", (index + 1), server[0], server[1], server[2], server[3]));
174+
server.log(format("DNS #%d address = %d.%d.%d.%d", (index + 1), server[0], server[1], server[2], server[3]));
126175
}
127176
```
128177

129178
## Extended Example For imp005 ##
130179

131-
Please see [example.device.nut](example.device.nut) for an extended example.
180+
Please see the examples directory [DHCP Example](../examples#dhcp-example) for an extended example.
132181

133182
## License ##
134183

DHCP/example.agent.nut

Whitespace-only changes.

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright 2016 Electric Imp
3+
Copyright 2016-19 Electric Imp
44

55
SPDX-License-Identifier: MIT
66

0 commit comments

Comments
 (0)