Bootcamp application example using LoRaWAN-lib MAC layer implementation. Provides an application example controlling a 3 color LED and a light sensor.

Dependencies:   mbed Chainable_RGB_LED DigitDisplay LoRaWAN-lib SX1272Lib

Fork of LoRaWAN-demo-72 by Semtech

For a detailed description of the LoRaWAN operations, please visit the MBED dedicated page at https://developer.mbed.org/teams/Semtech/code/LoRaWAN-demo-72/

Revision:
7:ceb4063e6863
Parent:
5:fa113b25f612
Child:
9:0083afd69815
diff -r 11b53eada5f3 -r ceb4063e6863 app/main.cpp
--- a/app/main.cpp	Wed May 18 11:33:45 2016 +0000
+++ b/app/main.cpp	Tue Jul 05 15:01:10 2016 +0000
@@ -21,10 +21,6 @@
 #include "SerialDisplay.h"
 #include "DigitDisplay.h"
 #include "ChainableLED.h"
-/*!
- * Join requests trials duty cycle.
- */
-#define OVER_THE_AIR_ACTIVATION_DUTYCYCLE           10000000 // 10 [s] value in us
 
 /*!
  * Defines the application data transmission duty cycle. 5s, value in [us].
@@ -97,13 +93,11 @@
 
 #endif
 
-#if( OVER_THE_AIR_ACTIVATION != 0 )
-
 static uint8_t DevEui[] = LORAWAN_DEVICE_EUI;
 static uint8_t AppEui[] = LORAWAN_APPLICATION_EUI;
 static uint8_t AppKey[] = LORAWAN_APPLICATION_KEY;
 
-#else
+#if( OVER_THE_AIR_ACTIVATION == 0 )
 
 static uint8_t NwkSKey[] = LORAWAN_NWKSKEY;
 static uint8_t AppSKey[] = LORAWAN_APPSKEY;
@@ -291,11 +285,10 @@
     SerialDisplayUpdateDevAddr( DevAddr );
     SerialDisplayUpdateKey( 12, NwkSKey );
     SerialDisplayUpdateKey( 13, AppSKey );
-#else
+#endif
     SerialDisplayUpdateEui( 5, DevEui );
     SerialDisplayUpdateEui( 6, AppEui );
     SerialDisplayUpdateKey( 7, AppKey );
-#endif
 
     mibReq.Type = MIB_NETWORK_JOINED;
     LoRaMacMibGetRequestConfirm( &mibReq );
@@ -542,6 +535,11 @@
         LoRaMacUplinkStatus.Datarate = mcpsConfirm->Datarate;
         LoRaMacUplinkStatus.UplinkCounter = mcpsConfirm->UpLinkCounter;
 
+        // Switch LED 1 ON
+        Led1State = true;
+        Led1StateChanged = true;
+        TimerStart( &Led1Timer );
+
         UplinkStatusUpdated = true;
     }
     NextTx = true;
@@ -720,6 +718,20 @@
                         LoRaMacMlmeRequest( &mlmeReq );
                     }
                     break;
+                case 6: // (ix)
+                    {
+                        MlmeReq_t mlmeReq;
+
+                        mlmeReq.Type = MLME_JOIN;
+
+                        mlmeReq.Req.Join.DevEui = DevEui;
+                        mlmeReq.Req.Join.AppEui = AppEui;
+                        mlmeReq.Req.Join.AppKey = AppKey;
+
+                        LoRaMacMlmeRequest( &mlmeReq );
+                        DeviceState = DEVICE_STATE_SLEEP;
+                    }
+                    break;
                 default:
                     break;
                 }
@@ -753,6 +765,8 @@
             {
                 // Status is OK, node has joined the network
                 IsNetworkJoinedStatusUpdate = true;
+                DeviceState = DEVICE_STATE_SEND;
+                NextTx = true;
                 break;
             }
             case MLME_LINK_CHECK:
@@ -790,6 +804,17 @@
     LightMode = 0;      // 0: manual,   1: automatic
     Buzzer = 0;         // 0: OFF,      1: ON
 
+    SerialDisplayUpdateEui( 5, DevEui );
+    SerialDisplayUpdateEui( 6, AppEui );
+    SerialDisplayUpdateKey( 7, AppKey );
+
+#if( OVER_THE_AIR_ACTIVATION == 0 )
+    SerialDisplayUpdateNwkId( LORAWAN_NETWORK_ID );
+    SerialDisplayUpdateDevAddr( DevAddr );
+    SerialDisplayUpdateKey( 12, NwkSKey );
+    SerialDisplayUpdateKey( 13, AppSKey );
+#endif
+
     DeviceState = DEVICE_STATE_INIT;
 
     while( 1 )
@@ -867,6 +892,10 @@
                 LoRaMacChannelAdd( 7, ( ChannelParams_t )LC8 );
                 LoRaMacChannelAdd( 8, ( ChannelParams_t )LC9 );
                 LoRaMacChannelAdd( 9, ( ChannelParams_t )LC10 );
+
+                mibReq.Type = MIB_RX2_CHANNEL;
+                mibReq.Param.Rx2Channel = ( Rx2ChannelParams_t ){ 869525000, DR_3 };
+                LoRaMacMibSetRequestConfirm( &mibReq );
 #endif
 
 #endif
@@ -894,15 +923,7 @@
                 {
                     LoRaMacMlmeRequest( &mlmeReq );
                 }
-
-                SerialDisplayUpdateEui( 5, DevEui );
-                SerialDisplayUpdateEui( 6, AppEui );
-                SerialDisplayUpdateKey( 7, AppKey );
-
-                // Schedule next packet transmission
-                TxDutyCycleTime = OVER_THE_AIR_ACTIVATION_DUTYCYCLE;
-                DeviceState = DEVICE_STATE_CYCLE;
-
+                DeviceState = DEVICE_STATE_SLEEP;
 #else
                 mibReq.Type = MIB_NET_ID;
                 mibReq.Param.NetID = LORAWAN_NETWORK_ID;
@@ -924,11 +945,6 @@
                 mibReq.Param.IsNetworkJoined = true;
                 LoRaMacMibSetRequestConfirm( &mibReq );
 
-                SerialDisplayUpdateNwkId( LORAWAN_NETWORK_ID );
-                SerialDisplayUpdateDevAddr( DevAddr );
-                SerialDisplayUpdateKey( 12, NwkSKey );
-                SerialDisplayUpdateKey( 13, AppSKey );
-
                 DeviceState = DEVICE_STATE_SEND;
 #endif
                 IsNetworkJoinedStatusUpdate = true;
@@ -943,11 +959,6 @@
                     PrepareTxFrame( AppPort );
 
                     NextTx = SendFrame( );
-
-                    // Switch LED 1 ON
-                    Led1State = true;
-                    Led1StateChanged = true;
-                    TimerStart( &Led1Timer );
                 }
                 if( ComplianceTest.Running == true )
                 {