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: README.md
+20-15
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
-
# ConnectionManager 1.1.0
1
+
# ConnectionManager 2.0.0
2
2
3
3
The ConnectionManager class is an Electric Imp device-side library aimed at simplifying connect and disconnect flows.
4
4
5
5
**Note** If you are using the ConnectionManager class in your model, you should ensure that you *never* call [**server.connect()**](https://electricimp.com/docs/api/server/connect/) or [**server.disconnect()**](https://electricimp.com/docs/api/server/disconnect/) in your application code. Instead you should use the ConnectionManager’s *connect()* and *disconnect()* methods.
6
6
7
-
**To add this library to your project, add**`#require "ConnectionManager.lib.nut:1.1.0"`**to the top of your device code.**
7
+
**To add this library to your project, add**`#require "ConnectionManager.lib.nut:2.0.0"`**to the top of your device code.**
8
8
9
9
## Class Usage
10
10
@@ -14,8 +14,7 @@ The ConnectionManager class can be instantiated with an optional table of settin
|*startConnected*|`false`| When set to `true` the device immediately connects |
18
-
|*startDisconnected*|`false`| When set to `true` the device immediately disconnects |
17
+
|*startupBehavior*| START_NO_ACTION | See below |
19
18
|*stayConnected*|`false`| When set to `true` the device will aggressively attempt to reconnect when disconnected |
20
19
|*retryOnTimeout*|`true`| When set to `true` the device will attempt to connect again if it times out. |
21
20
|*blinkupBehavior*| BLINK_ON_DISCONNECT | See below |
@@ -24,7 +23,7 @@ The ConnectionManager class can be instantiated with an optional table of settin
24
23
|*ackTimeout*| 1 | Float. Maximum time (in seconds) allowed for the server to acknowledge receipt of data. |
25
24
26
25
```squirrel
27
-
#require "ConnectionManager.lib.nut:1.1.0"
26
+
#require "ConnectionManager.lib.nut:2.0.0"
28
27
29
28
// Instantiate ConnectionManager so BlinkUp is always enabled,
30
29
// and we automatically agressively try to reconnect on disconnect
@@ -38,10 +37,11 @@ imp.setsendbuffersize(8096);
38
37
```
39
38
40
39
**Note** We’ve found setting the buffer size to 8096 to be very helpful in many applications using the ConnectionManager class, though your application may require a different buffer size.
41
-
42
-
#### ackTimeout
43
-
44
-
This value is passed into the imp API method [**server.setsendtimeoutpolicy()**](https://electricimp.com/docs/api/server/setsendtimeoutpolicy/), overriding any value your code may have already set in a separate call to that method (or overridden by a subsequent call your code makes). We recommend that if you make use of ConnectionManager, you ensure that you **never** call [**server.setsendtimeoutpolicy()**](https://electricimp.com/docs/api/server/setsendtimeoutpolicy/) in your application code.
40
+
#### startupBehavior
41
+
The startupBehavior flag modifies what action the ConnectionManager takes when initialized.
42
+
-*ConnectionManager.START_DO_NOTHING* will take no action after being initialized. This is the default value.
43
+
-*ConnectionManager.START_CONNECTED* will try to connect after being initialized.
44
+
-*ConnectionManager.START_DISCONNECTED* will disconnect after being initialized.
45
45
46
46
#### blinkupBehavior
47
47
@@ -54,6 +54,11 @@ The blinkupBehavior flag modifies when the ConnectionManager enables the BlinkUp
54
54
55
55
**Note** impOS™*always* enables the BlinkUp circuit for the first 60 seconds after a cold boot to ensure the imp never enters an unrecoverable state. As a result, regardless of what *blinkupBehavior* flag is set, the imp will enable the BlinkUp circuit for 60 seconds after a cold boot.
56
56
57
+
#### ackTimeout
58
+
59
+
This value is passed into the imp API method [**server.setsendtimeoutpolicy()**](https://electricimp.com/docs/api/server/setsendtimeoutpolicy/), overriding any value your code may have already set in a separate call to that method (or overridden by a subsequent call your code makes). We recommend that if you make use of ConnectionManager, you ensure that you **never** call [**server.setsendtimeoutpolicy()**](https://electricimp.com/docs/api/server/setsendtimeoutpolicy/) in your application code.
60
+
61
+
57
62
## Class Methods
58
63
59
64
### setBlinkUpBehavior(*blinkupBehaviorFlag*)
@@ -65,7 +70,7 @@ The *setBlinkUpBehavior()* method changes the class’ BlinkUp behavior (see [bl
The *isConnected()* method returns the value of ConnectionManager’s internal connected state flag (whether or not we are connected). This flag is updated every five seconds, or as set by the *checkTimeout* setting in the constructor.
71
76
@@ -79,7 +84,7 @@ if (!cm.isConnected()) {
79
84
}
80
85
```
81
86
82
-
## onDisconnect(*callback*)
87
+
###onDisconnect(*callback*)
83
88
84
89
The *onDisconnect()* method assigns a callback function to the onDisconnect event. The onDisconnect event will fire every time the connection state changes from online to offline, or when the ConnectionManager’s *disconnect()* method is called (even if the device is already disconnected).
The *onConnect()* method assigns a callback method to the onConnect event. The onConnect event will fire every time the connection state changes from offline to online, or when the ConnectionManager’s *connect()* method is called (even if the device is already connected).
103
108
@@ -110,7 +115,7 @@ cm.onConnect(function() {
110
115
});
111
116
```
112
117
113
-
## onTimeout(callback)
118
+
###onTimeout(callback)
114
119
115
120
The *onTimeout* method assigns a callback method to the onTimeout event. The onTimeout event will fire every time the device attempts to connect but does not succeed.
116
121
@@ -123,7 +128,7 @@ cm.onTimeout(function() {
123
128
});
124
129
```
125
130
126
-
## onNextConnect(*callback*)
131
+
###onNextConnect(*callback*)
127
132
128
133
The *onNextConnect()* method queues a task (the callback) to run the next time the device connects. If the imp is already connected, the callback will be invoked immediately.
129
134
@@ -150,7 +155,7 @@ function poll() {
150
155
151
156
**Note** If the imp enters a deep sleep or performs a cold boot, the task queue will be cleared.
152
157
153
-
## connectFor(*callback*)
158
+
###connectFor(*callback*)
154
159
155
160
The *connectFor()* method tells the imp to connect, run the callback method, then disconnect when complete. If the imp is already connected, the callback will be invoked immediately, and the imp will disconnect upon completion.
0 commit comments