-
Notifications
You must be signed in to change notification settings - Fork 178
Adding LoRaWAN docs for Mbed-OS 5.8 #414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b40124c
Adding LoRaWAN docs for Mbed-OS 5.8
134ecd5
Update loraradio.md
6c214cd
Copy edit lorawan.md
d028686
Copy edit lorawanevents.md
ac707d5
ERRATA
b8bf550
Fix spaces in errorcodes.md
6b6b377
A link fix as proposed by Antti.
peknis01 50381dd
Update formatting in errorcodes.md
51c6659
Update links in loraradio.md
1af1fa7
Fix link in loraradio.md
b78854d
Update formatting in lorawan.md
7d5f993
Update spacing in errorcodes.md again
5e7113a
Fix link in loraradio.md
1bbbb2c
Update links in lorawan.md
358148d
Merge branch 'new_engine' into lorwan_docs
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<h2 id="lorawan-error-codes">Mbed LoRaWAN Stack error codes</h2> | ||
|
||
All operations on `LoRaWANInterface` return an error code `lorawan_status_t` that reflects success or failure of the operation. | ||
|
||
Here is the list of error codes and their description. | ||
|
||
| Error code | Value | Description | | ||
| --------------- | ------------- | ----------| | ||
| `LORAWAN_STATUS_OK`| 0 | Service done successfully | | ||
| `LORAWAN_STATUS_BUSY`| -1000| Stack busy | | ||
|`LORAWAN_STATUS_WOULD_BLOCK`| -1001 | Stack cannot send at the moment or have nothing to read | | ||
| `LORAWAN_STATUS_SERVICE_UNKNOWN`| -1002 | Unknown service request | | ||
| `LORAWAN_STATUS_PARAMETER_INVALID`| -1003 | Invalid parameter | | ||
| `LORAWAN_STATUS_FREQUENCY_INVALID`| -1004| Invalid frequency | | ||
| `LORAWAN_STATUS_DATARATE_INVALID` | -1005| Invalid frequency and datarate | | ||
| `LORAWAN_STATUS_FREQ_AND_DR_INVALID`| -1006| When stack was unable to send packet in TX window | | ||
|`LORAWAN_STATUS_NO_NETWORK_JOINED`| -1009 | Device is not part of a network yet (Applicable only for OTAA) | | ||
|`LORAWAN_STATUS_LENGTH_ERROR`| -1010 | Payload lenght error | | ||
| `LORAWAN_STATUS_DEVICE_OFF`| -1011 | The device is off, in other words, disconnected state | | ||
| `LORAWAN_STATUS_NOT_INITIALIZED`| -1012| Stack not initialized | | ||
| `LORAWAN_STATUS_UNSUPPORTED`| -1013| Unsupported service | | ||
| `LORAWAN_STATUS_CRYPTO_FAIL`| -1014| Crypto failure | | ||
|`LORAWAN_STATUS_PORT_INVALID`| -1015 | Invalid port | | ||
|`LORAWAN_STATUS_CONNECT_IN_PROGRESS`| -1016 | Connection in progress (application should wait for CONNECT event) | | ||
|`LORAWAN_STATUS_NO_ACTIVE_SESSIONS`| -1017 | No active session in progress | | ||
|`LORAWAN_STATUS_IDLE`| -1018 | Stack idle at the moment | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<h2 id="loraradio-api">LoRaRadio</h2> | ||
|
||
`LoRaRadio` is a pure virtual class that defines APIs for a LoRa radio driver. | ||
|
||
An implementation of this class is passed to the Arm Mbed LoRaWAN stack. Please see existing [Mbed OS supported drivers](https://github.com/ARMmbed/mbed-semtech-lora-rf-drivers) for more information. | ||
|
||
### LoRaRadio class reference | ||
|
||
[](http://os-doc-builder.test.mbed.com/docs/development/mbed-os-api-doxy/class_lo_ra_radio.html) | ||
|
||
### LoRaRadio example | ||
|
||
[](https://os.mbed.com/teams/mbed-os-examples/code/mbed-os-example-lorawan/file/dc95ac6d6d4e/main.cpp) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<h2 id="lorawan-api">LoRaWAN</h2> | ||
|
||
LoRaWAN is a technology designed for low-power battery powered devices. These devices operate in an unlicensed spectrum, creating high desnity wide-area networks. | ||
|
||
Arm Mbed OS provides a native network stack for LoRaWAN, which can run on any Mbed Enabled device with a LoRa radio onboard. | ||
|
||
The [LoRaWANInterface](https://os-doc-builder.test.mbed.com/docs/development/mbed-os-api-doxy/class_lo_ra_w_a_n_interface.html) provides a C++ API for connecting to the internet over a LoRa network. | ||
|
||
## LoRaWANInterface class reference | ||
|
||
[](http://os-doc-builder.test.mbed.com/docs/development/mbed-os-api-doxy/class_lo_ra_w_a_n_interface.html) | ||
|
||
## Usage | ||
|
||
To bring up the Mbed LoRaWAN stack, consider the following progression: | ||
|
||
1) An [EventQueue](https://os.mbed.com/docs/v5.8/reference/eventqueue.html) object: | ||
|
||
```cpp | ||
// construct an event queue | ||
EventQueue ev_queue(NUM_EVENTS * EVENTS_EVENT_SIZE); | ||
``` | ||
|
||
2) A [LoRaRadio](https://os.mbed.com/docs/v5.8/reference/loraradio.html) object: | ||
|
||
```CPP | ||
// construct a LoRadio object | ||
SX1272_LoRaRadio radio(PIN_NAMES ... ); | ||
``` | ||
|
||
3) Instantiate `LoRaWANInterface`, and pass `LoRaRadio` object: | ||
|
||
```CPP | ||
LoRaWANInterface lorawan(radio) ; | ||
``` | ||
|
||
4) Initialize mac layer and pass `EventQueue` object: | ||
|
||
```CPP | ||
lorawan.initialize(&ev_queue); | ||
``` | ||
|
||
5) Set up the event callback: | ||
|
||
```cpp | ||
lorawan_app_callbacks_t callbacks | ||
callbacks.events = mbed::callback(YOUR_EVENT_HANDLER); | ||
lorawan.add_app_callbacks(&callbacks); | ||
``` | ||
|
||
6) Add network credentials (security keys) and any configurations: | ||
|
||
```CPP | ||
lorawan_connect_t connection; | ||
|
||
connection.connect_type = LORAWAN_CONNECTION_OTAA; | ||
connection.connection_u.otaa.app_eui = YOUR_APP_EUI_KEY; | ||
connection.connection_u.otaa.dev_eui = YOUR_DEV_EUI_KEY; | ||
connection.connection_u.otaa.app_key = YOUR_APP_KEY; | ||
connection.connection_u.otaa.nb_trials = MBED_CONF_LORA_NB_TRIALS; | ||
|
||
lorawan.connect(connection); | ||
``` | ||
|
||
### LoRaWAN example | ||
|
||
Please visit our Arm Mbed Online Compiler example, and follow the instructions in the `README.md`. | ||
|
||
[](https://os.mbed.com/teams/mbed-os-examples/code/mbed-os-example-lorawan/file/dc95ac6d6d4e/main.cpp) | ||
|
||
### Related content | ||
|
||
- End-to-end [LoRa on Arm Mbed tutorial](https://docs.mbed.com/docs/lora-with-mbed/en/latest/). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<h2 id="lorawan-configuration">Configuring Mbed LoRaWAN Stack</h2> | ||
|
||
Various parameters for Mbed LoRaWAN stack can be configured via either C++ APIs or by using Mbed configuration system. | ||
|
||
### Using Mbed Configuration system | ||
|
||
Here are the parameters that can be configured using Mbed configuration system: | ||
|
||
```json | ||
{ | ||
"name": "lora", | ||
"config": { | ||
"phy": { | ||
"help": "LoRa PHY region. 0 = EU868 (default), 1 = AS923, 2 = AU915, 3 = CN470, 4 = CN779, 5 = EU433, 6 = IN865, 7 = KR920, 8 = US915, 9 = US915_HYBRID", | ||
"value": "0" | ||
}, | ||
"over-the-air-activation": { | ||
"help": "When set to 1 the application uses the Over-the-Air activation procedure, default: true", | ||
"value": true | ||
}, | ||
"nb-trials": { | ||
"help": "Indicates how many times join can be tried, default: 12", | ||
"value": 12 | ||
}, | ||
"device-eui": { | ||
"help": "Mote device IEEE EUI", | ||
"value": "{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}" | ||
}, | ||
"application-eui": { | ||
"help": "Application IEEE EUI", | ||
"value": "{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}" | ||
}, | ||
"application-key": { | ||
"help": "AES encryption/decryption cipher application key", | ||
"value": "{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}" | ||
}, | ||
"device-address": { | ||
"help": "Device address on the network", | ||
"value": "0x00000000" | ||
}, | ||
"nwkskey": { | ||
"help": "AES encryption/decryption cipher network session key", | ||
"value": "{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}" | ||
}, | ||
"appskey": { | ||
"help": "AES encryption/decryption cipher application session key", | ||
"value": "{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}" | ||
}, | ||
"app-port": { | ||
"help": "LoRaWAN application port, default: 15", | ||
"value": 15 | ||
}, | ||
"tx-max-size": { | ||
"help": "User application data buffer maximum size, default: 64, MAX: 255", | ||
"value": 64 | ||
}, | ||
"adr-on": { | ||
"help": "LoRaWAN Adaptive Data Rate, default: 1", | ||
"value": 1 | ||
}, | ||
"public-network": { | ||
"help": "LoRaWAN will connect to a public network or private network, true = public network", | ||
"value": true | ||
}, | ||
"duty-cycle-on": { | ||
"help": "Enables/disables duty cycling. NOTE: Disable only for testing. Mandatory in many regions.", | ||
"value": true | ||
}, | ||
"lbt-on": { | ||
"help": "Enables/disables LBT. NOTE: [This feature is not yet integrated].", | ||
"value": false | ||
} | ||
} | ||
} | ||
``` | ||
|
||
For changing any of these parameters, edit the `mbed_app.json` file in the root of your application. Prefix the parameter name with `lora.`, e.g., `lora.my-parameter: value`. | ||
|
||
```json | ||
"target_overrides": { | ||
"*": { | ||
"lora.device-address": "0x12345678", | ||
"lora.over-the-air-activation": true, | ||
"lora.duty-cycle-on": true | ||
} | ||
} | ||
``` | ||
|
||
### Using APIs from LoRaWANInterface | ||
|
||
See API reference [here](https://os.mbed.com/docs/v5.8/reference/lorawan.html). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<h2 id="lorawan-events">Mbed LoRaWAN Stack events and callbacks</h2> | ||
|
||
Owing to the fact that most of the LoRaWAN devices are simple telemetry drvices, the stack and its operation need to be as simple as possible. That's why the Mbed LoRaWAN stack is event driven. | ||
|
||
### Network events | ||
|
||
Here is the list of possible events that you can post from the stack to the application: | ||
|
||
| Event | Description | ||
| --------------- | ------------- | | ||
| `CONNECTED` | When the connection is complete | | ||
| `DISCONNECTED` | When the protocol is shut down in response to disconnect() | | ||
| `TX_DONE` | When a packet is transmitted | | ||
| `TX_TIMEOUT` | When the stack is unable to send packet in TX window | | ||
| `TX_ERROR` | A general TX error | | ||
| `TX_CRYPTO_ERROR` | If MIC fails, or any other crypto related error | | ||
| `TX_SCHEDULING_ERROR` | When the stack is unable to schedule a packet | | ||
| `TX_TIMEOUT` | When the stack is unable to send a packet in TX window | | ||
| `RX_DONE` | When a packet is received | | ||
| `RX_ERROR` | A general RX error | | ||
|
||
The application must attach an event handler to the stack. The `LoRaWANInterface` provides an API to attach various callbacks to the stacks. One such callback is the event handler callback. | ||
|
||
### Application callbacks | ||
|
||
The Mbed LoRaWAN stack currently maps 3 different callbacks: | ||
|
||
| Callback type | Description | ||
| --------------- | ------------- | | ||
| `Event callback` | Mandatory, Direction: from stack to application | | ||
| `Link check response callback` |Optional, Direction: from stack to application | | ||
| `Battery level callabck` | Optional, Direction: from application to stack | | ||
|
||
#### Event handler | ||
|
||
An example of attaching your event handler to the stack: | ||
|
||
```CPP | ||
|
||
void your_event_handler(lorawan_event_t event) | ||
{ | ||
switch (event) { | ||
case CONNECTED: | ||
//do something | ||
break; | ||
case DISCONNECTED: | ||
break; | ||
.... | ||
.... | ||
} | ||
} | ||
lorawan_app_callbacks_t callbacks; | ||
|
||
callbacks.events = mbed::callback(your_event_handler); | ||
//lorawan is the LoRaWANInterface object | ||
lorawan.add_app_callbacks(&callbacks); | ||
``` | ||
|
||
#### Link check response handler | ||
|
||
Link check request is a MAC command defined by the LoRaWAN Specification. To receive the response of this MAC command, the user should set `link_check_resp` callback. | ||
|
||
```CPP | ||
void your_link_check_response(uint8_t demod_margin, uint8_t num_gw) | ||
{ | ||
//demod_margin is the demodulation margin | ||
// num_gw represents the number of gateways involved in the path | ||
} | ||
|
||
callbacks.link_check_resp = mbed::callback(your_link_check_response); | ||
lorawan.add_app_callbacks(&callbacks); | ||
|
||
``` | ||
|
||
#### Battery level handler | ||
|
||
The battery level callback is different from others. The direction of this callback is from the application to the stack. In other words, it provides information to the stack. The application is reponsible for letting the stack know about the current battery level. | ||
|
||
```CPP | ||
uint8_t your_battery_level() | ||
{ | ||
return battery_level; | ||
} | ||
|
||
callbacks.battery_level = mbed::callback(your_battery_level); | ||
lorawan.add_app_callbacks(&callbacks); | ||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I this content should go on this page: https://github.com/ARMmbed/Handbook/blob/new_engine/docs/reference/configuration/Connectivity.md
Do you mind if we move it there and make it match that format?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am afraid not. There are many reasons why not. For instance, LoRaWAN is non-IP that's why it is out of the Network Socket scope. Secondly, the purpose of this page is just to let user know what he can overwrite in terms of configuration and how to do it. I think the link you provided, is used for creating json config files for embedded example codes which are then exported to Online Compiler. We are not embedding any example in the docs at the moment (@AnttiKauppila will communicate the reason).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hasnainvirk Thanks for the response.