Dependencies:   STM32F103c8t6-LoRaWAN-lmic SX1276Lib mbed-STM32F103C8T6 mbed

Fork of LoRaWAN-lmic-app by Semtech

Revision:
6:6fe6c547ba55
Parent:
5:1b2fcc2582e8
--- a/main.cpp	Thu Nov 26 17:20:53 2015 +0000
+++ b/main.cpp	Wed Apr 19 08:00:38 2017 +0000
@@ -12,6 +12,7 @@
 
 Maintainer: Miguel Luis and Gregory Cristian
 */
+#include "stm32f103c8t6.h"
 #include "mbed.h"
 
 #include "lmic.h"
@@ -21,7 +22,9 @@
  * When set to 1 the application uses the Over-the-Air activation procedure
  * When set to 0 the application uses the Personalization activation procedure
  */
-#define OVER_THE_AIR_ACTIVATION                     0
+ 
+#define SINGLE_CHANNEL_GATEWAY                      1
+#define OVER_THE_AIR_ACTIVATION                     1
 
 #if( OVER_THE_AIR_ACTIVATION == 0 )
 
@@ -33,26 +36,27 @@
 /*!
  * Defines the device address when using personalization activation procedure
  */
-#define LORAWAN_DEV_ADDR                            ( uint32_t )0x12345678
+#define LORAWAN_DEV_ADDR                            ( uint32_t )0x12345679
 
 #endif
 
 /*!
  * Defines the application data transmission duty cycle
  */
-#define APP_TX_DUTYCYCLE                            5000 // 5 [s] value in ms
-#define APP_TX_DUTYCYCLE_RND                        1000 // 1 [s] value in ms
+#define APP_TX_DUTYCYCLE                            60000 // 5 [s] value in ms 1min
+#define APP_TX_DUTYCYCLE_RND                        50000 // 1 [s] value in ms
 
 /*!
  * LoRaWAN Adaptative Data Rate
  */
 #define LORAWAN_ADR_ON                              1
+//#define LORAWAN_ADR_ON                              1
 
 /*!
  * LoRaWAN confirmed messages
  */
+//#define LORAWAN_CONFIRMED_MSG_ON                    1
 #define LORAWAN_CONFIRMED_MSG_ON                    1
-
 /*!
  * LoRaWAN application port
  */
@@ -73,38 +77,40 @@
 // CONFIGURATION (FOR APPLICATION CALLBACKS BELOW)
 //////////////////////////////////////////////////
 
+//fe dc ba 98 76 54 32 10
 // application router ID (LSBF)
 static const uint8_t AppEui[8] =
 {
-    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+   0xb8, 0x27, 0xeb, 0xff, 0xff, 0xef, 0x00, 0x62
 };
 
 // unique device ID (LSBF)
 static const u1_t DevEui[8] =
 {
-    0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
 };
 
 // device-specific AES key (derived from device EUI)
 static const uint8_t DevKey[16] = 
 {
-    0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6,
-    0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C
+    
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
 };
 
 #if( OVER_THE_AIR_ACTIVATION == 0 )
 // network session key
 static uint8_t NwkSKey[] = 
 { 
-    0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6,
-    0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
 };
 
 // application session key
 static uint8_t ArtSKey[] = 
 { 
-    0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6,
-    0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
 };
 
 #endif
@@ -113,9 +119,10 @@
 osjob_t rxLedJob;
 osjob_t txLedJob;
 osjob_t sendFrameJob;
+DigitalOut  myled(LED1);
 
 // LED state
-static bool AppLedStateOn = false;
+static bool AppLedStateOn = true;
 
 //////////////////////////////////////////////////
 // Utility functions
@@ -212,9 +219,16 @@
 {
     // reset MAC state
     LMIC_reset( );
-    LMIC_setAdrMode( LORAWAN_ADR_ON );
+    //LMIC_setAdrMode( LORAWAN_ADR_ON );
+    LMIC_setAdrMode(0);
+    LMIC_setLinkCheckMode(0);
+    LMIC_disableTracking ();
+    LMIC_stopPingable();
+   // LMIC_setDrTxpow(DR_SF7,14);
+    
 #if defined(CFG_eu868)
-    LMIC_setDrTxpow( DR_SF12, 14 );
+    //LMIC_setDrTxpow( DR_SF12, 14 );
+    LMIC_setDrTxpow(DR_SF12,14);
 #elif defined(CFG_us915)    
     LMIC_setDrTxpow( DR_SF10, 14 );
 #endif
@@ -231,8 +245,19 @@
 
 int main( void )
 {
+
+  #ifdef SINGLE_CHANNEL_GATEWAY
+   //MAX_CHANNELS = 1;
+   //MAX_BANDS = 1;
+   //LIMIT_CHANNELS = 1;
+  for (int i=1; i<16; i++)
+   LMIC_disableChannel(i);
+    #endif
+    //confSysClock();
+    //DigitalOut  myled(LED1);
+    myled = 0;      // turn the LED on
+    
     osjob_t initjob;
-
     // initialize runtime env
     os_init( );
     // setup initial job
@@ -277,13 +302,14 @@
     default:
         break;
     }
+    myled = 1;      // turn the LED off
     if( txOn == true )
     {
         //Sends frame every APP_TX_DUTYCYCLE +/- APP_TX_DUTYCYCLE_RND random time (if not duty cycle limited)
         os_setTimedCallback( &sendFrameJob,
-                             os_getTime( ) + ms2osticks( APP_TX_DUTYCYCLE + randr( -APP_TX_DUTYCYCLE_RND, APP_TX_DUTYCYCLE_RND ) ),
+                             os_getTime( ) + ms2osticks( ((APP_TX_DUTYCYCLE) + randr( 10000, 60000 ))*2 ),
                              onSendFrame );
-        
+        myled = !myled;      // turn the LED on
         ////Sends frame as soon as possible (duty cylce limitations)
         //onSendFrame( NULL );
     }