Hello BSTRobin, thank you for your reply. The changes you suggested seem to work, as the sensor is already running for several hours. However it still resets the iaq_acc values everytime I start a LoRaWAN transmission. All values are defined as static, therefore it should not reset after performing a LoRaWAN Here is the code I use: //Main loop for BME680 measurements
if ((ret.bme680_status == 0) && (ret.bsec_status == 0))
{
// PDEBUG("intialize BSEC library successful\r\n");
/* Call to endless loop function which reads and processes data based on sensor settings */
/* State is saved every 10.000 samples, which means every 10.000 * 3 secs = 500 minutes */
while (1)
{
bsec_iot_loop(sleep, get_timestamp_us, output_ready, state_save,
10000);
HAL_GPIO_TogglePin(LED_0_GPIO_Port, LED_0_Pin);
if (lora_timer > tx_intervall_LoRa * 1000)
{
start_lora(my_data, data_len);
lora_timer = 0;
}
} Meanwhile I changed the bsec_iot_loop to void bsec_iot_loop(sleep_fct sleep, get_timestamp_us_fct get_timestamp_us, output_ready_fct output_ready,
state_save_fct state_save, uint32_t save_intvl)
{
/* Timestamp variables */
int64_t static time_stamp = 0;
int64_t static time_stamp_interval_ms = 0;
/* Allocate enough memory for up to BSEC_MAX_PHYSICAL_SENSOR physical inputs*/
bsec_input_t static bsec_inputs[BSEC_MAX_PHYSICAL_SENSOR];
/* Number of inputs to BSEC */
uint8_t static num_bsec_inputs = 0;
/* BSEC sensor settings struct */
bsec_bme_settings_t static sensor_settings;
/* Save state variables */
uint8_t static bsec_state[BSEC_MAX_STATE_BLOB_SIZE];
uint8_t static work_buffer[BSEC_MAX_WORKBUFFER_SIZE];
uint32_t static bsec_state_len = 0;
uint32_t static n_samples = 0;
bsec_library_return_t static bsec_status = BSEC_OK;
// while (1)
// {
/* get the timestamp in nanoseconds before calling bsec_sensor_control() */
time_stamp = get_timestamp_us() * 1000;
/* Retrieve sensor settings to be used in this time instant by calling bsec_sensor_control */
bsec_sensor_control(time_stamp, &sensor_settings);
/* Trigger a measurement if necessary */
bme680_bsec_trigger_measurement(&sensor_settings, sleep);
/* Read data from last measurement */
num_bsec_inputs = 0;
bme680_bsec_read_data(time_stamp, bsec_inputs, &num_bsec_inputs, sensor_settings.process_data);
/* Time to invoke BSEC to perform the actual processing */
bme680_bsec_process_data(bsec_inputs, num_bsec_inputs, output_ready);
/* Increment sample counter */
n_samples++;
/* Retrieve and store state if the passed save_intvl */
if (n_samples >= save_intvl)
{
bsec_status = bsec_get_state(0, bsec_state, sizeof(bsec_state), work_buffer, sizeof(work_buffer), &bsec_state_len);
if (bsec_status == BSEC_OK)
{
state_save(bsec_state, bsec_state_len);
}
n_samples = 0;
}
/* Compute how long we can sleep until we need to call bsec_sensor_control() next */
/* Time_stamp is converted from microseconds to nanoseconds first and then the difference to milliseconds */
time_stamp_interval_ms = (sensor_settings.next_call - get_timestamp_us() * 1000) / 1000000;
if (time_stamp_interval_ms > 0)
{
sleep((uint32_t)time_stamp_interval_ms);
}
// }
} so it will eventually leave the original loop to check, if it's ready to transmit data via LoRa. After every transmission, the stat_iaq resets and I cannot figure out why. Thank you in advance.
... View more