2017-10-08 12:47:17 +02:00
|
|
|
/**
|
|
|
|
* @defgroup pkg_semtech-loramac Semtech LoRaMAC implementation
|
|
|
|
* @ingroup pkg
|
|
|
|
* @ingroup net
|
|
|
|
* @brief Provides a RIOT adaption of Semtech LoRaMAC implementation
|
|
|
|
*
|
|
|
|
* # Introduction
|
|
|
|
*
|
|
|
|
* This package provides an API built on top of the
|
2018-02-28 23:46:43 +01:00
|
|
|
* [Semtech LoRaMAC-node](https://github.com/Lora-net/LoRaMac-node) reference
|
2017-10-08 12:47:17 +02:00
|
|
|
* implementation of a LoRa network.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* # Importing this package in an application
|
|
|
|
*
|
|
|
|
* This package only works with Semtech SX1272 and SX1276 radio devices. Thus,
|
|
|
|
* in order to use it properly, the application `Makefile` must import the
|
|
|
|
* corresponding device driver:
|
|
|
|
* ```
|
|
|
|
* USEMODULE += sx1272 # for a SX1272 radio device
|
|
|
|
* USEMODULE += sx1276 # for a SX1276 radio device
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* In order to use this package in an application, add the following in
|
|
|
|
* the application `Makefile`:
|
|
|
|
* ```
|
|
|
|
* USEPKG += semtech-loramac
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* Since the LoRa radio depends on regional parameters regarding the access
|
|
|
|
* to the physical support, the region where the device is used needs to be
|
|
|
|
* set at compile time. Example for EU868:
|
|
|
|
* ```
|
|
|
|
* CFLAGS += -DREGION_EU868
|
2019-02-20 21:39:16 +01:00
|
|
|
* CFLAGS += -DLORAMAC_ACTIVE_REGION=LORAMAC_REGION_EU868
|
2017-10-08 12:47:17 +02:00
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* # Using the package API
|
|
|
|
*
|
|
|
|
* The package provides a simple API for initializing the MAC, setting/getting
|
|
|
|
* parameters, joining a network and sending/receiving packets to/from a LoRa
|
|
|
|
* Network.
|
|
|
|
*
|
|
|
|
* In your `main.c`, some header files must be first included:
|
|
|
|
* ```c
|
|
|
|
* #include "net/loramac.h" /* core loramac definitions */
|
2018-03-19 08:28:13 +01:00
|
|
|
* #include "semtech_loramac.h" /* package API */
|
2017-10-08 12:47:17 +02:00
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* Then define global variables:
|
|
|
|
* ```c
|
2018-03-19 08:28:13 +01:00
|
|
|
* semtech_loramac_t loramac; /* The loramac stack device descriptor */
|
2017-10-08 12:47:17 +02:00
|
|
|
* /* define the required keys for OTAA, e.g over-the-air activation (the
|
|
|
|
* null arrays need to be updated with valid LoRa values) */
|
2018-02-25 14:22:30 +01:00
|
|
|
* static const uint8_t deveui[LORAMAC_DEVEUI_LEN] = { 0x00, 0x00, 0x00, 0x00, \
|
|
|
|
* 0x00, 0x00, 0x00, 0x00 };
|
|
|
|
* static const uint8_t appeui[LORAMAC_APPEUI_LEN] = { 0x00, 0x00, 0x00, 0x00, \
|
|
|
|
* 0x00, 0x00, 0x00, 0x00 };
|
|
|
|
* static const uint8_t appkey[LORAMAC_APPKEY_LEN] = { 0x00, 0x00, 0x00, 0x00, \
|
|
|
|
* 0x00, 0x00, 0x00, 0x00, \
|
|
|
|
* 0x00, 0x00, 0x00, 0x00, \
|
|
|
|
* 0x00, 0x00, 0x00, 0x00 };
|
2017-10-08 12:47:17 +02:00
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* Now in the `main` function:
|
2018-03-19 08:28:13 +01:00
|
|
|
* 1. initialize the LoRaMAC MAC layer
|
|
|
|
* 2. set the LoRa keys
|
|
|
|
* 3. join the network
|
|
|
|
* 4. send some data to the network
|
|
|
|
* 5. wait for any potentially received data
|
2017-10-08 12:47:17 +02:00
|
|
|
*
|
|
|
|
* ```c
|
|
|
|
* int main(void)
|
|
|
|
* {
|
2018-03-19 08:28:13 +01:00
|
|
|
* /* 1. initialize the LoRaMAC MAC layer */
|
|
|
|
* semtech_loramac_init(&loramac);
|
2017-10-08 12:47:17 +02:00
|
|
|
*
|
2018-03-19 08:28:13 +01:00
|
|
|
* /* 2. set the keys identifying the device */
|
|
|
|
* semtech_loramac_set_deveui(&loramac, deveui);
|
|
|
|
* semtech_loramac_set_appeui(&loramac, appeui);
|
|
|
|
* semtech_loramac_set_appkey(&loramac, appkey);
|
2017-10-08 12:47:17 +02:00
|
|
|
*
|
2018-03-19 08:28:13 +01:00
|
|
|
* /* 3. join the network */
|
|
|
|
* if (semtech_loramac_join(&loramac, LORAMAC_JOIN_OTAA) != SEMTECH_LORAMAC_JOIN_SUCCEEDED) {
|
2017-10-08 12:47:17 +02:00
|
|
|
* puts("Join procedure failed");
|
2018-02-28 23:46:43 +01:00
|
|
|
* return 1;
|
2017-10-08 12:47:17 +02:00
|
|
|
* }
|
|
|
|
* puts("Join procedure succeeded");
|
|
|
|
*
|
2018-03-19 08:28:13 +01:00
|
|
|
* /* 4. send some data */
|
2018-02-25 14:22:30 +01:00
|
|
|
* char *message = "This is RIOT";
|
2019-04-10 08:20:40 +02:00
|
|
|
* if (semtech_loramac_send(&loramac,
|
|
|
|
* (uint8_t *)message, strlen(message)) != SEMTECH_LORAMAC_TX_OK) {
|
|
|
|
printf("Cannot send message '%s'\n", message);
|
|
|
|
* return 1;
|
|
|
|
* }
|
2018-03-19 08:28:13 +01:00
|
|
|
*
|
|
|
|
* /* 5. wait for any potentially received data */
|
|
|
|
* if (semtech_loramac_recv(&loramac) == SEMTECH_LORAMAC_DATA_RECEIVED) {
|
|
|
|
* loramac.rx_data.payload[loramac.rx_data.payload_len] = 0;
|
|
|
|
* printf("Data received: %s, port: %d\n",
|
|
|
|
* (char *)loramac.rx_data.payload, loramac.rx_data.port);
|
|
|
|
* }
|
2017-10-08 12:47:17 +02:00
|
|
|
* }
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* @warning It is not possible to directly call the original LoRaMAC-node API
|
|
|
|
* using this package. This package should only be considered as a
|
|
|
|
* wrapper around the original LoRaMAC-node API and only the API
|
|
|
|
* provided by this package should be used.
|
|
|
|
*
|
|
|
|
* # License
|
|
|
|
*
|
|
|
|
* The library is using the BSD 3-clause license.
|
|
|
|
*
|
2019-04-10 08:21:41 +02:00
|
|
|
* @see https://github.com/Lora-net/LoRaMac-node
|
|
|
|
*/
|