Skip to content

Commit

Permalink
examples/lorawan: rename to lorawan_otaa + add pm
Browse files Browse the repository at this point in the history
  • Loading branch information
aabadie committed Mar 22, 2019
1 parent 4dc0626 commit f33ebe6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
LoRaWAN
=======
LoRaWAN - OTAA
==============

Description
-----------
Expand All @@ -9,7 +9,7 @@ This application shows a simple use case of LoRaWAN with RIOT.
By using the real time clock and low-power capabilities of a board, this
application shows how to program a LoRaWAN Class A device using RIOT.

This application is using the Over-The-Air Activation procedure.
This application is using the Over-The-Air Activation (OTAA) procedure.

Usage
-----
Expand Down
17 changes: 17 additions & 0 deletions examples/lorawan/main.c → examples/lorawan_otaa/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
#include "msg.h"
#include "thread.h"
#include "fmt.h"
#ifdef MODULE_PM_LAYERED
#include "pm_layered.h"
#endif

#include "periph/rtc.h"

Expand All @@ -35,6 +38,9 @@
/* Messages are sent every 20s to respect the duty cycle on each channel */
#define PERIOD (20U)

/* Low-power mode level */
#define PM_LOCK_LEVEL (1)

#define SENDER_PRIO (THREAD_PRIORITY_MAIN - 1)
static kernel_pid_t sender_pid;
static char sender_stack[THREAD_STACKSIZE_MAIN / 2];
Expand All @@ -50,6 +56,12 @@ static uint8_t appkey[LORAMAC_APPKEY_LEN];
static void rtc_cb(void *arg)
{
(void) arg;

#ifdef MODULE_PM_LAYERED
/* block sleep level mode until the next sending cycle has completed */
pm_block(PM_LOCK_LEVEL);
#endif

msg_t msg;
msg_send(&msg, sender_pid);
}
Expand Down Expand Up @@ -95,6 +107,11 @@ static void *sender(void *arg)

/* Schedule the next wake-up alarm */
_prepare_next_alarm();

#ifdef MODULE_PM_LAYERED
/* go back to sleep */
pm_unblock(PM_LOCK_LEVEL);
#endif
}

/* this should never be reached */
Expand Down

0 comments on commit f33ebe6

Please sign in to comment.