-
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
Changes from 5 commits
b40124c
134ecd5
6c214cd
d028686
ac707d5
b8bf550
6b6b377
50381dd
51c6659
1af1fa7
b78854d
7d5f993
5e7113a
1bbbb2c
358148d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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, i.e., 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| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove space between - and the number for these errors: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @AnotherButler, would it be possible for you to do these 3 whitespace modifications Kimmo requested? Both Hasnain and Kimmo are on holiday. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AnttiKauppila Sure thing. I'll do that shortly. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<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/v5.8/mbed-os-api-doxy/class_l_o_r_a_radio.html) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This link doesn't work. Please fix it or let me know when it will go into effect. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it will work after the release. I am not sure. I just followed what others had been doing here. Seemingly, the script to fetch doxygen from Mbed-OS would make it work during the release process. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is valid link currently: |
||
|
||
### LoRaRadio example | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add an example here from Mbed teams. For an example, please see the LowPowerTicker user API. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AnttiKauppila Could you please communicate to Amanda through email the reason why we are not posting an embedded example ? I didn't not get hold of the full context when we were discussing this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AnotherButler Okay, I got clearance to tell you the reason. Please note that we do have a very simple example code which do exist at os.mbed.com, https://os.mbed.com/teams/mbed-os-examples/code/lorawan-example/. But this is private. We can't make it public as it will need at least two months of process through legal and we don't have enough time for it. So for the time being it will suffice to just provide a link for the github repository which contains full example code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm fine with this going in without an example for now, but we should add an example as soon as possible. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi Amanda, example is now public and ready for Online compiler There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is valid link currently: |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<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://github.com/ARMmbed/mbed-os/blob/feature-lorawan/features/lorawan/LoRaWANInterface.h) provides a C++ API for connecting to the internet over a LoRa network. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We prefer not to link to GitHub. Is there a Doxygen page we could link to, instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AnttiKauppila This relates to #414 (comment). Please clarify the reason to Amanda. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AnotherButler Please check this #414 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should use real doxygen tag here, but can we change this after release Amanda when we know the real path? Or is there already some doxygen generated for the release? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is valid link currently: |
||
|
||
## LoRaWANInterface class reference | ||
|
||
[](http://os-doc-builder.test.mbed.com/docs/v5.8/mbed-os-api-doxy/class_l_o_r_a_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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Query: Do these numbers indicate steps that need to happen in order? Or is it more of a logical grouping of items? [This only matters because we use numbers for ordered steps and bullets for unordered groupings.] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its an ordered progression. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
```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) Setup 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 [github example repository](https://github.com/ARMmbed/mbed-os-example-lorawan) and follow the instructions in the `README.md`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please move this example to Mbed teams? I don't have permissions to, but I would like to transclude this example like we do for other APIs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AnttiKauppila Related to the comments above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AnotherButler Please check this #414 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This must be used here as a correct link: https://os.mbed.com/teams/mbed-os-examples/code/mbed-os-example-lorawan I don't have access to Hasnain's fork or this repo, so could you please replace this Amanda? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pekka has corrected this link already together with Antti. |
||
|
||
### Related content | ||
|
||
- End-to-end [LoRa on Arm Mbed tutorial](https://docs.mbed.com/docs/lora-with-mbed/en/latest/). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<h2 id="lorawan-configuration">Configuring Mbed LoRaWAN Stack</h2> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. @hasnainvirk Thanks for the response.
|
||
|
||
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). |
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); | ||
``` |
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.
👍 Thanks for remembering to add this section.