Skip to content

Commit 8f44689

Browse files
author
Pavel Petroshenko
authored
Merge pull request #28 from electricimp/develop
Doc fix
2 parents 3143413 + 222040f commit 8f44689

File tree

1 file changed

+59
-60
lines changed

1 file changed

+59
-60
lines changed

Diff for: README.md

+59-60
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
The ConnectionManager class is an Electric Imp device-side library created to simplify connect and disconnect flows.
44

5-
**Note** If you are using ConnectionManager in your code, you should ensure that you *never* call [**server.connect()**](https://developer.electricimp.com/api/server/connect/) or [**server.disconnect()**](https://developer.electricimp.com/api/server/disconnect/). Instead you should only use ConnectionManager’s *connect()* and *disconnect()* methods.
5+
**Note** If you are using ConnectionManager in your code, you should ensure that you *never* call [**server.connect()**](https://developer.electricimp.com/api/server/connect) or [**server.disconnect()**](https://developer.electricimp.com/api/server/disconnect). Instead you should only use ConnectionManager’s *connect()* and *disconnect()* methods.
66

77
**To add this library to your project, add** `#require "ConnectionManager.lib.nut:3.0.0"` **to the top of your device code.**
88

@@ -14,10 +14,10 @@ ConnectionManager can be instantiated with an optional table of settings that mo
1414

1515
| Key | Default | Notes |
1616
| --- | --- | --- |
17-
| *startBehavior* | *START_NO_ACTION* | See below |
17+
| *startBehavior* | *CM_START_NO_ACTION* | See below |
1818
| *stayConnected* | `false` | When set to `true`, the device will aggressively attempt to reconnect when disconnected |
1919
| *retryOnTimeout* | `true` | When set to `true`, the device will attempt to connect again if it times out |
20-
| *blinkupBehavior* | *BLINK_ON_DISCONNECT* | See below |
20+
| *blinkupBehavior* | *CM_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 |
2323
| *errorPolicy* | *RETURN_ON_ERROR* | The disconnection handling policy: *SUSPEND_ON_ERROR*, *RETURN_ON_ERROR or *RETURN_ON_ERROR_NO_DISCONNECT* |
@@ -29,10 +29,8 @@ ConnectionManager can be instantiated with an optional table of settings that mo
2929
3030
// Instantiate ConnectionManager so BlinkUp is always enabled,
3131
// and we automatically aggressively try to reconnect on disconnect
32-
cm <- ConnectionManager({
33-
"blinkupBehavior": CM_BLINK_ALWAYS,
34-
"stayConnected": true
35-
});
32+
cm <- ConnectionManager({ "blinkupBehavior": CM_BLINK_ALWAYS,
33+
"stayConnected" : true });
3634
3735
// Set the recommended buffer size (see note below)
3836
imp.setsendbuffersize(8096);
@@ -41,6 +39,7 @@ imp.setsendbuffersize(8096);
4139
**Note** We’ve found setting the buffer size to 8096 to be very helpful in many applications using ConnectionManager, though your application may require a different buffer size.
4240

4341
#### Setting: startBehavior ####
42+
4443
The *startBehavior* flag modifies what action ConnectionManager takes when initialized.
4544
- *CM_START_NO_ACTION* will take no action after being initialized. This is the default value.
4645
- *CM_START_CONNECTED* will try to connect after being initialized.
@@ -59,7 +58,7 @@ The *blinkupBehavior* flag modifies when ConnectionManager enables the BlinkUp
5958

6059
#### Setting: ackTimeout ####
6160

62-
This value is passed into the imp API method [**server.setsendtimeoutpolicy()**](https://developer.electricimp.com/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://developer.electricimp.com/api/server/setsendtimeoutpolicy/) in your application code.
61+
This value is passed into the imp API method [**server.setsendtimeoutpolicy()**](https://developer.electricimp.com/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://developer.electricimp.com/api/server/setsendtimeoutpolicy) in your application code.
6362

6463
## Class Methods ##
6564

@@ -78,11 +77,11 @@ This method returns the value of ConnectionManager’s internal connection state
7877

7978
```squirrel
8079
if (!cm.isConnected()) {
81-
// If we're not connected, gather some data, then connect
82-
cm.onNextConnect(function() {
83-
local data = sensor.read();
84-
agent.send("data", data);
85-
}).connect();
80+
// If we're not connected, gather some data, then connect
81+
cm.onNextConnect(function() {
82+
local data = sensor.read();
83+
agent.send("data", data);
84+
}).connect();
8685
}
8786
```
8887

@@ -94,13 +93,13 @@ The callback method takes a single parameter, *expected*, which is `true` when t
9493

9594
```squirrel
9695
cm.onDisconnect(function(expected) {
97-
if (expected) {
98-
// Log a regular message that we disconnected as expected
99-
cm.log("Expected Disconnect");
100-
} else {
101-
// Log an error message that we unexpectedly disconnected
102-
cm.error("Unexpected Disconnect");
103-
}
96+
if (expected) {
97+
// Log a regular message that we disconnected as expected
98+
cm.log("Expected Disconnect");
99+
} else {
100+
// Log an error message that we unexpectedly disconnected
101+
cm.error("Unexpected Disconnect");
102+
}
104103
});
105104
```
106105

@@ -112,8 +111,8 @@ The callback function has no parameters.
112111

113112
```squirrel
114113
cm.onConnect(function() {
115-
// Send a message to the agent indicating that we're online
116-
agent.send("online", true);
114+
// Send a message to the agent indicating that we're online
115+
agent.send("online", true);
117116
});
118117
```
119118

@@ -125,8 +124,8 @@ The callback function has no parameters.
125124

126125
```squirrel
127126
cm.onTimeout(function() {
128-
// Go to sleep for 10 minutes if the device fails to connect
129-
server.sleepfor(600);
127+
// Go to sleep for 10 minutes if the device fails to connect
128+
server.sleepfor(600);
130129
});
131130
```
132131

@@ -138,18 +137,18 @@ The callback function has no parameters.
138137

139138
```squirrel
140139
function poll() {
141-
// Wake up every 60 seconds and gather data
142-
imp.wakeup(60, poll);
143-
144-
// Read the data, and insert the timestamp into the data table
145-
// (in this example, we assume sensor.read() returns a table)
146-
local data = sensor.read();
147-
data["ts"] <- time();
148-
149-
// Send the data the next time we connect
150-
cm.onNextConnect(function() {
151-
agent.send("data", data);
152-
});
140+
// Wake up every 60 seconds and gather data
141+
imp.wakeup(60, poll);
142+
143+
// Read the data, and insert the timestamp into the data table
144+
// (in this example, we assume sensor.read() returns a table)
145+
local data = sensor.read();
146+
data.ts <- time();
147+
148+
// Send the data the next time we connect
149+
cm.onNextConnect(function() {
150+
agent.send("data", data);
151+
});
153152
}
154153
```
155154

@@ -163,25 +162,25 @@ The callback function has no parameters.
163162

164163
```squirrel
165164
function poll() {
166-
// Wake up every 60 seconds, connect, send data and disconnect
167-
imp.wakeup(60, poll);
168-
169-
cm.connectFor(function() {
170-
// Read and send the data
171-
local data = sensor.read();
172-
data["ts"] <- time();
173-
agent.send("data", data);
174-
});
165+
// Wake up every 60 seconds, connect, send data and disconnect
166+
imp.wakeup(60, poll);
167+
168+
cm.connectFor(function() {
169+
// Read and send the data
170+
local data = sensor.read();
171+
data.ts <- time();
172+
agent.send("data", data);
173+
});
175174
}
176175
```
177176

178177
**Note** The *connectFor()* method is equivalent to:
179178

180179
```squirrel
181180
cm.onNextConnect(function() {
182-
// Do something
183-
...
184-
cm.disconnect();
181+
// Do something
182+
...
183+
cm.disconnect();
185184
}).connect();
186185
```
187186

@@ -203,7 +202,7 @@ If a connect is in process, the disconnect method will return `false` and won’
203202

204203
The *force* parameter provides a means to specify whether ConnectionManager should disconnect regardless of the connection status (ie. whether it’s in progress or not). The parameter is optional and is `false` by default.
205204

206-
The *flushTimeout* parameter specifies the timeout value used for [**server.flush()**](https://developer.electricimp.com/api/server/flush/) calls. The parameter is
205+
The *flushTimeout* parameter specifies the timeout value used for [**server.flush()**](https://developer.electricimp.com/api/server/flush) calls. The parameter is
207206
optional and is equal to *CM_FLUSH_TIMEOUT* (30 seconds) by default.
208207

209208
```
@@ -212,25 +211,25 @@ cm.disconnect();
212211

213212
### log(*message*) ###
214213

215-
This method will execute a [**server.log()**](https://developer.electricimp.com/api/server/log/) command (if connected), or queue the value of *message* to be logged on the next connect. Any object that can be passed to [**server.log()**](https://developer.electricimp.com/api/server/log/) can be passed to *log()*.
214+
This method will execute a [**server.log()**](https://developer.electricimp.com/api/server/log) command (if connected), or queue the value of *message* to be logged on the next connect. Any object that can be passed to [**server.log()**](https://developer.electricimp.com/api/server/log) can be passed to *log()*.
216215

217216
**Note** The ConnectionManager class stores log messages in memory but doesn’t persist log messages across deep sleeps and cold boots.
218217

219218
```squirrel
220219
cm.onDisconnect(function(expected) {
221-
if (expected) {
222-
// Log a regular message that we disconnected as expected
223-
cm.log("Expected Disconnect");
224-
} else {
225-
// Log an error message that we unexpectedly disconnected
226-
cm.error("Unexpected Disconnect");
227-
}
220+
if (expected) {
221+
// Log a regular message that we disconnected as expected
222+
cm.log("Expected Disconnect");
223+
} else {
224+
// Log an error message that we unexpectedly disconnected
225+
cm.error("Unexpected Disconnect");
226+
}
228227
});
229228
```
230229

231230
### error(*message*) ###
232231

233-
The *error()* method will execute a [**server.error()**](https://developer.electricimp.com/api/server/error/) command (if connected), or queue the value of *errorMessage* to be logged on the next connect. Any object that can be passed to [**server.error()**](https://developer.electricimp.com/api/server/error/) can be passed to *error()*.
232+
The *error()* method will execute a [**server.error()**](https://developer.electricimp.com/api/server/error) command (if connected), or queue the value of *errorMessage* to be logged on the next connect. Any object that can be passed to [**server.error()**](https://developer.electricimp.com/api/server/error) can be passed to *error()*.
234233

235234
**Note** The ConnectionManager class stores log messages in memory but doesn’t persist log messages across deep sleeps and cold boots.
236235

@@ -244,8 +243,8 @@ Alternatively, you can create an `.imptest-builder` file with *CM_TEST_SSID* and
244243

245244
```JSON
246245
{ "CM_TEST_SSID": "<YOUR_WIFI_SSID>",
247-
"CM_TEST_PWD": "<YOUR_WIFI_PASSWORD>" }
248-
```
246+
"CM_TEST_PWD" : "<YOUR_WIFI_PASSWORD>" }
247+
```
249248

250249
## License ##
251250

0 commit comments

Comments
 (0)