LoRaWAN VIT

Dependencies:   mbed DigitDisplay Chainable_RGB_LED LoRaWAN-lib SX1276Lib

Revision:
1:c365eaf833bb
Parent:
0:cb80564f40e1
Child:
2:66f94cef0765
diff -r cb80564f40e1 -r c365eaf833bb app/main.cpp
--- a/app/main.cpp	Thu Mar 17 09:32:46 2016 +0000
+++ b/app/main.cpp	Tue Apr 12 05:21:37 2016 +0000
@@ -52,9 +52,9 @@
  *
  * \remark Please note that when ADR is enabled the end-device should be static
  */
-#define LORAWAN_ADR_ON                              1
+#define LORAWAN_ADR_ON                              0
 
-#if defined( USE_BAND_868 )
+#if defined( USE_BAND_868 ) || defined( USE_BAND_865 )
 
 #include "LoRaMacTest.h"
 
@@ -70,16 +70,16 @@
 /*!
  * LoRaWAN application port
  */
-#define LORAWAN_APP_PORT                            10
+#define LORAWAN_APP_PORT                            5
 
 /*!
  * User application data buffer size
  */
 #if ( LORAWAN_CONFIRMED_MSG_ON == 1 )
-#define LORAWAN_APP_DATA_SIZE                       6
+#define LORAWAN_APP_DATA_SIZE                       7    //6
 
 #else
-#define LORAWAN_APP_DATA_SIZE                       5
+#define LORAWAN_APP_DATA_SIZE                       6   //5
 
 #endif
 
@@ -162,7 +162,7 @@
 /*!
  * Hold the value returned from the Light Sensor
  */
-static float LightValue = 0.0;
+//static float LightValue = 0.0;
 
 /*!
  * Control the 3-color LED 
@@ -191,13 +191,42 @@
 /*!
  * Constructor for Light Sensor
  */
-AnalogIn LightSens( A1 ); 
+AnalogIn LightSensor( A1 ); 
 
 /*!
  * Constructor for 4 Digit 7 semgent display
  */
 DigitDisplay display(D8, D9);
 
+/* LED For Customer */
+DigitalOut myLed ( D8 );
+
+/**
+Interrupt Event by SP
+**/
+InterruptIn buttonPressed(D7);
+uint8_t buttonCount = 0;
+bool buttonStatus = false;          //OFF = false & ON = true
+bool ledStatus = false;             //OFF = false & ON = true
+
+// Interrupt Handler for User Button
+void incButtonCount()
+{
+    buttonCount++;
+    buttonStatus=!buttonStatus;
+    if (buttonStatus == 1)
+    {
+        ledStatus=1;
+        myLed=1;
+    }
+    else 
+    {
+        ledStatus = 0;
+        myLed = 0;
+    }
+    
+}
+
 /*!
  * Device states
  */
@@ -288,7 +317,7 @@
     SerialDisplayUpdateNetworkIsJoined( mibReq.Param.IsNetworkJoined );
 
     SerialDisplayUpdateAdr( LORAWAN_ADR_ON );
-#if defined( USE_BAND_868 )
+#if defined( USE_BAND_868 ) || defined ( USE_BAND_865 )
     SerialDisplayUpdateDutyCycle( LORAWAN_DUTYCYCLE_ON );
 #else
     SerialDisplayUpdateDutyCycle( false );
@@ -324,14 +353,36 @@
     
     switch( port )
     {
+    case 5:
+            tempValue = LightSensor.read_u16();
+            AppData[0] = (( tempValue & 0xFF00 ) >> 8 ) & 0xFF;
+            AppData[1] = ( tempValue & 0x00FF );
+            AppData[2] = 44;            // Sending ','
+            AppData[3] = ledStatus + 48;      //Send LED status ON/OFF
+                        
+            //printf("Light Sensor = %d , %x", tempValue, tempValue);
+            break;
+            
     case 10:
         {  
+            AppData[0] = 72;
+            AppData[1] = 69;
+            AppData[2] = 76;
+            AppData[3] = 76;
+            AppData[4] = 79;
+            
+            tempValue = buttonStatus + 48;
+            AppData[5] = tempValue;
+            
+            buttonCount = 0;
+            /*
             tempValue = ( uint32_t )( LightValue * 1000000.0 );
             AppData[0] = LightMode;
             AppData[1] = ( ( tempValue & 0xFF000000 ) >> 24 ) & 0xFF;
             AppData[2] = ( ( tempValue & 0x00FF0000 ) >> 16 ) & 0xFF;
             AppData[3] = ( ( tempValue & 0x0000FF00 ) >> 8 ) & 0xFF;
             AppData[4] = ( tempValue & 0x000000FF );    
+            */
         }
         break;
     case 15:
@@ -660,7 +711,7 @@
                     mibReq.Param.AdrEnable = true;
                     LoRaMacMibSetRequestConfirm( &mibReq );
 
-#if defined( USE_BAND_868 )
+#if defined( USE_BAND_868 ) || defined( USE_BAND_865 )
                     LoRaMacTestSetDutyCycleOn( false );
 #endif
                 }
@@ -681,7 +732,7 @@
                     mibReq.Type = MIB_ADR;
                     mibReq.Param.AdrEnable = LORAWAN_ADR_ON;
                     LoRaMacMibSetRequestConfirm( &mibReq );
-#if defined( USE_BAND_868 )
+#if defined( USE_BAND_868 ) || defined( USE_BAND_865 )
                     LoRaMacTestSetDutyCycleOn( LORAWAN_DUTYCYCLE_ON );
 #endif
                     break;
@@ -772,10 +823,11 @@
  */
 int main( void )
 {
-    float tempLightValue = 0.0;   
+    //float tempLightValue = 0.0;   
     
     LightMode = 0;      // 0: manual,   1: automatic
     buzzer = 0;         // 0: OFF,      1: ON
+    myLed = 0;
     
     LoRaMacPrimitives_t LoRaMacPrimitives;
     LoRaMacCallback_t LoRaMacCallbacks;
@@ -783,7 +835,8 @@
 
     BoardInit( );
     SerialDisplayInit( );
-
+    buttonPressed.rise(&incButtonCount);
+    
     DeviceState = DEVICE_STATE_INIT;
 
     while( 1 )
@@ -849,7 +902,7 @@
                 mibReq.Param.EnablePublicNetwork = LORAWAN_PUBLIC_NETWORK;
                 LoRaMacMibSetRequestConfirm( &mibReq );
 
-#if defined( USE_BAND_868 )
+#if defined( USE_BAND_868 ) || defined( USE_BAND_865 )
                 LoRaMacTestSetDutyCycleOn( LORAWAN_DUTYCYCLE_ON );
                 SerialDisplayUpdateDutyCycle( LORAWAN_DUTYCYCLE_ON );
 #endif
@@ -967,6 +1020,7 @@
             
         }
         
+        /*
         // Read light sensor
         tempLightValue = LightSens.read( ) * 1.65;
         
@@ -977,5 +1031,6 @@
         {
             color_led.setColorRGB( 0, ( uint8_t )( 255 * LightValue ), ( uint8_t )( 255 * LightValue ), ( uint8_t )( 255 * LightValue ) );
         }
+        */
     }
 }