Skip to content

Commit

Permalink
examples/lorawan: merge examples
Browse files Browse the repository at this point in the history
  • Loading branch information
aabadie committed Apr 12, 2019
1 parent f491be3 commit 72ef603
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 289 deletions.
64 changes: 64 additions & 0 deletions examples/lorawan/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# name of your application
APPLICATION = lorawan

# Use the ST B-L072Z-LRWAN1 board by default:
BOARD ?= b-l072z-lrwan1

# This has to be the absolute path to the RIOT base directory:
RIOTBASE ?= $(CURDIR)/../..

BOARD_INSUFFICIENT_MEMORY := nucleo-f031k6 nucleo-f042k6 nucleo-l031k6

# Change this to abp to enable Activation By Personnalization mode
ACTIVATION_MODE ?= otaa

ifeq (otaa,$(ACTIVATION_MODE))
DEVEUI ?= 0000000000000000
APPEUI ?= 0000000000000000
APPKEY ?= 00000000000000000000000000000000
else ifeq (abp,$(ACTIVATION_MODE))
DEVADDR ?= 00000000
NWKSKEY ?= 00000000000000000000000000000000
APPSKEY ?= 00000000000000000000000000000000
RX2_FREQ ?= 869525000
RX2_DR ?= 3
else
$(error Unsupported activation mode '$(ACTIVATION_MODE)')
endif

# Default radio driver is Semtech SX1276 (used by the B-L072Z-LRWAN1 board)
DRIVER ?= sx1276

# Default region is Europe and default band is 868MHz
REGION ?= EU868

# Include the Semtech-loramac package
USEPKG += semtech-loramac

USEMODULE += $(DRIVER)
USEMODULE += fmt
FEATURES_REQUIRED += periph_rtc

CFLAGS += -DREGION_$(REGION)
CFLAGS += -DLORAMAC_ACTIVE_REGION=LORAMAC_REGION_$(REGION)
ifeq (otaa,$(ACTIVATION_MODE))
CFLAGS += -DDEVEUI=\"$(DEVEUI)\" -DAPPEUI=\"$(APPEUI)\" -DAPPKEY=\"$(APPKEY)\"
CFLAGS += -DUSE_OTAA
else ifeq (abp,$(ACTIVATION_MODE))
CFLAGS += -DDEVADDR=\"$(DEVADDR)\" -DNWKSKEY=\"$(NWKSKEY)\" -DAPPSKEY=\"$(APPSKEY)\"
CFLAGS += -DRX2_FREQ=$(RX2_FREQ) -DRX2_DR=$(RX2_DR)
CFLAGS += -DUSE_ABP
# With ABP, just keep STOP power management mode locked. STANDBY is unlocked
# by default.
CFLAGS += '-DPM_BLOCKER_INITIAL={ .val_u32 = 0x01010100 }'
endif

# Comment this out to disable code in RIOT that does safety checking
# which is not needed in a production environment but helps in the
# development process:
DEVELHELP ?= 1

# Change this to 0 show compiler invocation lines by default:
QUIET ?= 1

include $(RIOTBASE)/Makefile.include
File renamed without changes.
41 changes: 37 additions & 4 deletions examples/lorawan_otaa/main.c → examples/lorawan/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,17 @@ semtech_loramac_t loramac;

static const char *message = "This is RIOT!";

#ifdef USE_OTAA
static uint8_t deveui[LORAMAC_DEVEUI_LEN];
static uint8_t appeui[LORAMAC_APPEUI_LEN];
static uint8_t appkey[LORAMAC_APPKEY_LEN];
#endif

#ifdef USE_ABP
static uint8_t devaddr[LORAMAC_DEVADDR_LEN];
static uint8_t nwkskey[LORAMAC_NWKSKEY_LEN];
static uint8_t appskey[LORAMAC_APPSKEY_LEN];
#endif

static void rtc_cb(void *arg)
{
Expand Down Expand Up @@ -123,13 +131,14 @@ int main(void)
puts("LoRaWAN Class A low-power application");
puts("=====================================");

/* Convert identifiers and application key */
/* Initialize the loramac stack */
semtech_loramac_init(&loramac);

#ifdef USE_OTAA /* OTAA activation mode */
/* Convert identifiers and keys strings to byte arrays */
fmt_hex_bytes(deveui, DEVEUI);
fmt_hex_bytes(appeui, APPEUI);
fmt_hex_bytes(appkey, APPKEY);

/* Initialize the loramac stack */
semtech_loramac_init(&loramac);
semtech_loramac_set_deveui(&loramac, deveui);
semtech_loramac_set_appeui(&loramac, appeui);
semtech_loramac_set_appkey(&loramac, appkey);
Expand All @@ -146,6 +155,30 @@ int main(void)
puts("Join procedure failed");
return 1;
}
#endif

#ifdef USE_ABP /* ABP activation mode */
/* Convert identifiers and keys strings to byte arrays */
fmt_hex_bytes(devaddr, DEVADDR);
fmt_hex_bytes(nwkskey, NWKSKEY);
fmt_hex_bytes(appskey, APPSKEY);
semtech_loramac_set_devaddr(&loramac, devaddr);
semtech_loramac_set_nwkskey(&loramac, nwkskey);
semtech_loramac_set_appskey(&loramac, appskey);

/* Configure RX2 parameters */
semtech_loramac_set_rx2_freq(&loramac, RX2_FREQ);
semtech_loramac_set_rx2_dr(&loramac, RX2_DR);

/* Store ABP parameters to EEPROM */
semtech_loramac_save_config(&loramac);

/* Use a fast datarate, e.g. BW125/SF7 in EU868 */
semtech_loramac_set_dr(&loramac, LORAMAC_DR_5);

/* ABP join procedure always succeeds */
semtech_loramac_join(&loramac, LORAMAC_JOIN_ABP);
#endif
puts("Join procedure succeeded");

/* start the sender thread */
Expand Down
48 changes: 0 additions & 48 deletions examples/lorawan_abp/Makefile

This file was deleted.

38 changes: 0 additions & 38 deletions examples/lorawan_abp/README.md

This file was deleted.

158 changes: 0 additions & 158 deletions examples/lorawan_abp/main.c

This file was deleted.

Loading

0 comments on commit 72ef603

Please sign in to comment.