Sending IKS01A1 temperature sensor to LoRaWAN port-5 uplink

Dependencies:   X_NUCLEO_IKS01A1 mbed LoRaWAN-lib SX1276Lib

Fork of LoRaWAN-demo-76 by Semtech

Use IKS01A1 sensor shield with SX1272 shield or SX1276 shield.

Sends temperature sensor to LoRaWAN uplink port 5.


Remove SB22 and SB23 from IKS01A1 before using

SB28 conflicts with DIO0 on radio. (TxDone RxDone)

SB22 conflicts with RxTx on radio. (antenna switch)

Files at this revision

API Documentation at this revision

Comitter:
mluis
Date:
Fri May 13 15:15:13 2016 +0000
Parent:
4:00cf2370c99d
Child:
6:a48936885eac
Commit message:
Updated mbed, LoRaWAN-lib and SX1276Lib libraries.

Changed in this revision

app/Comissioning.h Show annotated file Show diff for this revision Revisions of this file
app/main.cpp Show annotated file Show diff for this revision Revisions of this file
mac/LoRaWAN-lib.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
radio/SX1276Lib.lib Show annotated file Show diff for this revision Revisions of this file
system/crypto/aes.cpp Show annotated file Show diff for this revision Revisions of this file
system/crypto/cmac.cpp Show annotated file Show diff for this revision Revisions of this file
system/timer.cpp Show annotated file Show diff for this revision Revisions of this file
system/timer.h Show annotated file Show diff for this revision Revisions of this file
--- a/app/Comissioning.h	Mon Mar 14 09:20:40 2016 +0000
+++ b/app/Comissioning.h	Fri May 13 15:15:13 2016 +0000
@@ -29,9 +29,14 @@
 #if( OVER_THE_AIR_ACTIVATION != 0 )
 
 /*!
+ * IEEE Organizationally Unique Identifier ( OUI ) (big endian)
+ */
+#define IEEE_OUI                                    0x11, 0x22, 0x33
+
+/*!
  * Mote device IEEE EUI (big endian)
  */
-#define LORAWAN_DEVICE_EUI                          { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88 }
+#define LORAWAN_DEVICE_EUI                          { IEEE_OUI, 0x44, 0x55, 0x66, 0x77, 0x88 }
 
 /*!
  * Application IEEE EUI (big endian)
--- a/app/main.cpp	Mon Mar 14 09:20:40 2016 +0000
+++ b/app/main.cpp	Fri May 13 15:15:13 2016 +0000
@@ -23,7 +23,7 @@
 /*!
  * Join requests trials duty cycle.
  */
-#define OVER_THE_AIR_ACTIVATION_DUTYCYCLE           10000000  // 10 [s] value in us
+#define OVER_THE_AIR_ACTIVATION_DUTYCYCLE           10000000 // 10 [s] value in us
 
 /*!
  * Defines the application data transmission duty cycle. 5s, value in [us].
@@ -37,7 +37,7 @@
 #define APP_TX_DUTYCYCLE_RND                        1000000
 
 /*!
- * Default mote datarate
+ * Default datarate
  */
 #define LORAWAN_DEFAULT_DATARATE                    DR_0
 
@@ -64,6 +64,20 @@
  */
 #define LORAWAN_DUTYCYCLE_ON                        true
 
+#define USE_SEMTECH_DEFAULT_CHANNEL_LINEUP          1
+
+#if( USE_SEMTECH_DEFAULT_CHANNEL_LINEUP == 1 ) 
+
+#define LC4                { 867100000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 }
+#define LC5                { 867300000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 }
+#define LC6                { 867500000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 }
+#define LC7                { 867700000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 }
+#define LC8                { 867900000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 }
+#define LC9                { 868800000, { ( ( DR_7 << 4 ) | DR_7 ) }, 2 }
+#define LC10               { 868300000, { ( ( DR_6 << 4 ) | DR_6 ) }, 1 }
+
+#endif
+
 #endif
 
 /*!
@@ -342,7 +356,7 @@
         mcpsReq.Req.Unconfirmed.fBuffer = NULL;
         mcpsReq.Req.Unconfirmed.fBufferSize = 0;
         mcpsReq.Req.Unconfirmed.Datarate = LORAWAN_DEFAULT_DATARATE;
-        
+
         LoRaMacUplinkStatus.Acked = false;
         LoRaMacUplinkStatus.Port = 0;
         LoRaMacUplinkStatus.Buffer = NULL;
@@ -435,14 +449,14 @@
 /*!
  * \brief   MCPS-Confirm event function
  *
- * \param   [IN] McpsConfirm - Pointer to the confirm structure,
+ * \param   [IN] mcpsConfirm - Pointer to the confirm structure,
  *               containing confirm attributes.
  */
-static void McpsConfirm( McpsConfirm_t *McpsConfirm )
+static void McpsConfirm( McpsConfirm_t *mcpsConfirm )
 {
-    if( McpsConfirm->Status == LORAMAC_EVENT_INFO_STATUS_OK )
+    if( mcpsConfirm->Status == LORAMAC_EVENT_INFO_STATUS_OK )
     {
-        switch( McpsConfirm->McpsRequest )
+        switch( mcpsConfirm->McpsRequest )
         {
             case MCPS_UNCONFIRMED:
             {
@@ -455,8 +469,8 @@
                 // Check Datarate
                 // Check TxPower
                 // Check AckReceived
-                // Check NbRetries
-                LoRaMacUplinkStatus.Acked = McpsConfirm->AckReceived;
+                // Check NbTrials
+                LoRaMacUplinkStatus.Acked = mcpsConfirm->AckReceived;
                 break;
             }
             case MCPS_PROPRIETARY:
@@ -466,9 +480,9 @@
             default:
                 break;
         }
-        LoRaMacUplinkStatus.Datarate = McpsConfirm->Datarate;
-        LoRaMacUplinkStatus.UplinkCounter = McpsConfirm->UpLinkCounter;
-    
+        LoRaMacUplinkStatus.Datarate = mcpsConfirm->Datarate;
+        LoRaMacUplinkStatus.UplinkCounter = mcpsConfirm->UpLinkCounter;
+
         UplinkStatusUpdated = true;
     }
     NextTx = true;
@@ -477,17 +491,17 @@
 /*!
  * \brief   MCPS-Indication event function
  *
- * \param   [IN] McpsIndication - Pointer to the indication structure,
+ * \param   [IN] mcpsIndication - Pointer to the indication structure,
  *               containing indication attributes.
  */
-static void McpsIndication( McpsIndication_t *McpsIndication )
+static void McpsIndication( McpsIndication_t *mcpsIndication )
 {
-    if( McpsIndication->Status != LORAMAC_EVENT_INFO_STATUS_OK )
+    if( mcpsIndication->Status != LORAMAC_EVENT_INFO_STATUS_OK )
     {
         return;
     }
 
-    switch( McpsIndication->McpsIndication )
+    switch( mcpsIndication->McpsIndication )
     {
         case MCPS_UNCONFIRMED:
         {
@@ -518,38 +532,38 @@
     // Check Rssi
     // Check Snr
     // Check RxSlot
-    LoRaMacDownlinkStatus.Rssi = McpsIndication->Rssi;
-    if( McpsIndication->Snr & 0x80 ) // The SNR sign bit is 1
+    LoRaMacDownlinkStatus.Rssi = mcpsIndication->Rssi;
+    if( mcpsIndication->Snr & 0x80 ) // The SNR sign bit is 1
     {
         // Invert and divide by 4
-        LoRaMacDownlinkStatus.Snr = ( ( ~McpsIndication->Snr + 1 ) & 0xFF ) >> 2;
+        LoRaMacDownlinkStatus.Snr = ( ( ~mcpsIndication->Snr + 1 ) & 0xFF ) >> 2;
         LoRaMacDownlinkStatus.Snr = -LoRaMacDownlinkStatus.Snr;
     }
     else
     {
         // Divide by 4
-        LoRaMacDownlinkStatus.Snr = ( McpsIndication->Snr & 0xFF ) >> 2;
+        LoRaMacDownlinkStatus.Snr = ( mcpsIndication->Snr & 0xFF ) >> 2;
     }
     LoRaMacDownlinkStatus.DownlinkCounter++;
-    LoRaMacDownlinkStatus.RxData = McpsIndication->RxData;
-    LoRaMacDownlinkStatus.Port = McpsIndication->Port;
-    LoRaMacDownlinkStatus.Buffer = McpsIndication->Buffer;
-    LoRaMacDownlinkStatus.BufferSize = McpsIndication->BufferSize;
+    LoRaMacDownlinkStatus.RxData = mcpsIndication->RxData;
+    LoRaMacDownlinkStatus.Port = mcpsIndication->Port;
+    LoRaMacDownlinkStatus.Buffer = mcpsIndication->Buffer;
+    LoRaMacDownlinkStatus.BufferSize = mcpsIndication->BufferSize;
 
     if( ComplianceTest.Running == true )
     {
         ComplianceTest.DownLinkCounter++;
     }
 
-    if( McpsIndication->RxData == true )
+    if( mcpsIndication->RxData == true )
     {
-        switch( McpsIndication->Port )
+        switch( mcpsIndication->Port )
         {
         case 1: // The application LED can be controlled on port 1 or 2
         case 2:
-            if( McpsIndication->BufferSize == 1 )
+            if( mcpsIndication->BufferSize == 1 )
             {
-                AppLedStateOn = McpsIndication->Buffer[0] & 0x01;
+                AppLedStateOn = mcpsIndication->Buffer[0] & 0x01;
                 Led3StateChanged = true;
             }
             break;
@@ -557,11 +571,11 @@
             if( ComplianceTest.Running == false )
             {
                 // Check compliance test enable command (i)
-                if( ( McpsIndication->BufferSize == 4 ) && 
-                    ( McpsIndication->Buffer[0] == 0x01 ) &&
-                    ( McpsIndication->Buffer[1] == 0x01 ) &&
-                    ( McpsIndication->Buffer[2] == 0x01 ) &&
-                    ( McpsIndication->Buffer[3] == 0x01 ) )
+                if( ( mcpsIndication->BufferSize == 4 ) &&
+                    ( mcpsIndication->Buffer[0] == 0x01 ) &&
+                    ( mcpsIndication->Buffer[1] == 0x01 ) &&
+                    ( mcpsIndication->Buffer[2] == 0x01 ) &&
+                    ( mcpsIndication->Buffer[3] == 0x01 ) )
                 {
                     IsTxConfirmed = false;
                     AppPort = 224;
@@ -585,7 +599,7 @@
             }
             else
             {
-                ComplianceTest.State = McpsIndication->Buffer[0];
+                ComplianceTest.State = mcpsIndication->Buffer[0];
                 switch( ComplianceTest.State )
                 {
                 case 0: // Check compliance test disable command (ii)
@@ -615,12 +629,12 @@
                     ComplianceTest.State = 1;
                     break;
                 case 4: // (vii)
-                    AppDataSize = McpsIndication->BufferSize;
+                    AppDataSize = mcpsIndication->BufferSize;
 
                     AppData[0] = 4;
                     for( uint8_t i = 1; i < AppDataSize; i++ )
                     {
-                        AppData[i] = McpsIndication->Buffer[i] + 1;
+                        AppData[i] = mcpsIndication->Buffer[i] + 1;
                     }
                     break;
                 case 5: // (viii)
@@ -650,14 +664,14 @@
 /*!
  * \brief   MLME-Confirm event function
  *
- * \param   [IN] MlmeConfirm - Pointer to the confirm structure,
+ * \param   [IN] mlmeConfirm - Pointer to the confirm structure,
  *               containing confirm attributes.
  */
-static void MlmeConfirm( MlmeConfirm_t *MlmeConfirm )
+static void MlmeConfirm( MlmeConfirm_t *mlmeConfirm )
 {
-    if( MlmeConfirm->Status == LORAMAC_EVENT_INFO_STATUS_OK )
+    if( mlmeConfirm->Status == LORAMAC_EVENT_INFO_STATUS_OK )
     {
-        switch( MlmeConfirm->MlmeRequest )
+        switch( mlmeConfirm->MlmeRequest )
         {
             case MLME_JOIN:
             {
@@ -672,8 +686,8 @@
                 if( ComplianceTest.Running == true )
                 {
                     ComplianceTest.LinkCheck = true;
-                    ComplianceTest.DemodMargin = MlmeConfirm->DemodMargin;
-                    ComplianceTest.NbGateways = MlmeConfirm->NbGateways;
+                    ComplianceTest.DemodMargin = mlmeConfirm->DemodMargin;
+                    ComplianceTest.NbGateways = mlmeConfirm->NbGateways;
                 }
                 break;
             }
@@ -765,6 +779,17 @@
 #if defined( USE_BAND_868 )
                 LoRaMacTestSetDutyCycleOn( LORAWAN_DUTYCYCLE_ON );
                 SerialDisplayUpdateDutyCycle( LORAWAN_DUTYCYCLE_ON );
+
+#if( USE_SEMTECH_DEFAULT_CHANNEL_LINEUP == 1 ) 
+                LoRaMacChannelAdd( 3, ( ChannelParams_t )LC4 );
+                LoRaMacChannelAdd( 4, ( ChannelParams_t )LC5 );
+                LoRaMacChannelAdd( 5, ( ChannelParams_t )LC6 );
+                LoRaMacChannelAdd( 6, ( ChannelParams_t )LC7 );
+                LoRaMacChannelAdd( 7, ( ChannelParams_t )LC8 );
+                LoRaMacChannelAdd( 8, ( ChannelParams_t )LC9 );
+                LoRaMacChannelAdd( 9, ( ChannelParams_t )LC10 );
+#endif
+
 #endif
                 SerialDisplayUpdateActivationMode( OVER_THE_AIR_ACTIVATION );
                 SerialDisplayUpdateAdr( LORAWAN_ADR_ON );
@@ -847,8 +872,8 @@
                 }
                 if( ComplianceTest.Running == true )
                 {
-                    // Schedule next packet transmission as soon as possible
-                    TxDutyCycleTime = 1000; // 1 ms
+                    // Schedule next packet transmission
+                    TxDutyCycleTime = 5000000; // 5000000 us
                 }
                 else
                 {
@@ -860,11 +885,11 @@
             }
             case DEVICE_STATE_CYCLE:
             {
+                DeviceState = DEVICE_STATE_SLEEP;
+
                 // Schedule next packet transmission
                 TimerSetValue( &TxNextPacketTimer, TxDutyCycleTime );
                 TimerStart( &TxNextPacketTimer );
-
-                DeviceState = DEVICE_STATE_SLEEP;
                 break;
             }
             case DEVICE_STATE_SLEEP:
--- a/mac/LoRaWAN-lib.lib	Mon Mar 14 09:20:40 2016 +0000
+++ b/mac/LoRaWAN-lib.lib	Fri May 13 15:15:13 2016 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/teams/Semtech/code/LoRaWAN-lib/#b9d87593a8ae
+http://developer.mbed.org/teams/Semtech/code/LoRaWAN-lib/#37c12dbc8dc7
--- a/mbed.bld	Mon Mar 14 09:20:40 2016 +0000
+++ b/mbed.bld	Fri May 13 15:15:13 2016 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/4336505e4b1c
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/7c328cabac7e
\ No newline at end of file
--- a/radio/SX1276Lib.lib	Mon Mar 14 09:20:40 2016 +0000
+++ b/radio/SX1276Lib.lib	Fri May 13 15:15:13 2016 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/teams/Semtech/code/SX1276Lib/#1e143575df0f
+http://developer.mbed.org/teams/Semtech/code/SX1276Lib/#3778e6204cc1
--- a/system/crypto/aes.cpp	Mon Mar 14 09:20:40 2016 +0000
+++ b/system/crypto/aes.cpp	Fri May 13 15:15:13 2016 +0000
@@ -46,7 +46,7 @@
 #include <stdint.h>
 
 /* define if you have fast 32-bit types on your system */
-#if 1
+#if ( __CORTEX_M != 0 ) // if Cortex is different from M0/M0+
 #  define HAVE_UINT_32T
 #endif
 
@@ -239,7 +239,7 @@
 static uint8_t gf_inv(const uint8_t x)
 {   uint8_t p1 = x, p2 = BPOLY, n1 = hibit(x), n2 = 0x80, v1 = 1, v2 = 0;
 
-    if(x < 2) 
+    if(x < 2)
         return x;
 
     for( ; ; )
@@ -247,20 +247,20 @@
         if(n1)
             while(n2 >= n1)             /* divide polynomial p2 by p1    */
             {
-                n2 /= n1;               /* shift smaller polynomial left */ 
+                n2 /= n1;               /* shift smaller polynomial left */
                 p2 ^= (p1 * n2) & 0xff; /* and remove from larger one    */
-                v2 ^= (v1 * n2);        /* shift accumulated value and   */ 
+                v2 ^= (v1 * n2);        /* shift accumulated value and   */
                 n2 = hibit(p2);         /* add into result               */
             }
         else
             return v1;
 
-        if(n2)                          /* repeat with values swapped    */ 
+        if(n2)                          /* repeat with values swapped    */
             while(n1 >= n2)
             {
-                n1 /= n2; 
-                p1 ^= p2 * n1; 
-                v1 ^= v2 * n1; 
+                n1 /= n2;
+                p1 ^= p2 * n1;
+                v1 ^= v2 * n1;
                 n1 = hibit(p1);
             }
         else
@@ -270,13 +270,13 @@
 
 /* The forward and inverse affine transformations used in the S-box */
 uint8_t fwd_affine(const uint8_t x)
-{   
+{
 #if defined( HAVE_UINT_32T )
     uint32_t w = x;
     w ^= (w << 1) ^ (w << 2) ^ (w << 3) ^ (w << 4);
     return 0x63 ^ ((w ^ (w >> 8)) & 0xff);
 #else
-    return 0x63 ^ x ^ (x << 1) ^ (x << 2) ^ (x << 3) ^ (x << 4) 
+    return 0x63 ^ x ^ (x << 1) ^ (x << 2) ^ (x << 3) ^ (x << 4)
                     ^ (x >> 7) ^ (x >> 6) ^ (x >> 5) ^ (x >> 4);
 #endif
 }
@@ -288,7 +288,7 @@
     w = (w << 1) ^ (w << 3) ^ (w << 6);
     return 0x05 ^ ((w ^ (w >> 8)) & 0xff);
 #else
-    return 0x05 ^ (x << 1) ^ (x << 3) ^ (x << 6) 
+    return 0x05 ^ (x << 1) ^ (x << 3) ^ (x << 6)
                 ^ (x >> 7) ^ (x >> 5) ^ (x >> 2);
 #endif
 }
@@ -520,8 +520,8 @@
     case 24:
     case 32:
         break;
-    default: 
-        ctx->rnd = 0; 
+    default:
+        ctx->rnd = 0;
         return ( uint8_t )-1;
     }
     block_copy_nn(ctx->ksch, key, keylen);
@@ -648,10 +648,10 @@
 
 return_type aes_cbc_decrypt( const uint8_t *in, uint8_t *out,
                          int32_t n_block, uint8_t iv[N_BLOCK], const aes_context ctx[1] )
-{   
+{
     while(n_block--)
     {   uint8_t tmp[N_BLOCK];
-        
+
         //memcpy(tmp, in, N_BLOCK);
         block_copy(tmp, in);
         if(aes_decrypt(in, out, ctx) != EXIT_SUCCESS)
--- a/system/crypto/cmac.cpp	Mon Mar 14 09:20:40 2016 +0000
+++ b/system/crypto/cmac.cpp	Fri May 13 15:15:13 2016 +0000
@@ -86,7 +86,7 @@
                     len -= mlen;
             }
             while (len > 16) {      /* not last block */
-         
+
                     XOR(data, ctx->X);
                     //rijndael_encrypt(&ctx->rijndael, ctx->X, ctx->X);
 
@@ -119,7 +119,7 @@
             } else
                     LSHIFT(K, K);
 
-       
+
             if (ctx->M_n == 16) {
                     /* last block was a complete block */
                     XOR(K, ctx->M_last);
@@ -138,13 +138,13 @@
                          ctx->M_last[ctx->M_n] = 0;
    
                   XOR(K, ctx->M_last);
-          
-           
+
+
            }
            XOR(ctx->M_last, ctx->X);
-      
+
            //rijndael_encrypt(&ctx->rijndael, ctx->X, digest);
-    
+
        memcpy1(in, &ctx->X[0], 16); //Bestela ez du ondo iten
        aes_encrypt(in, digest, &ctx->rijndael);
            memset1(K, 0, sizeof K);
--- a/system/timer.cpp	Mon Mar 14 09:20:40 2016 +0000
+++ b/system/timer.cpp	Fri May 13 15:15:13 2016 +0000
@@ -40,6 +40,22 @@
     return ( ( TimerTime_t )CurrentTime );
 }
 
+TimerTime_t TimerGetElapsedTime( TimerTime_t savedTime )
+{
+    CurrentTime += TimeCounter.read_us( );
+    TimeCounter.reset( );
+    TimeCounter.start( );
+    return ( TimerTime_t )( CurrentTime - savedTime );
+}
+
+TimerTime_t TimerGetFutureTime( TimerTime_t eventInFuture )
+{
+    CurrentTime += TimeCounter.read_us( );
+    TimeCounter.reset( );
+    TimeCounter.start( );
+    return ( TimerTime_t )( CurrentTime + eventInFuture );
+}
+
 void TimerInit( TimerEvent_t *obj, void ( *callback )( void ) )
 {
     obj->value = 0;
--- a/system/timer.h	Mon Mar 14 09:20:40 2016 +0000
+++ b/system/timer.h	Fri May 13 15:15:13 2016 +0000
@@ -88,5 +88,20 @@
  */
 TimerTime_t TimerGetCurrentTime( void );
 
+/*!
+ * \brief Return the Time elapsed since a fix moment in Time
+ *
+ * \param [IN] savedTime    fix moment in Time
+ * \retval time             returns elapsed time
+ */
+TimerTime_t TimerGetElapsedTime( TimerTime_t savedTime );
+
+/*!
+ * \brief Return the Time elapsed since a fix moment in Time
+ *
+ * \param [IN] eventInFuture    fix moment in the future
+ * \retval time             returns difference between now and future event
+ */
+TimerTime_t TimerGetFutureTime( TimerTime_t eventInFuture );
 
 #endif // __TIMER_H__