Skip to content

Commit 984df49

Browse files
author
Pavel Petroshenko
authored
Merge pull request #21 from electricimp/develop
Introduced errorPolicy and waitPolicy arguments for the ConnectionManager constructor
2 parents 8ca2840 + adc7cb0 commit 984df49

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

Diff for: .imptest

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"modelId": "yAGfbguy7_mj" /* B */,
2+
"modelId": "Ih8znqaeDT2G" /* D */,
33
"devices": [
4-
"23236c6938a609ee" /* B */
4+
"23604c058fb7bdee" /* D */
55
],
66
"agentFile": false,
77
"deviceFile": false,

Diff for: ConnectionManager.lib.nut

+11-9
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525

2626
class ConnectionManager {
27-
static VERSION = "2.0.0";
27+
static VERSION = "2.1.0";
2828

2929
static BLINK_ALWAYS = 0;
3030
static BLINK_NEVER = 1;
@@ -57,20 +57,22 @@ class ConnectionManager {
5757

5858
constructor(settings = {}) {
5959
// Grab settings
60-
_checkTimeout = ("checkTimeout" in settings) ? settings.checkTimeout : 5;
61-
_connectTimeout = ("connectTimeout" in settings) ? settings.connectTimeout : 60;
62-
_stayConnected = ("stayConnected" in settings) ? settings.stayConnected : false;
63-
_blinkupBehavior = ("blinkupBehavior" in settings) ? settings.blinkupBehavior : BLINK_ON_DISCONNECT;
64-
_retryOnTimeout = ("retryOnTimeout" in settings) ? settings.retryOnTimeout : true;
65-
local startBehavior = ("startBehavior" in settings) ? settings.startBehavior : START_NO_ACTION;
66-
local ackTimeout = ("ackTimeout" in settings) ? settings.ackTimeout : 1;
60+
_checkTimeout = ("checkTimeout" in settings) ? settings.checkTimeout : 5;
61+
_connectTimeout = ("connectTimeout" in settings) ? settings.connectTimeout : 60;
62+
_stayConnected = ("stayConnected" in settings) ? settings.stayConnected : false;
63+
_blinkupBehavior = ("blinkupBehavior" in settings) ? settings.blinkupBehavior : BLINK_ON_DISCONNECT;
64+
_retryOnTimeout = ("retryOnTimeout" in settings) ? settings.retryOnTimeout : true;
65+
local startBehavior = ("startBehavior" in settings) ? settings.startBehavior : START_NO_ACTION;
66+
local errorPolicy = ("errorPolicy" in settings) ? settings.errorPolicy : RETURN_ON_ERROR;
67+
local waitPolicy = ("waitPolicy" in settings) ? settings.waitPolicy : WAIT_TIL_SENT;
68+
local ackTimeout = ("ackTimeout" in settings) ? settings.ackTimeout : 1;
6769

6870
// Initialize the onConnected task queue and logs
6971
_queue = [];
7072
_logs = [];
7173

7274
// Set the timeout policy + disconnect if required
73-
server.setsendtimeoutpolicy(RETURN_ON_ERROR, WAIT_TIL_SENT, ackTimeout);
75+
server.setsendtimeoutpolicy(errorPolicy, waitPolicy, ackTimeout);
7476

7577
switch (startBehavior) {
7678
case START_NO_ACTION:

Diff for: README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ConnectionManager 2.0.0
1+
# ConnectionManager 2.1.0
22

33
The ConnectionManager class is an Electric Imp device-side library aimed at simplifying connect and disconnect flows.
44

@@ -20,10 +20,12 @@ The ConnectionManager class can be instantiated with an optional table of settin
2020
| *blinkupBehavior* | BLINK_ON_DISCONNECT | See below |
2121
| *checkTimeout* | 5 | Changes how often the ConnectionManager checks the connection state (online / offline). |
2222
| *connectTimeout* | 60 | Float. Maximum time (in seconds) allowed for the imp to connect to the server before timing out. |
23+
| *errorPolicy* | RETURN_ON_ERROR | The disconnection handling policy: either SUSPEND_ON_ERROR, RETURN_ON_ERROR or RETURN_ON_ERROR_NO_DISCONNECT. |
24+
| *waitPolicy* | WAIT_TIL_SENT | The successful transmission criterion: either WAIT_TIL_SENT or WAIT_FOR_ACK. |
2325
| *ackTimeout* | 1 | Float. Maximum time (in seconds) allowed for the server to acknowledge receipt of data. |
2426

2527
```squirrel
26-
#require "ConnectionManager.lib.nut:2.0.0"
28+
#require "ConnectionManager.lib.nut:2.1.0"
2729
2830
// Instantiate ConnectionManager so BlinkUp is always enabled,
2931
// and we automatically agressively try to reconnect on disconnect

Diff for: example/ConnectionManager.example.nut

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2323
// OTHER DEALINGS IN THE SOFTWARE.
2424

25-
26-
#require "ConnectionManager.lib.nut:2.0.0"
25+
26+
#require "ConnectionManager.lib.nut:2.1.0"
2727

2828
// Instantiate ConnectionManager so BlinkUp is always enabled,
2929
// and starts connected.
@@ -35,9 +35,9 @@ cm <- ConnectionManager({
3535

3636
// Set the timeout behaviour after failing to connect for 90 seconds.
3737
cm.onTimeout(function() {
38-
// Go to sleep for 10 minutes
38+
// Go to sleep for 10 minutes
3939
server.sleepfor(600);
4040
});
4141

42-
// Set the recommended buffer size
42+
// Set the recommended buffer size
4343
imp.setsendbuffersize(8096);

0 commit comments

Comments
 (0)