From bb8bdadd69b92b4916f88245ebb6d55d3284de94 Mon Sep 17 00:00:00 2001
From: Alexandre Abadie <alexandre.abadie@inria.fr>
Date: Wed, 30 Jan 2019 10:05:37 +0100
Subject: [PATCH] examples/lorawan: fix potential hang in example

---
 examples/lorawan/main.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/examples/lorawan/main.c b/examples/lorawan/main.c
index 97770294d0..da2e43212d 100644
--- a/examples/lorawan/main.c
+++ b/examples/lorawan/main.c
@@ -67,9 +67,15 @@ static void _prepare_next_alarm(void)
 static void _send_message(void)
 {
     printf("Sending: %s\n", message);
-    /* The send call blocks until done */
-    semtech_loramac_send(&loramac, (uint8_t *)message, strlen(message));
-    /* Wait until the send cycle has completed */
+    /* Try to send the message */
+    uint8_t ret = semtech_loramac_send(&loramac,
+                                       (uint8_t *)message, strlen(message));
+    if (ret != SEMTECH_LORAMAC_TX_OK) {
+        printf("Cannot send message '%s', ret code: %d\n", message, ret);
+        return;
+    }
+    /* The send was successfully scheduled, now wait until the send cycle has
+       completed and a reply is received from the MAC */
     semtech_loramac_recv(&loramac);
 }
 
-- 
GitLab