Skip to content

Commit 8e04757

Browse files
author
Hasnain Virk
committed
Updating app logic
If the stack is busy (could be because of automatic uplink and fpending bit being set etc), send() will return WOULD_BLOCK. We now enqueue a TX again after 3 seconds if WOULD_BLOCK happens. UPLINK_REQUIRED event in case of disabled automated uplinks, was not being handled. We handle it now and enqueue a transmission.
1 parent 71a769a commit 8e04757

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

main.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ int main (void)
145145
return 0;
146146
}
147147

148-
149148
/**
150149
* Sends a message to the Network Server
151150
*/
@@ -174,6 +173,13 @@ static void send_message()
174173
if (retcode < 0) {
175174
retcode == LORAWAN_STATUS_WOULD_BLOCK ? printf("send - WOULD BLOCK\r\n")
176175
: printf("\r\n send() - Error code %d \r\n", retcode);
176+
177+
if (retcode == LORAWAN_STATUS_WOULD_BLOCK) {
178+
//retry in 3 seconds
179+
if (MBED_CONF_LORA_DUTY_CYCLE_ON) {
180+
ev_queue.call_in(3000, send_message);
181+
}
182+
}
177183
return;
178184
}
179185

@@ -253,6 +259,12 @@ static void lora_event_handler(lorawan_event_t event)
253259
case JOIN_FAILURE:
254260
printf("\r\n OTAA Failed - Check Keys \r\n");
255261
break;
262+
case UPLINK_REQUIRED:
263+
printf("\r\n Uplink required by NS \r\n");
264+
if (MBED_CONF_LORA_DUTY_CYCLE_ON) {
265+
send_message();
266+
}
267+
break;
256268
default:
257269
MBED_ASSERT("Unknown Event");
258270
}

0 commit comments

Comments
 (0)