From e7368e194068ed0883bf279378a67043e441a7f7 Mon Sep 17 00:00:00 2001 From: Jordan Yates Date: Wed, 21 Apr 2021 22:31:53 +1000 Subject: [PATCH] samples: lorawan: class_a: downlink cb Add an example downlink callback to the LoRaWAN sample. Signed-off-by: Jordan Yates --- samples/subsys/lorawan/class_a/src/main.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/samples/subsys/lorawan/class_a/src/main.c b/samples/subsys/lorawan/class_a/src/main.c index f9f6700267c..03dee428335 100644 --- a/samples/subsys/lorawan/class_a/src/main.c +++ b/samples/subsys/lorawan/class_a/src/main.c @@ -32,6 +32,16 @@ LOG_MODULE_REGISTER(lorawan_class_a); char data[] = {'h', 'e', 'l', 'l', 'o', 'w', 'o', 'r', 'l', 'd'}; +static void dl_callback(uint8_t port, bool data_pending, + int16_t rssi, int8_t snr, + uint8_t len, const uint8_t *data) +{ + LOG_INF("Port %d, Pending %d, RSSI %ddB, SNR %ddBm", port, data_pending, rssi, snr); + if (data) { + LOG_HEXDUMP_INF(data, len, "Payload: "); + } +} + static void lorwan_datarate_changed(enum lorawan_datarate dr) { uint8_t unused, max_size; @@ -49,6 +59,11 @@ void main(void) uint8_t app_key[] = LORAWAN_APP_KEY; int ret; + struct lorawan_downlink_cb downlink_cb = { + .port = LW_RECV_PORT_ANY, + .cb = dl_callback + }; + lora_dev = device_get_binding(DEFAULT_RADIO); if (!lora_dev) { LOG_ERR("%s Device not found", DEFAULT_RADIO); @@ -61,6 +76,7 @@ void main(void) return; } + lorawan_register_downlink_callback(&downlink_cb); lorawan_register_dr_changed_callback(lorwan_datarate_changed); join_cfg.mode = LORAWAN_ACT_OTAA;