mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
examples/gnrc_lorawan: refactor
This commit is contained in:
parent
7343c1c503
commit
7cf5530cae
@ -1,24 +1,37 @@
|
|||||||
# name of your application
|
# name of your application
|
||||||
APPLICATION = gnrc_lorawan
|
APPLICATION = gnrc_lorawan
|
||||||
|
|
||||||
USEMODULE += shell
|
|
||||||
USEMODULE += shell_commands
|
|
||||||
USEMODULE += gnrc_netdev_default
|
|
||||||
USEMODULE += auto_init_gnrc_netif
|
|
||||||
USEMODULE += gnrc_lorawan
|
|
||||||
USEMODULE += gnrc_pktdump
|
|
||||||
USEMODULE += gnrc_neterr
|
|
||||||
|
|
||||||
BOARD ?= b-l072z-lrwan1
|
|
||||||
RIOTBASE ?= ../../
|
|
||||||
|
|
||||||
# Turn on developer helpers
|
# Turn on developer helpers
|
||||||
DEVELHELP ?= 1
|
DEVELHELP ?= 1
|
||||||
|
|
||||||
# use SX1276 by default
|
BOARD ?= b-l072z-lrwan1
|
||||||
DRIVER ?= sx1276
|
RIOTBASE ?= ../../
|
||||||
|
|
||||||
USEMODULE += $(DRIVER)
|
# Include board's default network devices and auto-initialization of GNRC
|
||||||
|
# interfaces
|
||||||
|
USEMODULE += gnrc_netdev_default
|
||||||
|
USEMODULE += auto_init_gnrc_netif
|
||||||
|
|
||||||
|
# Add support for GNRC LoRaWAN
|
||||||
|
USEMODULE += gnrc_lorawan
|
||||||
|
|
||||||
|
# Use GNRC pktdump to print downlink messages
|
||||||
|
USEMODULE += gnrc_pktdump
|
||||||
|
|
||||||
|
# Include the shell and shell commands.
|
||||||
|
USEMODULE += shell
|
||||||
|
USEMODULE += shell_commands
|
||||||
|
|
||||||
|
# Use GNRC Txtsnd to transmit LoRaWAN from the shell
|
||||||
|
USEMODULE += gnrc_txtsnd
|
||||||
|
|
||||||
|
# Uncomment as needed if a board doesn't include a LoRa radio by default
|
||||||
|
# USEMODULE += sx1272
|
||||||
|
# USEMODULE += sx1276
|
||||||
|
|
||||||
|
# As there is an 'app.config' we want to explicitly disable Kconfig by setting
|
||||||
|
# the variable to empty
|
||||||
|
SHOULD_RUN_KCONFIG ?=
|
||||||
|
|
||||||
include $(RIOTBASE)/Makefile.include
|
include $(RIOTBASE)/Makefile.include
|
||||||
|
|
||||||
@ -33,6 +46,14 @@ include $(RIOTBASE)/Makefile.include
|
|||||||
# Check if being configured via Kconfig
|
# Check if being configured via Kconfig
|
||||||
ifndef CONFIG_KCONFIG_USEMODULE_LORAWAN
|
ifndef CONFIG_KCONFIG_USEMODULE_LORAWAN
|
||||||
|
|
||||||
|
# Tell GNRC to encode LoRaWAN port in the GNRC netif header.
|
||||||
|
# This allows us to use `gnrc_txtsnd` to send data from the shell using the
|
||||||
|
# `txtsnd` command.
|
||||||
|
#
|
||||||
|
# Note: From Release 22.01 all GNRC LoRaWAN packets will include the netif
|
||||||
|
# header. Therefore this flag will be removed after that
|
||||||
|
CFLAGS += -DCONFIG_GNRC_NETIF_LORAWAN_NETIF_HDR
|
||||||
|
|
||||||
CFLAGS += -DCONFIG_LORAMAC_APP_KEY_DEFAULT=\"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"
|
CFLAGS += -DCONFIG_LORAMAC_APP_KEY_DEFAULT=\"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"
|
||||||
CFLAGS += -DCONFIG_LORAMAC_APP_EUI_DEFAULT=\"BBBBBBBBBBBBBBBB\"
|
CFLAGS += -DCONFIG_LORAMAC_APP_EUI_DEFAULT=\"BBBBBBBBBBBBBBBB\"
|
||||||
CFLAGS += -DCONFIG_LORAMAC_DEV_EUI_DEFAULT=\"CCCCCCCCCCCCCCCC\"
|
CFLAGS += -DCONFIG_LORAMAC_DEV_EUI_DEFAULT=\"CCCCCCCCCCCCCCCC\"
|
||||||
|
@ -15,7 +15,6 @@ Usage
|
|||||||
|
|
||||||
It's necessary to join the LoRaWAN network either via OTAA or ABP.
|
It's necessary to join the LoRaWAN network either via OTAA or ABP.
|
||||||
All keys, addresses and EUIs are in network endian (big endian).
|
All keys, addresses and EUIs are in network endian (big endian).
|
||||||
The application listens to downlinks on Port 2 by default.
|
|
||||||
Region need to be set in the Makefile.
|
Region need to be set in the Makefile.
|
||||||
|
|
||||||
## OTAA
|
## OTAA
|
||||||
@ -73,10 +72,15 @@ CFLAGS += -DCONFIG_LORAMAC_DEV_ADDR_DEFAULT=\"FFFFFFFF\"
|
|||||||
|
|
||||||
## Send data
|
## Send data
|
||||||
|
|
||||||
After join, send data using `send` command. E.g to send "Hello RIOT!" to port 2:
|
After join, send data using `txtsnd` command:
|
||||||
|
```
|
||||||
|
txtsnd <if> <hex_port> <data>
|
||||||
|
```
|
||||||
|
|
||||||
|
E.g to send "Hello RIOT!" to LoRaWAN port 123 (hex 0x7B) via interface 3:
|
||||||
|
|
||||||
```
|
```
|
||||||
send 3 "Hello RIOT!" 2
|
txtsnd 3 7B "Hello RIOT!"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Changing datarate of transmission
|
## Changing datarate of transmission
|
||||||
@ -100,7 +104,7 @@ Send some data. The result of the Link Check request can be seen with
|
|||||||
|
|
||||||
```
|
```
|
||||||
ifconfig 3 link_check
|
ifconfig 3 link_check
|
||||||
send 3 "Join the RIOT!"
|
txtsnd 3 01 "Join the RIOT!"
|
||||||
```
|
```
|
||||||
|
|
||||||
Check demodulation margin and number of gateways using `ifconfig`
|
Check demodulation margin and number of gateways using `ifconfig`
|
||||||
@ -124,18 +128,43 @@ E.g send confirmable messages:
|
|||||||
|
|
||||||
```
|
```
|
||||||
ifconfig 3 ack_req
|
ifconfig 3 ack_req
|
||||||
send 3 "My confirmable message"
|
txtsnd 3 01 "My confirmable message"
|
||||||
```
|
```
|
||||||
|
|
||||||
And unconfirmable messages:
|
And unconfirmable messages:
|
||||||
|
|
||||||
```
|
```
|
||||||
ifconfig 3 -ack_req
|
ifconfig 3 -ack_req
|
||||||
send 3 "My unconfirmable message"
|
txtsnd 3 01 "My unconfirmable message"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Receiving data
|
||||||
|
|
||||||
|
Schedule a downlink for the LoRaWAN node in the Application Server. If using
|
||||||
|
TTN, this can be done under `Applications > <APP> > Devices > <DEV> > Overview`
|
||||||
|
and then check the `Downlink` section.
|
||||||
|
|
||||||
|
After sending data, the LoRaWAN Network Server will reply with the downlink
|
||||||
|
data. For simplicity, this application is configured to dump downlink data to
|
||||||
|
[GNRC pktdump](https://doc.riot-os.org/pktdump_8h.html).
|
||||||
|
|
||||||
|
E.g:
|
||||||
|
```
|
||||||
|
PKTDUMP: data received:
|
||||||
|
~~ SNIP 0 - size: 2 byte, type: NETTYPE_UNDEF (0)
|
||||||
|
00000000 AA AA
|
||||||
|
~~ SNIP 1 - size: 9 byte, type: NETTYPE_NETIF (-1)
|
||||||
|
if_pid: 3 rssi: -32768 lqi: 0
|
||||||
|
flags: 0x0
|
||||||
|
src_l2addr: (nil)
|
||||||
|
dst_l2addr: 01
|
||||||
|
~~ PKT - 2 snips, total size: 11 byte
|
||||||
|
```
|
||||||
|
|
||||||
|
This downlink was sent to port 1 (check `dst_l2addr` field)
|
||||||
|
|
||||||
Current state and future plans
|
Current state and future plans
|
||||||
============
|
==============================
|
||||||
|
|
||||||
The current GNRC LoRaWAN stack is still in an experimental state. It's still
|
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
|
not compliant with the LoRaWAN specification because some features like duty
|
||||||
|
2
examples/gnrc_lorawan/app.config
Normal file
2
examples/gnrc_lorawan/app.config
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
CONFIG_KCONFIG_USEMODULE_GNRC_NETIF=y
|
||||||
|
CONFIG_GNRC_NETIF_LORAWAN_NETIF_HDR=y
|
@ -32,81 +32,23 @@
|
|||||||
#include "net/gnrc/netif.h"
|
#include "net/gnrc/netif.h"
|
||||||
|
|
||||||
#include "net/gnrc/pktbuf.h"
|
#include "net/gnrc/pktbuf.h"
|
||||||
#include "net/gnrc/pktdump.h"
|
|
||||||
#include "net/gnrc/netreg.h"
|
#include "net/gnrc/netreg.h"
|
||||||
|
#include "net/gnrc/pktdump.h"
|
||||||
#include "net/loramac.h"
|
#include "net/loramac.h"
|
||||||
|
|
||||||
#define LORAWAN_QUEUE_SIZE (4U)
|
|
||||||
|
|
||||||
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 = CONFIG_LORAMAC_DEFAULT_TX_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_netif_send(gnrc_netif_get_by_pid(interface), pkt);
|
|
||||||
|
|
||||||
/* wait for packet status and check */
|
|
||||||
msg_t msg;
|
|
||||||
msg_receive(&msg);
|
|
||||||
if ((msg.type != GNRC_NETERR_MSG_TYPE) ||
|
|
||||||
(msg.content.value != GNRC_NETERR_SUCCESS)) {
|
|
||||||
printf("Error sending packet: (status: %d\n)", (int) msg.content.value);
|
|
||||||
}
|
|
||||||
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)
|
int main(void)
|
||||||
{
|
{
|
||||||
/* start the shell */
|
/* start the shell */
|
||||||
puts("Initialization successful - starting the shell now");
|
puts("Initialization successful - starting the shell now");
|
||||||
gnrc_netreg_entry_t dump = GNRC_NETREG_ENTRY_INIT_PID(CONFIG_LORAMAC_DEFAULT_TX_PORT,
|
|
||||||
|
/* Receive LoRaWAN packets in GNRC pktdump */
|
||||||
|
gnrc_netreg_entry_t dump = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL,
|
||||||
gnrc_pktdump_pid);
|
gnrc_pktdump_pid);
|
||||||
|
|
||||||
gnrc_netreg_register(GNRC_NETTYPE_LORAWAN, &dump);
|
gnrc_netreg_register(GNRC_NETTYPE_UNDEF, &dump);
|
||||||
char line_buf[SHELL_DEFAULT_BUFSIZE];
|
|
||||||
|
|
||||||
shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
|
char line_buf[SHELL_DEFAULT_BUFSIZE];
|
||||||
|
shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user