LoRaWAN_FAE_Training
Dependencies: X_NUCLEO_IKS01A2
Diff: main.cpp
- Revision:
- 51:a6da9392e7c3
- Parent:
- 50:dbfbb8d03a79
- Child:
- 52:d75d967418ed
diff -r dbfbb8d03a79 -r a6da9392e7c3 main.cpp --- a/main.cpp Wed Mar 13 10:18:20 2019 +0000 +++ b/main.cpp Thu Mar 14 09:24:00 2019 +0000 @@ -33,11 +33,13 @@ static XNucleoIKS01A2 *mems_expansion_board = XNucleoIKS01A2::instance(D14, D15, D4, D5); /* Retrieve the composing elements of the expansion board */ +/* static LSM303AGRMagSensor *magnetometer = mems_expansion_board->magnetometer; static HTS221Sensor *hum_temp = mems_expansion_board->ht_sensor; static LPS22HBSensor *press_temp = mems_expansion_board->pt_sensor; static LSM6DSLSensor *acc_gyro = mems_expansion_board->acc_gyro; static LSM303AGRAccSensor *accelerometer = mems_expansion_board->accelerometer; +*/ using namespace events; @@ -106,32 +108,34 @@ */ int main (void) { - uint8_t id; + //uint8_t id; // setup tracing setup_trace(); // Init IKS01A2 Board -// printf("\r\n--- IKS01A2 conf start ---\r\n"); -// -// /* Enable all sensors */ -// hum_temp->enable(); -// press_temp->enable(); -// magnetometer->enable(); -// accelerometer->enable(); -// acc_gyro->enable_x(); -// acc_gyro->enable_g(); -// -// hum_temp->read_id(&id); -// printf("HTS221 humidity & temperature = 0x%X\r\n", id); -// press_temp->read_id(&id); -// printf("LPS22HB pressure & temperature = 0x%X\r\n", id); -// magnetometer->read_id(&id); -// printf("LSM303AGR magnetometer = 0x%X\r\n", id); -// accelerometer->read_id(&id); -// printf("LSM303AGR accelerometer = 0x%X\r\n", id); -// acc_gyro->read_id(&id); -// printf("LSM6DSL accelerometer & gyroscope = 0x%X\r\n", id); + /* + printf("\r\n--- IKS01A2 conf start ---\r\n"); + + // Enable all sensors + hum_temp->enable(); + press_temp->enable(); + magnetometer->enable(); + accelerometer->enable(); + acc_gyro->enable_x(); + acc_gyro->enable_g(); + + hum_temp->read_id(&id); + printf("HTS221 humidity & temperature = 0x%X\r\n", id); + press_temp->read_id(&id); + printf("LPS22HB pressure & temperature = 0x%X\r\n", id); + magnetometer->read_id(&id); + printf("LSM303AGR magnetometer = 0x%X\r\n", id); + accelerometer->read_id(&id); + printf("LSM303AGR accelerometer = 0x%X\r\n", id); + acc_gyro->read_id(&id); + printf("LSM6DSL accelerometer & gyroscope = 0x%X\r\n", id); + */ // stores the status of a call to LoRaWAN protocol lorawan_status_t retcode; @@ -188,92 +192,96 @@ */ static void send_message() { - uint16_t packet_len, Temperature, Index=1; + int16_t retcode; + uint16_t packet_len; + /* + uint16_t Temperature, Index=1; uint32_t Pressure, Humidity; - int16_t retcode; float sensor_value; float value1, value2; char buffer1[32], buffer2[32]; int32_t axes[3]; -// hum_temp->get_temperature(&value1); -// hum_temp->get_humidity(&value2); -// printf("HTS221: [temp] %2.2f C, [hum] %2.2f \r\n", value1, value2); -// Humidity = value2 * 100; -// -// /*Add Humidity*/ -// tx_buffer[0]+=1; // Add 1 Nbelment -// tx_buffer[Index]=0x03; // Humidity -// tx_buffer[Index+1]=0x03; // Len -// tx_buffer[Index+2]=(uint8_t)(Humidity & 0xFF); // Press LSB -// tx_buffer[Index+3]=(uint8_t)((Humidity >> 8) & 0xFF); // Press MID -// tx_buffer[Index+4]=(uint8_t)((Humidity >> 16) & 0xFF); // Press MSB -// Index+=5; -// -// press_temp->get_temperature(&value1); -// press_temp->get_pressure(&value2); -// printf("LPS22HB: [temp] %2.2f C, [press] %4.2f mbar\r\n", value1, value2); -// -// -// Temperature = value1 * 100; // Convert for transmit -// Pressure = value2 * 100; // Convert for transmit -// -// /*Add Tempertaure*/ -// tx_buffer[0]+=1; // Add 1 Nbelment -// tx_buffer[Index]=0x01; // Temperature -// tx_buffer[Index+1]=0x02; // Len -// tx_buffer[Index+2]=(uint8_t)(Temperature & 0xFF); // Temp LSB -// tx_buffer[Index+3]=(uint8_t)((Temperature >> 8) & 0xFF); // Temp MSB -// Index+=4; // Update the Index -// -// /*Add Pressure*/ -// tx_buffer[0]+=1; -// tx_buffer[Index]=0x02; // Pressure -// tx_buffer[Index+1]=0x03; // Len -// tx_buffer[Index+2]=(uint8_t)(Pressure & 0xFF); // Press LSB -// tx_buffer[Index+3]=(uint8_t)((Pressure >> 8) & 0xFF); // Press MID -// tx_buffer[Index+4]=(uint8_t)((Pressure >> 16) & 0xFF); // Press MSB -// Index+=5; -// -// printf("---\r\n"); -// -//// magnetometer->get_m_axes(axes); -//// printf("LSM303AGR [mag/mgauss]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]); -//// -// accelerometer->get_x_axes(axes); -// printf("LSM303AGR [acc/mg]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]); -// -// /*Add Accelerometer*/ -// tx_buffer[0]+=1; -// tx_buffer[Index]=0x04; // Accelerometer -// tx_buffer[Index+1]=0x03; // Len -// /* x */ -// tx_buffer[Index+2]=(uint8_t)(axes[0] & 0xFF); // Press LSB -// tx_buffer[Index+3]=(uint8_t)((axes[0] >> 8) & 0xFF); // Press MID -// tx_buffer[Index+4]=(uint8_t)((axes[0] >> 16) & 0xFF); // Press MID -// tx_buffer[Index+5]=(uint8_t)((axes[0] >> 24) & 0xFF); // Press MSB -// -// /* y */ -// tx_buffer[Index+6]=(uint8_t)(axes[1] & 0xFF); // Press LSB -// tx_buffer[Index+7]=(uint8_t)((axes[1] >> 8) & 0xFF); // Press MID -// tx_buffer[Index+8]=(uint8_t)((axes[1] >> 16) & 0xFF); // Press MID -// tx_buffer[Index+9]=(uint8_t)((axes[1] >> 24) & 0xFF); // Press MSB -// -// /* z */ -// tx_buffer[Index+10]=(uint8_t)(axes[2] & 0xFF); // Press LSB -// tx_buffer[Index+11]=(uint8_t)((axes[2] >> 8) & 0xFF); // Press MID -// tx_buffer[Index+12]=(uint8_t)((axes[2] >> 16) & 0xFF); // Press MID -// tx_buffer[Index+13]=(uint8_t)((axes[2] >> 24) & 0xFF); // Press MSB -// Index+=14; -// -// acc_gyro->get_x_axes(axes); -// printf("LSM6DSL [acc/mg]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]); -// -// acc_gyro->get_g_axes(axes); -// printf("LSM6DSL [gyro/mdps]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]); + hum_temp->get_temperature(&value1); + hum_temp->get_humidity(&value2); + printf("HTS221: [temp] %2.2f C, [hum] %2.2f \r\n", value1, value2); + Humidity = value2 * 100; + + //Add Humidity + tx_buffer[0]+=1; // Add 1 Nbelment + tx_buffer[Index]=0x03; // Humidity + tx_buffer[Index+1]=0x03; // Len + tx_buffer[Index+2]=(uint8_t)(Humidity & 0xFF); // Press LSB + tx_buffer[Index+3]=(uint8_t)((Humidity >> 8) & 0xFF); // Press MID + tx_buffer[Index+4]=(uint8_t)((Humidity >> 16) & 0xFF); // Press MSB + Index+=5; + + press_temp->get_temperature(&value1); + press_temp->get_pressure(&value2); + printf("LPS22HB: [temp] %2.2f C, [press] %4.2f mbar\r\n", value1, value2); + + + Temperature = value1 * 100; // Convert for transmit + Pressure = value2 * 100; // Convert for transmit + + //Add Tempertaure + tx_buffer[0]+=1; // Add 1 Nbelment + tx_buffer[Index]=0x01; // Temperature + tx_buffer[Index+1]=0x02; // Len + tx_buffer[Index+2]=(uint8_t)(Temperature & 0xFF); // Temp LSB + tx_buffer[Index+3]=(uint8_t)((Temperature >> 8) & 0xFF); // Temp MSB + Index+=4; // Update the Index -// packet_len = Index + 1; // Compute the final payload size + //Add Pressure + tx_buffer[0]+=1; + tx_buffer[Index]=0x02; // Pressure + tx_buffer[Index+1]=0x03; // Len + tx_buffer[Index+2]=(uint8_t)(Pressure & 0xFF); // Press LSB + tx_buffer[Index+3]=(uint8_t)((Pressure >> 8) & 0xFF); // Press MID + tx_buffer[Index+4]=(uint8_t)((Pressure >> 16) & 0xFF); // Press MSB + Index+=5; + + printf("---\r\n"); + + magnetometer->get_m_axes(axes); + printf("LSM303AGR [mag/mgauss]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]); + + accelerometer->get_x_axes(axes); + printf("LSM303AGR [acc/mg]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]); + + //Add Accelerometer + tx_buffer[0]+=1; + tx_buffer[Index]=0x04; // Accelerometer + tx_buffer[Index+1]=0x03; // Len + // x + tx_buffer[Index+2]=(uint8_t)(axes[0] & 0xFF); // Press LSB + tx_buffer[Index+3]=(uint8_t)((axes[0] >> 8) & 0xFF); // Press MID + tx_buffer[Index+4]=(uint8_t)((axes[0] >> 16) & 0xFF); // Press MID + tx_buffer[Index+5]=(uint8_t)((axes[0] >> 24) & 0xFF); // Press MSB + + // y + tx_buffer[Index+6]=(uint8_t)(axes[1] & 0xFF); // Press LSB + tx_buffer[Index+7]=(uint8_t)((axes[1] >> 8) & 0xFF); // Press MID + tx_buffer[Index+8]=(uint8_t)((axes[1] >> 16) & 0xFF); // Press MID + tx_buffer[Index+9]=(uint8_t)((axes[1] >> 24) & 0xFF); // Press MSB + + // z + tx_buffer[Index+10]=(uint8_t)(axes[2] & 0xFF); // Press LSB + tx_buffer[Index+11]=(uint8_t)((axes[2] >> 8) & 0xFF); // Press MID + tx_buffer[Index+12]=(uint8_t)((axes[2] >> 16) & 0xFF); // Press MID + tx_buffer[Index+13]=(uint8_t)((axes[2] >> 24) & 0xFF); // Press MSB + Index+=14; + + acc_gyro->get_x_axes(axes); + printf("LSM6DSL [acc/mg]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]); + + acc_gyro->get_g_axes(axes); + printf("LSM6DSL [gyro/mdps]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]); + + packet_len = Index + 1; // Compute the final payload size + + */ retcode = lorawan.send(MBED_CONF_LORA_APP_PORT, tx_buffer, packet_len, MSG_UNCONFIRMED_FLAG); @@ -318,6 +326,7 @@ printf("\r\n Data Length: %d\r\n", retcode); + /* if(rx_buffer[0] & 0x01 == 1) { printf("\r\n Board is in Wrong side !!!!! \r\n\r\n"); @@ -330,6 +339,7 @@ { printf("\r\n It's humid here !!!!! \r\n\r\n"); } + */ memset(rx_buffer, 0, sizeof(rx_buffer)); }