Skip to content

Commit 60c536b

Browse files
committed
Update README to bring it up to date to latest changes
1 parent 95be03a commit 60c536b

File tree

1 file changed

+60
-40
lines changed

1 file changed

+60
-40
lines changed

README.md

Lines changed: 60 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,60 @@
1-
# Arduino Library for network connections management
2-
3-
Library for handling and managing network connections by providing keepAlive functionalities and reconnection attempts. Initially for WiFi, GSM and NB, its goal is to be extended to more networking layers over diverse hardware (Ethernet, BlueTooth et al.)
4-
5-
6-
## Usage
7-
8-
## Credits
9-
10-
## Website
11-
12-
# License
13-
14-
This library is free software; you can redistribute it and/or
15-
modify it under the terms of the GNU Lesser General Public
16-
License as published by the Free Software Foundation; either
17-
version 2.1 of the License, or (at your option) any later version.
18-
19-
This library is distributed in the hope that it will be useful,
20-
but WITHOUT ANY WARRANTY; without even the implied warranty of
21-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22-
Lesser General Public License for more details.
23-
24-
You should have received a copy of the GNU Lesser General Public
25-
License along with this library; if not, write to the Free Software
26-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27-
28-
29-
### ConnectionHandler
30-
31-
**Connection Handler** is configured via a series of compiler directives, including the correct implementation of the class based on which board is selected.
32-
33-
### How to use it
34-
- Instantiate the class with `ConnectionHandler conHandler(SECRET_SSID, SECRET_PASS);` if you are using a WiFi board, otherwise replace **WiFi** with **GSM** or **NB** or any future implementation minding to carefully pass the init parameters to the constructor (i.e.: for the GSM you'll need to pass PIN, APN, login, password).
35-
36-
- The `update()` method does all the work. It uses a finite state machine and is responsible for connection and reconnection to a network. The method is designed to be non-blocking by using time (milliseconds) to perform its tasks.
37-
38-
- `&getClient()` returns a reference to an instance of the `Client` class used to connect to the network.
39-
40-
- `getStatus()` returns the network connection status. The different states are defined in an `enum`
1+
Arduino Library for network connections management
2+
==================================================
3+
4+
Library for handling and managing network connections by providing keep-alive functionality and automatic reconnection in case of connection-loss. It supports the following boards:
5+
* **WiFi**: MKR 1000, MKR WiFi 1010, ESP8266
6+
* **GSM**: MKR GSM 1400
7+
* **5G**: MKR NB 1500
8+
* **LoRa**: MKR WAN 1300/1310
9+
10+
### How-to-use
11+
12+
```C++
13+
/* ... */
14+
#include <Arduino_ConnectionHandler.h>
15+
/* ... */
16+
#if defined(BOARD_HAS_WIFI)
17+
WiFiConnectionHandler conMan("SECRET_SSID", "SECRET_PASS");
18+
#elif defined(BOARD_HAS_GSM)
19+
GSMConnectionHandler conMan("SECRET_PIN", "SECRET_APN", "SECRET_GSM_LOGIN", "SECRET_GSM_PASS");
20+
#elif defined(BOARD_HAS_NB)
21+
NBConnectionHandler conMan("SECRET_PIN", "SECRET_APN", "SECRET_GSM_LOGIN", "SECRET_GSM_PASS");
22+
#elif defined(BOARD_HAS_LORA)
23+
LoRaConnectionHandler conMan("SECRET_APP_EUI", "SECRET_APP_KEY");
24+
#endif
25+
/* ... */
26+
void setup() {
27+
Serial.begin(9600);
28+
while(!Serial) { }
29+
30+
setDebugMessageLevel(DBG_INFO);
31+
32+
conMan.addCallback(NetworkConnectionEvent::CONNECTED, onNetworkConnect);
33+
conMan.addCallback(NetworkConnectionEvent::DISCONNECTED, onNetworkDisconnect);
34+
conMan.addCallback(NetworkConnectionEvent::ERROR, onNetworkError);
35+
}
36+
37+
void loop() {
38+
/* The following code keeps on running connection workflows on our
39+
* ConnectionHandler object, hence allowing reconnection in case of failure
40+
* and notification of connect/disconnect event if enabled (see
41+
* addConnectCallback/addDisconnectCallback) NOTE: any use of delay() within
42+
* the loop or methods called from it will delay the execution of .check(),
43+
* which might not guarantee the correct functioning of the ConnectionHandler
44+
* object.
45+
*/
46+
conMan.check();
47+
}
48+
/* ... */
49+
void onNetworkConnect() {
50+
Serial.println(">>>> CONNECTED to network");
51+
}
52+
53+
void onNetworkDisconnect() {
54+
Serial.println(">>>> DISCONNECTED from network");
55+
}
56+
57+
void onNetworkError() {
58+
Serial.println(">>>> ERROR");
59+
}
60+
```

0 commit comments

Comments
 (0)