A demo application for HXC900 LoRaWAN module using Nucleo-L053R8.

Dependencies:   mbed

Revision:
25:50414f44a431
Parent:
24:f3b987589609
Child:
26:176e648c03f6
--- a/LoRa/lora_driver.c	Fri Oct 19 04:59:55 2018 +0000
+++ b/LoRa/lora_driver.c	Thu Nov 01 21:41:59 2018 +0000
@@ -57,7 +57,7 @@
 #define JOIN_STATUS_REQ_DELAY (7000U)  // milliseconds. Join req takes 6s.
 
 // Re Authenticate every REJOIN_TIME
-#define REJOIN_TIME           (1 * 60 * 60 * 1000) // 1 hour
+#define REJOIN_TIME           (1 * 60 * 60 * 1000U) // 1 hour
 
 /* Private global variables --------------------------------------------------*/
 static sLoraConfig_t *LoraConfigParam;
@@ -403,8 +403,9 @@
 			eAtStatus_t status = Lora_SendDataBinary(&SendDataBinary);
 			if (status == AT_OK)
 			{
+				DBG_PRINTF("Uplink sent\n");
 				// Schedule the next packet
-				TimerStart( &SensorMeasureTimer, LoraDriverParam->SensorMeasureTime );
+				TimerStart(&SensorMeasureTimer, LoraDriverParam->SensorMeasureTime);
 				DeviceState = SLEEP_DEVICE;
 			}
 			else if(status == AT_TIMEOUT)
@@ -412,6 +413,10 @@
 				// Device isn't responding. Go to init.
 				DeviceState = DEVICE_INIT;
 			}
+			else
+			{
+				DBG_PRINTF("Uplink Failed (Error: %d)\n", (uint8_t)status);
+			}
 
 		    break;
 		}
@@ -446,7 +451,7 @@
 	// Use a random delay to avoid synchronized join request from all LoRa node after power up
 	uint32_t joinDelay = (HAL_RNG_GetRandomNumber(&RngHandle) % JOIN_SEND_DELAY_MAX) + 1;
 	
-	TimerStart( &JoinRequestTimer, joinDelay);
+	TimerStart(&JoinRequestTimer, joinDelay);
 }
 
 /******************************************************************************
@@ -478,7 +483,7 @@
 ******************************************************************************/
 static void OnJoinStatusDelayTimerEvt(void)
 {
-	TimerStop( &JoinStatusDelayTimer );
+	TimerStop(&JoinStatusDelayTimer);
 	DeviceState = DEVICE_JOIN_STATUS_CHECK;
 }
 
@@ -489,7 +494,7 @@
 ******************************************************************************/
 static void OnSensorMeasureTimerEvt(void)
 {
-	TimerStop( &SensorMeasureTimer );
+	TimerStop(&SensorMeasureTimer);
     DeviceState = DEVICE_SEND;
 }