light sensor

Dependencies:   X_NUCLEO_IKS01A1 LoRaWAN-lib SX1276Lib mbed

Fork of LoRaWAN-SX1276-Application-Demo by Uttam Bhat

Files at this revision

API Documentation at this revision

Comitter:
ubhat
Date:
Thu Apr 06 16:35:17 2017 +0000
Parent:
2:78df92a365c2
Child:
4:a8706ec8a6d0
Commit message:
Added Cayenne Payload Format for IKAS Mems (PORT# 9)

Changed in this revision

app/Config.h Show annotated file Show diff for this revision Revisions of this file
app/LoRaApp.cpp Show annotated file Show diff for this revision Revisions of this file
app/LoRaApp.h Show annotated file Show diff for this revision Revisions of this file
app/LoRaEventProc.cpp Show annotated file Show diff for this revision Revisions of this file
board/board.cpp Show annotated file Show diff for this revision Revisions of this file
board/board.h Show annotated file Show diff for this revision Revisions of this file
--- a/app/Config.h	Sat Aug 27 04:03:02 2016 +0000
+++ b/app/Config.h	Thu Apr 06 16:35:17 2017 +0000
@@ -63,7 +63,7 @@
 /*!
  * LoRaWAN application port
  */
-#define LORAWAN_APP_PORT                            8
+#define LORAWAN_APP_PORT                            9
 
 /*!
  * LoRaWAN User defined Tx Power
@@ -97,6 +97,21 @@
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
+#elif ( LORAWAN_APP_PORT == 9 )
+/*====================================================
+    IKS01A1 SENSOR DATA (PORT 9) + CAYENNE LPP
+====================================================*/
+
+#define USE_IKS01A1_SENSOR
+
+#define USE_CAYENNE_LPP
+/*!
+ * User application data buffer size
+ */
+#define LORAWAN_APP_DATA_SIZE                       11
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
 #elif ( LORAWAN_APP_PORT == 11 )
 /*====================================================
                 PUSH BUTTON DEMO (PORT 11)
--- a/app/LoRaApp.cpp	Sat Aug 27 04:03:02 2016 +0000
+++ b/app/LoRaApp.cpp	Thu Apr 06 16:35:17 2017 +0000
@@ -21,6 +21,16 @@
 int32_t Accl_Value[3] = {0};
 #endif
 
+#ifdef USE_CAYENNE_LPP
+/*
+.... Pressure
+.... Temperature
+.... Humidity
+.... Accelerometer
+*/
+uint8_t maxLPPsize[4] = {4, 4, 3, 8};
+#endif
+
 bool VerticalStatus = false;
 
 
@@ -55,13 +65,18 @@
         {    
 #ifdef USE_IKS01A1_SENSOR 
                         
-            temp_sensor1->GetTemperature(&iks01a1_data);
+            temp_sensor2->GetTemperature(&iks01a1_data);
                                     
             printf("Temp = %f, %d\r\n", iks01a1_data, (int8_t) iks01a1_data);
                                
             if( ( BuffPtr + 1 ) <= LORAWAN_APP_DATA_SIZE )
             {
-                BuffAddr[BuffPtr++] = (int8_t) iks01a1_data;                         
+#ifdef USE_CAYENNE_LPP
+                BuffAddr[BuffPtr++] = 0;
+                BuffAddr[BuffPtr++] = (int8_t) ( iks01a1_data * 10 );
+#else                
+                BuffAddr[BuffPtr++] = (int8_t) iks01a1_data;
+#endif                
             }
             
 #endif            
@@ -79,8 +94,16 @@
                                
             if( ( BuffPtr + 2 ) <= LORAWAN_APP_DATA_SIZE )
             {
+#ifdef USE_CAYENNE_LPP
+                int16_t tmp;
+                
+                tmp =  (int16_t) ( iks01a1_data * 10 );
+                BuffAddr[BuffPtr++] = ( tmp >> 8 ) & 0xFF;
+                BuffAddr[BuffPtr++] = ( tmp ) & 0xFF;
+#else                
                 BuffAddr[BuffPtr++] = ( (int16_t) iks01a1_data >> 8 ) & 0xFF;
-                BuffAddr[BuffPtr++] = ( (int16_t) iks01a1_data ) & 0xFF;                         
+                BuffAddr[BuffPtr++] = ( (int16_t) iks01a1_data ) & 0xFF;
+#endif                
             }
             
 #endif            
@@ -98,7 +121,11 @@
                                
             if( ( BuffPtr + 1 ) <= LORAWAN_APP_DATA_SIZE )
             {
+#ifdef USE_CAYENNE_LPP
+                BuffAddr[BuffPtr++] = (uint8_t) ( iks01a1_data * 2 );
+#else                
                 BuffAddr[BuffPtr++] = (int8_t) iks01a1_data;
+#endif                
             }
             
 #endif            
--- a/app/LoRaApp.h	Sat Aug 27 04:03:02 2016 +0000
+++ b/app/LoRaApp.h	Thu Apr 06 16:35:17 2017 +0000
@@ -123,6 +123,10 @@
 
 extern bool VerticalStatus;
 
+#ifdef USE_CAYENNE_LPP
+extern uint8_t maxLPPsize[4];
+#endif
+
 /*!  
 * \brief Blink LED
 *
--- a/app/LoRaEventProc.cpp	Sat Aug 27 04:03:02 2016 +0000
+++ b/app/LoRaEventProc.cpp	Thu Apr 06 16:35:17 2017 +0000
@@ -23,6 +23,8 @@
 
 bool AppLed = 0;
 
+uint8_t AppCase = 0;
+
 /*!
  * \brief   Prepares the payload of the frame based on application port
  */
@@ -92,6 +94,105 @@
 
             break;
         }
+       
+        // IKAS sensor using Cayenne Payload Format
+        case 9: 
+        { 
+#ifdef USE_CAYENNE_LPP        
+            uint8_t ptrIndex = 0;
+            
+            uint16_t AppSize = 0;
+            
+            uint8_t tmp[2] = {0};
+            
+            //Point the pointer to position index of Tx Buffer
+            LoRaApp.ApplicationPtrPos( ptrIndex );
+            
+            AppCase = AppCase > 3 ? 0 : AppCase;
+            
+            while( 1 )
+            {            
+                switch( AppCase ) 
+                {
+                    case 0: 
+                    {
+                        tmp[0] = 0;
+                        tmp[1] = 115; // Data Type PRESSURE: 115
+                        LoRaApp.ApplicationAppendData( tmp, 2 );
+                        
+                        /*!
+                        *  Read Pressure
+                        *  Appends 2 Bytes to TX buffer
+                        */
+                        LoRaApp.ApplicationCall( AppPressr );
+                        
+                        AppSize += maxLPPsize[AppCase];
+
+                        break;
+                    }
+                    
+                    case 1: 
+                    {
+                        tmp[0] = 1;
+                        tmp[1] = 103; // Data Type TEMP: 103
+                        LoRaApp.ApplicationAppendData( tmp, 2 );
+                    
+                        /*!
+                        *  Read Temperature
+                        *  Appends 1 Byte to TX buffer
+                        */
+                        LoRaApp.ApplicationCall( AppTemp );
+                        
+                        AppSize += maxLPPsize[AppCase];
+
+                        break;
+                    }
+                    
+                    case 2: 
+                    {
+                        tmp[0] = 2;
+                        tmp[1] = 104; // Data Type HUMIDITY: 103
+                        LoRaApp.ApplicationAppendData( tmp, 2 );
+                        
+                        /*!
+                        *  Read Humidity
+                        *  Appends 1 Byte to TX buffer
+                        */
+                        LoRaApp.ApplicationCall( AppHumid );
+                        
+                        AppSize += maxLPPsize[AppCase];
+
+                        break;
+                    }
+                    
+                    case 3: 
+                    {
+                        tmp[0] = 3;
+                        tmp[1] = 113; // Data Type Accl: 113
+                        LoRaApp.ApplicationAppendData( tmp, 2 );
+                        /*!
+                        *  Read Accelerometer                        
+                        */
+                        LoRaApp.ApplicationCall( AppAccl ); // Generate Accelerometer data bytes
+                        
+                        AppSize += maxLPPsize[AppCase];
+
+                        break;
+                    }
+                }
+                
+                AppCase++;
+                
+                if( AppSize + maxLPPsize[AppCase] > LORAWAN_APP_DATA_SIZE )
+                {
+                    break;
+                }
+            }
+                        
+            AppDataSize = AppSize;            
+#endif
+            break;
+        }
 
     // Push-Button Demo     
     case 11: 
--- a/board/board.cpp	Sat Aug 27 04:03:02 2016 +0000
+++ b/board/board.cpp	Thu Apr 06 16:35:17 2017 +0000
@@ -29,6 +29,7 @@
 HumiditySensor *humidity_sensor = mems_expansion_board->ht_sensor;;
 PressureSensor *pressure_sensor = mems_expansion_board->pt_sensor;
 TempSensor *temp_sensor1 = mems_expansion_board->ht_sensor;
+TempSensor *temp_sensor2 = mems_expansion_board->pt_sensor;
 #endif
 
 SX1276MB1xAS Radio( NULL );
--- a/board/board.h	Sat Aug 27 04:03:02 2016 +0000
+++ b/board/board.h	Thu Apr 06 16:35:17 2017 +0000
@@ -49,6 +49,7 @@
 extern HumiditySensor *humidity_sensor;
 extern PressureSensor *pressure_sensor;
 extern TempSensor *temp_sensor1;
+extern TempSensor *temp_sensor2;
 #endif
 
 /*!