forked from RIOT-OS/RIOT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request RIOT-OS#11022 from jia200x/pr/gnrc_lorawan
gnrc_lorawan: add support for GNRC based LoRaWAN stack
- Loading branch information
Showing
29 changed files
with
3,085 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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 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,60 @@ | ||
# name of your application | ||
APPLICATION = gnrc_lorawan | ||
|
||
USEMODULE += shell | ||
USEMODULE += shell_commands | ||
USEMODULE += gnrc_netdev_default | ||
USEMODULE += auto_init_gnrc_netif | ||
USEMODULE += gnrc_lorawan | ||
USEMODULE += gnrc_pktdump | ||
|
||
BOARD ?= b-l072z-lrwan1 | ||
RIOTBASE ?= ../../ | ||
|
||
# Turn on developer helpers | ||
DEVELHELP ?= 1 | ||
|
||
# use SX1276 by default | ||
DRIVER ?= sx1276 | ||
|
||
USEMODULE += $(DRIVER) | ||
|
||
# Required for the cipher module */ | ||
CFLAGS += -DCRYPTO_AES | ||
# | ||
# We can reduce the size of the packet buffer for LoRaWAN, since there's no IP | ||
# support. This will reduce RAM consumption. | ||
CFLAGS += -DGNRC_PKTBUF_SIZE=512 | ||
|
||
|
||
########################### COMPILE TIME CONFIGURATION ######################## | ||
# NOTE: The following options can be configured on runtime as well using | ||
# `ifconfig` | ||
|
||
# OTAA compile time configuration keys | ||
CFLAGS += -DLORAMAC_APP_KEY_DEFAULT=\{0x00\,0x00\,0x00\,0x00\,0x00\,0x00\,0x00\,0x00\,0x00\,0x00\,0x00\,0x00\,0x00\,0x00\,0x00\,0x00\} | ||
CFLAGS += -DLORAMAC_APP_EUI_DEFAULT=\{0x00\,0x00\,0x00\,0x00\,0x00\,0x00\,0x00\,0x00\} | ||
CFLAGS += -DLORAMAC_DEV_EUI_DEFAULT=\{0x00\,0x00\,0x00\,0x00\,0x00\,0x00\,0x00\,0x00\} | ||
|
||
# Uncomment and replace with proper keys for joining with ABP | ||
# NOTE: This values will be overriten in case of OTAA. | ||
#CFLAGS += -DLORAMAC_DEV_ADDR_DEFAULT=\{0x00\,0x00\,0x00\,0x00\} | ||
#CFLAGS += -DLORAMAC_NWK_SKEY_DEFAULT=\{0x00\,0x00\,0x00\,0x00\,0x00\,0x00\,0x00\,0x00\,0x00\,0x00\,0x00\,0x00\,0x00\,0x00\,0x00\,0x00\} | ||
#CFLAGS += -DLORAMAC_APP_SKEY_DEFAULT=\{0x00\,0x00\,0x00\,0x00\,0x00\,0x00\,0x00\,0x00\,0x00\,0x00\,0x00\,0x00\,0x00\,0x00\,0x00\,0x00\} | ||
|
||
# Comment/uncomment as necessary | ||
CFLAGS += -DLORAMAC_DEFAULT_JOIN_PROCEDURE=LORAMAC_JOIN_OTAA | ||
#CFLAGS += -DLORAMAC_DEFAULT_JOIN_PROCEDURE=LORAMAC_JOIN_ABP | ||
|
||
# Uncomment to set the highest DR for the EU868 in order to maximize throughput. | ||
# If uncommented, the default value (DR0) is used. | ||
# Note this value is also used for the OTAA. | ||
#CFLAGS += -DLORAMAC_DEFAULT_DR=LORAMAC_DR_5 | ||
|
||
# Set the default RX2 datarate to DR3 (used by The Things Network) | ||
CFLAGS += -DLORAMAC_DEFAULT_RX2_DR=LORAMAC_DR_3 | ||
|
||
# Set default messages to unconfirmable | ||
CFLAGS += -DLORAMAC_DEFAULT_TX_MODE=LORAMAC_TX_CNF | ||
|
||
include $(RIOTBASE)/Makefile.include |
This file contains 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,20 @@ | ||
BOARD_INSUFFICIENT_MEMORY := \ | ||
arduino-duemilanove \ | ||
arduino-leonardo \ | ||
arduino-mega2560 \ | ||
arduino-nano \ | ||
arduino-uno \ | ||
atmega328p \ | ||
nucleo-f031k6 \ | ||
nucleo-f042k6 \ | ||
nucleo-l031k6 \ | ||
stm32f030f4-demo \ | ||
stm32f0discovery \ | ||
msb-430 \ | ||
msb-430h \ | ||
telosb \ | ||
waspmote-pro \ | ||
wsn430-v1_3b \ | ||
wsn430-v1_4 \ | ||
z1 \ | ||
# |
This file contains 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,145 @@ | ||
GNRC LoRaWAN application | ||
============================= | ||
|
||
This application is a showcase for testing GNRC LoRaWAN stack. You should be | ||
able to send and receive LoRaWAN packets and perform basic LoRaWAN commands | ||
(Link Check). | ||
|
||
The MAC layers still doesn't implement any duty cycle restriction mechanism. | ||
However, it respects the retransmission procedure. | ||
|
||
Only Class A and EU868 region are supported so far. | ||
|
||
Usage | ||
===== | ||
|
||
It's necessary to join the LoRaWAN network either via OTAA or ABP. | ||
All keys, addresses and EUIs are in network endian (big endian). | ||
|
||
## OTAA | ||
|
||
Join by OTAA is set by default. | ||
Set the Application Key, Device EUI and Application EUI using ifconfig. Assuming | ||
the interface pid is 3: | ||
|
||
``` | ||
ifconfig 3 set deveui AAAAAAAAAAAAAAAA | ||
ifconfig 3 set appeui BBBBBBBBBBBBBBBB | ||
ifconfig 3 set appkey CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC | ||
ifconfig 3 up | ||
``` | ||
|
||
Wait for 5-6 seconds. Type `ifconfig`. The link status should be `up`: | ||
|
||
``` | ||
Iface 3 HWaddr: 26:01:27:2F Frequency: 868500000Hz BW: 125kHz SF: 7 | ||
CR: 4/5 Link: up | ||
TX-Power: 14dBm State: SLEEP Demod margin.: 0 Num gateways.: 0 | ||
IQ_INVERT | ||
RX_SINGLE OTAA | ||
``` | ||
|
||
## ABP | ||
|
||
Deactivate OTAA using ifconfig and set the AppSKey, NwkSKey and DevAddr; | ||
|
||
``` | ||
ifconfig 3 -otaa | ||
ifconfig 3 set appskey DDDDDDDDDDDDDDDD | ||
ifconfig 3 set nwkskey EEEEEEEEEEEEEEEE | ||
ifconfig 3 set addr FFFFFFFF | ||
ifconfig 3 up | ||
``` | ||
|
||
The join by ABP occurs immediately. | ||
|
||
Alternatively all keys can be set using CFLAGS so it's only required to | ||
select join mode and type `ifconfig <if_pid> up`. | ||
|
||
E.g in the application Makefile: | ||
|
||
``` | ||
CFLAGS += -DLORAMAC_DEV_EUI_DEFAULT=\{0xAA\,0xAA\,0xAA\,0xAA\,0xAA\,0xAA\,0xAA\,0xAA\} | ||
CFLAGS += -DLORAMAC_APP_EUI_DEFAULT=\{0xBB\,0xBB\,0xBB\,0xBB\,0xBB\,0xBB\,0xBB\,0xBB\} | ||
CFLAGS += -DLORAMAC_APP_KEY_DEFAULT=\{0xCC\,0xCC\,0xCC\,0xCC\,0xCC\,0xCC\,0xCC\,0xCC\,0xCC\,0xCC\,0xCC\,0xCC\,0xCC\,0xCC\,0xCC\,0xCC\} | ||
CFLAGS += -DLORAMAC_APP_SKEY_DEFAULT=\{0xDD\,0xDD\,0xDD\,0xDD\,0xDD\,0xDD\,0xDD\,0xDD\,0xDD\,0xDD\,0xDD\,0xDD\,0xDD\,0xDD\,0xDD\,0xDD\} | ||
CFLAGS += -DLORAMAC_NWK_SKEY_DEFAULT=\{0xEE\,0xEE\,0xEE\,0xEE\,0xEE\,0xEE\,0xEE\,0xEE\,0xEE\,0xEE\,0xEE\,0xEE\,0xEE\,0xEE\,0xEE\,0xEE\} | ||
CFLAGS += -DLORAMAC_DEV_ADDR_DEFAULT=\{0xFF\,0xFF\,0xFF\,0xFF\} | ||
``` | ||
|
||
## Send data | ||
|
||
After join, send data using `send` command. E.g to send "Hello RIOT!" to port 2: | ||
|
||
``` | ||
send 3 "Hello RIOT!" 2 | ||
``` | ||
|
||
## Changing datarate of transmission | ||
Use `ifconfig` to change the datarate of the transmission. E.g to set the DR to | ||
2: | ||
|
||
``` | ||
ifconfig 3 set dr 2 | ||
``` | ||
|
||
## Perform a Link Check | ||
|
||
Use `ifconfig` to request a Link Check on the next transmission: | ||
|
||
``` | ||
ifconfig 3 link_check | ||
``` | ||
|
||
Send some data. The result of the Link Check request can be seen with | ||
`ifconfig`. | ||
|
||
``` | ||
ifconfig 3 link_check | ||
send 3 "Join the RIOT!" | ||
``` | ||
|
||
Check demodulation margin and number of gateways using `ifconfig` | ||
|
||
``` | ||
ifconfig | ||
Iface 3 HWaddr: 26:01:2C:EA Frequency: 867500000Hz BW: 125kHz SF: 7 | ||
CR: 4/5 Link: up | ||
TX-Power: 14dBm State: SLEEP Demod margin.: 14 Num gateways.: 2 | ||
IQ_INVERT | ||
RX_SINGLE OTAA | ||
``` | ||
|
||
## Confirmable and unconfirmable messages | ||
|
||
Use `ifconfig` to set the `ack_req` flag. With this flag on, messages are | ||
confirmable. | ||
|
||
E.g send confirmable messages: | ||
|
||
``` | ||
ifconfig 3 ack_req | ||
send "My confirmable message" | ||
``` | ||
|
||
And unconfirmable messages: | ||
|
||
``` | ||
ifconfig 3 -ack_req | ||
send "My unconfirmable message" | ||
``` | ||
|
||
Current state and future plans | ||
============ | ||
|
||
The current GNRC LoRaWAN stack is still in an experimental state. It's still | ||
not compliant with the LoRaWAN specification because some features like duty | ||
cycle restrictions and some FOps are missing. Work in progress. | ||
|
||
Next steps: | ||
- Add other regions (US915, etc) | ||
- Add Adaptive Data Rate | ||
- Add Duty Cycle restrictions | ||
- Add support for RTC |
This file contains 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,109 @@ | ||
/* | ||
* Copyright (C) 2019 HAW Hamburg | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
/** | ||
* @ingroup tests | ||
* @{ | ||
* @file | ||
* @brief Test application for GNRC LoRaWAN | ||
* | ||
* @author José Ignacio Alamos <[email protected]> | ||
* @} | ||
*/ | ||
|
||
#include <errno.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#include "thread.h" | ||
#include "xtimer.h" | ||
#include "shell.h" | ||
#include "shell_commands.h" | ||
|
||
#include "board.h" | ||
|
||
#include "net/gnrc/netapi.h" | ||
#include "net/gnrc/netif.h" | ||
|
||
#include "net/gnrc/pktbuf.h" | ||
#include "net/gnrc/pktdump.h" | ||
#include "net/gnrc/netreg.h" | ||
|
||
#define LORAWAN_PORT (2U) | ||
|
||
static void _usage(void) | ||
{ | ||
puts("usage: send <if_pid> <payload> [port]"); | ||
} | ||
|
||
int tx_cmd(int argc, char **argv) | ||
{ | ||
gnrc_pktsnip_t *pkt; | ||
uint8_t port = LORAWAN_PORT; /* Default: 2 */ | ||
int interface; | ||
|
||
if(argc < 3) { | ||
_usage(); | ||
return 1; | ||
} | ||
|
||
interface = atoi(argv[1]); | ||
/* handle optional parameters */ | ||
if (argc > 3) { | ||
port = atoi(argv[3]); | ||
if (port == 0 || port >= 224) { | ||
printf("error: invalid port given '%d', " | ||
"port can only be between 1 and 223\n", port); | ||
return 1; | ||
} | ||
} | ||
|
||
pkt = gnrc_pktbuf_add(NULL, argv[2], strlen(argv[2]), GNRC_NETTYPE_UNDEF); | ||
|
||
/* register for returned packet status */ | ||
if (gnrc_neterr_reg(pkt) != 0) { | ||
puts("Can not register for error reporting"); | ||
return 0; | ||
} | ||
|
||
gnrc_netapi_set(interface, NETOPT_LORAWAN_TX_PORT, 0, &port, sizeof(port)); | ||
gnrc_netapi_send(interface, pkt); | ||
|
||
msg_t msg; | ||
/* wait for packet status and check */ | ||
msg_receive(&msg); | ||
if ((msg.type != GNRC_NETERR_MSG_TYPE) || | ||
(msg.content.value != GNRC_NETERR_SUCCESS)) { | ||
puts("Error sending packet (not joined?)"); | ||
} | ||
else { | ||
puts("Successfully sent packet"); | ||
} | ||
return 0; | ||
} | ||
|
||
static const shell_command_t shell_commands[] = { | ||
{ "send", "Send LoRaWAN data", tx_cmd}, | ||
{ NULL, NULL, NULL } | ||
}; | ||
|
||
|
||
int main(void) | ||
{ | ||
/* start the shell */ | ||
puts("Initialization successful - starting the shell now"); | ||
gnrc_netreg_entry_t dump = GNRC_NETREG_ENTRY_INIT_PID(LORAWAN_PORT, | ||
gnrc_pktdump_pid); | ||
gnrc_netreg_register(GNRC_NETTYPE_LORAWAN, &dump); | ||
char line_buf[SHELL_DEFAULT_BUFSIZE]; | ||
|
||
shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE); | ||
|
||
return 0; | ||
} |
This file contains 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
Oops, something went wrong.