RP

Dependencies:   mbed SX1272Lib

Revision:
13:4429cb012011
Parent:
9:443b48f76c2e
Child:
14:c7449c450d0b
--- a/app/main.cpp	Wed Jul 25 08:18:57 2018 +0000
+++ b/app/main.cpp	Thu Jul 26 07:25:15 2018 +0000
@@ -34,7 +34,7 @@
 /*!
  * Default datarate
  */
-#define LORAWAN_DEFAULT_DATARATE                    DR_5
+#define LORAWAN_DEFAULT_DATARATE                    DR_0
 
 /*!
  * LoRaWAN confirmed messages
@@ -59,7 +59,7 @@
  */
 #define LORAWAN_DUTYCYCLE_ON                        true
 
-#define USE_SEMTECH_DEFAULT_CHANNEL_LINEUP          1
+#define USE_SEMTECH_DEFAULT_CHANNEL_LINEUP          0
 
 #if( USE_SEMTECH_DEFAULT_CHANNEL_LINEUP == 1 )
 
@@ -87,7 +87,7 @@
 #define LORAWAN_APP_DATA_SIZE                       6
 
 #else
-#define LORAWAN_APP_DATA_SIZE                       1
+#define LORAWAN_APP_DATA_SIZE                       8
 
 #endif
 
@@ -232,6 +232,11 @@
 }LoRaMacDownlinkStatus;
 volatile bool DownlinkStatusUpdated = false;
 
+
+AnalogIn LightSensor(A3); 
+AnalogIn AirSensor(A2); 
+AnalogIn TemperatureSensor(A1); 
+
 void SerialDisplayRefresh( void )
 {
     MibRequestConfirm_t mibReq;
@@ -286,17 +291,52 @@
  */
 static void PrepareTxFrame( uint8_t port )
 {
+    unsigned int a, beta = 4275, units, tens;
+    
+    float temperature, resistance, lux, air;
+    
     switch( port )
     {
     case 15:
         {
+            
+            // Read Temperature sensor
+            a = TemperatureSensor.read_u16(); /* Read analog value */
+        
+            /* Calculate the resistance of the thermistor from analog votage read. */
+            resistance= (float) 10000.0 * ((65536.0 / a) - 1.0);
+        
+            /* Convert the resistance to temperature using Steinhart's Hart equation */
+            temperature=(1/((log(resistance/10000.0)/beta) + (1.0/298.15)))-273.15; 
+ 
+             units = (int)(temperature*10);
+             tens  = (int)units/0x100;
+            
             //AppData[0] = AppLedStateOn;
-            AppData[0] = 'A'; 
-            //AppData[1] = 'H'; // ASCII : 0x48
-            //AppData[2] = 'e'; // ASCII : 0x65
-            //AppData[3] = 'l'; // ASCII : 0x6C
-            //AppData[4] = 'l'; // ASCII : 0x6C
-            //AppData[5] = 'o'; // ASCII : 0x6F
+            AppData[0] = 01;   // Channel 1
+            AppData[1] = 0x67; // Temperature
+            AppData[2] = tens;
+            AppData[3] = units;  
+
+            // Read Light Sensor
+            a = LightSensor.read_u16(); /* Read analog value */
+            /* Calculate resistance of sensor in K */
+            resistance = (float)(65535 - a) * 10 / a;
+            
+            // convert to Lux
+            lux = (1/resistance)*2000;  // value to be optimise
+            SerialDisplayData(lux);
+            AppData[4] = 2;   // Channel 2
+            AppData[5] = 0x65; // lux
+            AppData[6] = (int)lux/0x100; 
+            AppData[7] = (int)lux; 
+            
+            // Air quality
+            air = AirSensor.read()*1000; /* Read analog value */
+            //SerialDisplayData(a);
+            SerialDisplayFloat(air);    
+           
+
             if( IsTxConfirmed == true )
             {
             }