1
Dependencies: X_NUCLEO_IKS01A1 LoRaWAN-lib SX1276Lib mbed
Revision 2:78df92a365c2, committed 2016-08-27
- Comitter:
- ubhat
- Date:
- Sat Aug 27 04:03:02 2016 +0000
- Parent:
- 1:80c1daf19aa4
- Child:
- 3:4bca7f8f731a
- Commit message:
- X_Nucleo_IKS01A1 Sensor application (Port 8)
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/X_NUCLEO_IKS01A1.lib Sat Aug 27 04:03:02 2016 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/teams/ST/code/X_NUCLEO_IKS01A1/#f4fa3dad9ec4
--- a/app/Config.h Fri Aug 26 20:51:07 2016 +0000 +++ b/app/Config.h Sat Aug 27 04:03:02 2016 +0000 @@ -63,7 +63,7 @@ /*! * LoRaWAN application port */ -#define LORAWAN_APP_PORT 11 +#define LORAWAN_APP_PORT 8 /*! * LoRaWAN User defined Tx Power @@ -84,23 +84,12 @@ /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#elif ( LORAWAN_APP_PORT == 6 ) +#elif ( LORAWAN_APP_PORT == 8 ) /*==================================================== - SENET M2X DEMO (PORT 6) + IKS01A1 SENSOR DATA (PORT 8) ====================================================*/ -/*! - * User application data buffer size - */ -#define LORAWAN_APP_DATA_SIZE 2 - -/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ - -#elif ( LORAWAN_APP_PORT == 7 ) -/*==================================================== - SENET GPS DEMO (PORT 7) -====================================================*/ - +#define USE_IKS01A1_SENSOR /*! * User application data buffer size */ @@ -120,19 +109,6 @@ /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#elif ( LORAWAN_APP_PORT == 12 ) -/*==================================================== - TRANSMIT ON VERTICAL ORIENTATION DEMO (PORT 12) -====================================================*/ - -/*! - * User application data buffer size - */ -#define LORAWAN_APP_DATA_SIZE 2 - -/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ - - #endif #endif // __LORA_CONFIG_H__
--- a/app/LoRaApp.cpp Fri Aug 26 20:51:07 2016 +0000 +++ b/app/LoRaApp.cpp Sat Aug 27 04:03:02 2016 +0000 @@ -16,6 +16,11 @@ #include "LoRaApp.h" +#ifdef USE_IKS01A1_SENSOR +float iks01a1_data; +int32_t Accl_Value[3] = {0}; +#endif + bool VerticalStatus = false; @@ -44,40 +49,59 @@ void Application::ApplicationCall( eAppType App ) { switch( App ) - { - // Appends 8 Bytes (3 bytes longitude, 3 bytes latitude, 2 bytes altitude) to TX buffer - case AppGps: - { - /* - Gps.service( ); - - uint16_t altitudeGps = atoi( Gps.NmeaGpsData.NmeaAltitude ); - - if( ( BuffPtr + 8 ) <= LORAWAN_APP_DATA_SIZE ) - { - BuffAddr[BuffPtr++] = ( Gps.LatitudeBinary >> 16 ) & 0xFF; - BuffAddr[BuffPtr++] = ( Gps.LatitudeBinary >> 8 ) & 0xFF; - BuffAddr[BuffPtr++] = Gps.LatitudeBinary & 0xFF; - BuffAddr[BuffPtr++] = ( Gps.LongitudeBinary >> 16 ) & 0xFF; - BuffAddr[BuffPtr++] = ( Gps.LongitudeBinary >> 8 ) & 0xFF; - BuffAddr[BuffPtr++] = Gps.LongitudeBinary & 0xFF; - BuffAddr[BuffPtr++] = ( altitudeGps >> 8 ) & 0xFF; - BuffAddr[BuffPtr++] = altitudeGps & 0xFF; - } - */ - break; - } - + { // Appends 1 Byte to TX buffer case AppTemp: { - /* - Mpl3115a2.ReadTemperature( ); +#ifdef USE_IKS01A1_SENSOR + + temp_sensor1->GetTemperature(&iks01a1_data); + + printf("Temp = %f, %d\r\n", iks01a1_data, (int8_t) iks01a1_data); + if( ( BuffPtr + 1 ) <= LORAWAN_APP_DATA_SIZE ) { - BuffAddr[BuffPtr++] = ( int32_t )Mpl3115a2.Temperature; // Signed degrees Celcius in half degree units. So, +/-63 °C + BuffAddr[BuffPtr++] = (int8_t) iks01a1_data; + } + +#endif + break; + } + + // Appends 2 Bytes to TX buffer + case AppPressr: + { +#ifdef USE_IKS01A1_SENSOR + + pressure_sensor->GetPressure(&iks01a1_data); + + printf("Pressure = %f, %d\r\n", iks01a1_data, (uint16_t) iks01a1_data); + + if( ( BuffPtr + 2 ) <= LORAWAN_APP_DATA_SIZE ) + { + BuffAddr[BuffPtr++] = ( (int16_t) iks01a1_data >> 8 ) & 0xFF; + BuffAddr[BuffPtr++] = ( (int16_t) iks01a1_data ) & 0xFF; } - */ + +#endif + break; + } + + // Appends 2 Bytes to TX buffer + case AppHumid: + { +#ifdef USE_IKS01A1_SENSOR + + humidity_sensor->GetHumidity(&iks01a1_data); + + printf("Humidity = %f, %d\r\n", iks01a1_data, (uint8_t) iks01a1_data); + + if( ( BuffPtr + 1 ) <= LORAWAN_APP_DATA_SIZE ) + { + BuffAddr[BuffPtr++] = (int8_t) iks01a1_data; + } + +#endif break; } @@ -108,76 +132,25 @@ // Appends 2 Bytes to TX buffer case AppAccl: { - /* - uint8_t statusReg; - - // Read the PS_STATUS register - statusReg = Mma8451q.read_single( MMA8451_PL_STATUS ); - - // Display Orientation of NAMote on Serial Port - SerialAcclMetrDisplay( statusReg ); - - // If Orientation of the Mote changed then let Green LED ON - if( ( statusReg & 0x80 ) != 0 ) - { - AppLed = 1; - CtrlLED( Green, LED_ON ); - } - - // Read and populate device orientation in Tx Buffer - if( ( BuffPtr + 2 ) <= LORAWAN_APP_DATA_SIZE ) +#ifdef USE_IKS01A1_SENSOR + + accelerometer->Get_X_Axes(Accl_Value); + + printf("X/Y/Z = %d/%d/%d\r\n", Accl_Value[0], Accl_Value[1], Accl_Value[2]); + + if( ( BuffPtr + 6 ) <= LORAWAN_APP_DATA_SIZE ) { - if( statusReg & 0x40 ) - { - if( statusReg & 0x01 ) - { - BuffAddr[BuffPtr++] = 0x66; // horizontal + faceup - } - else - { - BuffAddr[BuffPtr++] = 0x99; // horizontal + facedown - } - - BuffAddr[BuffPtr++] = 0; // vertical = false - } - else - { - BuffAddr[BuffPtr++] = 0; // horizontal = false - BuffAddr[BuffPtr++] = 0x11; // vertical = true - } - } - */ + BuffAddr[BuffPtr++] = ( (int16_t) Accl_Value[0] >> 8 ) & 0xFF; + BuffAddr[BuffPtr++] = ( (int16_t) Accl_Value[0] ) & 0xFF; + BuffAddr[BuffPtr++] = ( (int16_t) Accl_Value[1] >> 8 ) & 0xFF; + BuffAddr[BuffPtr++] = ( (int16_t) Accl_Value[1] ) & 0xFF; + BuffAddr[BuffPtr++] = ( (int16_t) Accl_Value[2] >> 8 ) & 0xFF; + BuffAddr[BuffPtr++] = ( (int16_t) Accl_Value[2] ) & 0xFF; + } +#endif break; } - case AppAcclSenet: - { - /* - uint8_t statusReg; - - // Read the PS_STATUS register - statusReg = Mma8451q.read_single( MMA8451_PL_STATUS ); - - // Display Orientation of NAMote on Serial Port - SerialAcclMetrDisplay( statusReg ); - - // If Orientation of the Mote changed then populate Upper Nibble of 0th Byte of Tx Buffer - if( ( statusReg & 0x40 ) != 0 ) - { - AppLed = 0; - CtrlLED( Green, LED_OFF ); - BuffAddr[BuffPtr++] = 0; // horizontal - } - else - { - AppLed = 1; - CtrlLED( Green, LED_ON ); - BuffAddr[BuffPtr++] = 10; // vertical - } - */ - break; - } - case AppPushButton: { uint16_t PushButtonCnt;
--- a/app/LoRaApp.h Fri Aug 26 20:51:07 2016 +0000 +++ b/app/LoRaApp.h Sat Aug 27 04:03:02 2016 +0000 @@ -43,13 +43,13 @@ */ enum eAppType { - AppGps = 0, // GPS application - AppTemp = 1, // Temperature measurement application - AppBat = 2, // Battery measurement application - AppRamp = 3, // Generate Ramp bytes - AppAccl = 4, // Accelerometer application - AppAcclSenet = 5, // Senet + M2X application example - AppPushButton = 6, // Push button application example + AppPressr = 0, // Pressure measurement application + AppTemp, // Temperature measurement application + AppHumid, // Humidity measurement application + AppBat, // Battery measurement application + AppRamp, // Generate Ramp bytes + AppAccl, // Accelerometer application + AppPushButton, // Push button application example }; /*!
--- a/app/LoRaEventProc.cpp Fri Aug 26 20:51:07 2016 +0000 +++ b/app/LoRaEventProc.cpp Sat Aug 27 04:03:02 2016 +0000 @@ -46,22 +46,38 @@ LoRaApp.ApplicationAppendData( &tmp, tmpLength ); // Populate lower nibble of 0th Byte with LED state /*! + * Generate Ramp data bytes + * Appends incremental values of 1 Byte each to TX buffer until Full + */ + LoRaApp.ApplicationCall( AppRamp ); + + break; + } + + case 8: + { + uint8_t ptrIndex = 0; + + //Point the pointer to position index of Tx Buffer + LoRaApp.ApplicationPtrPos( ptrIndex ); + + /*! + * Read Pressure + * Appends 2 Bytes to TX buffer + */ + LoRaApp.ApplicationCall( AppPressr ); + + /*! * Read Temperature * Appends 1 Byte to TX buffer */ LoRaApp.ApplicationCall( AppTemp ); - + /*! - * Read Battery + * Read Humidity * Appends 1 Byte to TX buffer */ - LoRaApp.ApplicationCall( AppBat ); - - /*! - * Read GPS coordinates - * Appends 8 Bytes (3 bytes longitude, 3 bytes latitude, 2 bytes altitude) to TX buffer - */ - LoRaApp.ApplicationCall( AppGps ); + LoRaApp.ApplicationCall( AppHumid ); /*! * Read Accelerometer @@ -73,49 +89,6 @@ */ LoRaApp.ApplicationCall( AppAccl ); // Generate Accelerometer data bytes - /*! - * Generate Ramp data bytes - * Appends incremental values of 1 Byte each to TX buffer until Full - */ - LoRaApp.ApplicationCall( AppRamp ); - - break; - } - - // Senet M2X ORIENTATION Demo - // Set LORAWAN_APP_DATA_SIZE to 2 - case 6: - { - uint8_t ptrIndex = 1; - - //Point the pointer to position index of Tx Buffer - LoRaApp.ApplicationPtrPos( ptrIndex ); - - LoRaApp.ApplicationCall( AppAcclSenet ); // Generate Accelerometer data bytes - - - - break; - } - - /* Senet GPS Demo - Data Format (in Hex): - [01, 02, Lattitude (3 bytes), Longitude (3 Bytes), Elevation (2 bytes), Tx Power (1 byte)] - */ - case 7: - { - uint8_t ptrIndex = 0; - uint8_t tmp[] = {0x01, 0x02}; - - //Point the pointer to position index of Tx Buffer - LoRaApp.ApplicationPtrPos( ptrIndex ); - - LoRaApp.ApplicationAppendData( tmp, 2 ); - - LoRaApp.ApplicationCall( AppGps ); // Generate Accelerometer data bytes - - uint8_t pow = 30 - 2*(( uint8_t ) LoRaMacUplinkStatus.TxPower); - LoRaApp.ApplicationAppendData( &pow, 1 ); break; } @@ -132,20 +105,7 @@ break; } - - // Transmit on Vertical Orientation Demo - case 12: - { - uint8_t ptrIndex = 0; - - //Point the pointer to position index of Tx Buffer - LoRaApp.ApplicationPtrPos( ptrIndex ); - - LoRaApp.ApplicationCall( AppPushButton ); // Transmit uplink counter - - break; - } - + default: break; } @@ -300,12 +260,12 @@ if( AppLed != 0 ) { // Turn USR_LED ON - //CtrlLED( Usr, LED_ON ); + //UsrLED = 3.3; } else { // Turn USR_LED OFF - //CtrlLED( Usr, LED_OFF ); + //UsrLED = 0; } }
--- a/board/board.cpp Fri Aug 26 20:51:07 2016 +0000 +++ b/board/board.cpp Sat Aug 27 04:03:02 2016 +0000 @@ -15,18 +15,21 @@ #include "mbed.h" #include "board.h" -MoteVersion_t BoardGetVersion( void ); - DigitalIn I2cInterrupt( PB_4 ); I2C I2c(I2C_SDA, I2C_SCL); DigitalOut Pc7( PC_7 ); DigitalIn Pc1( PC_1 ); -DigitalIn UsrButton(PC_13 ); +DigitalIn UsrButton( PC_13 ); -#define AIN_VREF 3.3 // STM32 internal refernce -#define AIN_VBAT_DIV 2 // Resistor divider +#ifdef USE_IKS01A1_SENSOR +X_NUCLEO_IKS01A1 *mems_expansion_board = X_NUCLEO_IKS01A1::Instance(); +MotionSensor *accelerometer = mems_expansion_board->GetAccelerometer(); +HumiditySensor *humidity_sensor = mems_expansion_board->ht_sensor;; +PressureSensor *pressure_sensor = mems_expansion_board->pt_sensor; +TempSensor *temp_sensor1 = mems_expansion_board->ht_sensor; +#endif SX1276MB1xAS Radio( NULL );
--- a/board/board.h Fri Aug 26 20:51:07 2016 +0000 +++ b/board/board.h Sat Aug 27 04:03:02 2016 +0000 @@ -22,6 +22,10 @@ #include "system/utilities.h" #include "sx1276-hal.h" +#ifdef USE_IKS01A1_SENSOR +#include "x_nucleo_iks01a1.h" +#endif + /*! * Unique Devices IDs register set ( STM32L1xxx ) */ @@ -30,18 +34,22 @@ #define ID3 ( 0x1FF800E4 ) #define LOW_BAT_THRESHOLD 3.45 +#define AIN_VREF 3.3 // STM32 internal refernce +#define AIN_VBAT_DIV 2 // Resistor divider extern SX1276MB1xAS Radio; extern DigitalIn UsrButton; -typedef enum -{ - MOTE_VERSION_NONE = 0, - MOTE_VERSION_2, - MOTE_VERSION_3, -}MoteVersion_t; +extern AnalogOut UsrLED; +#ifdef USE_IKS01A1_SENSOR +extern X_NUCLEO_IKS01A1 *mems_expansion_board; +extern MotionSensor *accelerometer; +extern HumiditySensor *humidity_sensor; +extern PressureSensor *pressure_sensor; +extern TempSensor *temp_sensor1; +#endif /*! * \brief Initializes the target board peripherals.