uint32_t temp_values_handler() { uint32_t err_code = NRF_SUCCESS; int32_t temp_buffer; err_code = bme280_read_temperature(&temp_buffer); if (err_code != NRF_SUCCESS) { // temp_printf("temp: bme280_read_temperature() failed.\r\n"); return err_code; } char val[20]; char time_val[20]; add_zeroes((int)temp_buffer, val); add_zeroes((int)getTimeStamp(), time_val); char buf[20]; sprintf(buf, "\n%d,%s,%s", DEVICE_ID,time_val,val); log2sd(buf, "READINGS.txt"); // temp_printf("li\n"); // temp_printf("Temperature: %d\n", (int)temp_buffer); err_code = ble_ambient_sensor_update(m_temp.m_amb, (uint8_t *) &temp_buffer, AMB_TEMP_MAX_PACKET_VALUE, BLE_AMBIENT_TEMP); check_ble_service_err_code(err_code); return NRF_SUCCESS; }
uint32_t rain_reset_configs(){ uint32_t err_code = NRF_SUCCESS; //Set service to default configurations err_code = ble_ambient_config_update(m_rain.m_amb, RAIN_INITIAL_CONFIG, BLE_AMBIENT_RAIN); if(err_code != NRF_SUCCESS){ rain_printf("ble_ambient_config_update() for RAIN failed.\r\n"); return err_code; } err_code = rain_configs_update(); if(err_code != NRF_SUCCESS){ rain_printf("rain_configs_update() failed.\r\n"); return err_code; } //Reset sensor values uint8_t rain_buffer[AMB_RAIN_MAX_PACKET_VALUE]; for(uint8_t i = 0; i < AMB_RAIN_MAX_PACKET_VALUE; i++) rain_buffer[i] = INVALID_SENSOR_VALUE; check_ble_service_err_code( ble_ambient_sensor_update(m_rain.m_amb, rain_buffer, AMB_RAIN_MAX_PACKET_VALUE, BLE_AMBIENT_RAIN)); return NRF_SUCCESS; }
uint32_t temp_reset_configs(){ uint32_t err_code = NRF_SUCCESS; //Set service to default configurations err_code = ble_ambient_config_update(m_temp.m_amb, TEMP_INITIAL_CONFIG, BLE_AMBIENT_TEMP); if(err_code != NRF_SUCCESS){ temp_printf("ble_ambient_config_update() for TEMP failed.\r\n"); return err_code; } err_code = temp_configs_update(); if(err_code != NRF_SUCCESS){ temp_printf("temp_configs_update() failed.\r\n"); return err_code; } //Reset sensor values uint8_t temp_buffer[AMB_TEMP_MAX_PACKET_VALUE]; for(uint8_t i = 0; i < AMB_TEMP_MAX_PACKET_VALUE; i++) temp_buffer[i] = INVALID_SENSOR_VALUE; check_ble_service_err_code(ble_ambient_sensor_update(m_temp.m_amb, temp_buffer, AMB_TEMP_MAX_PACKET_VALUE, BLE_AMBIENT_TEMP)); return NRF_SUCCESS; }
uint32_t lum_values_handler() { uint32_t err_code = NRF_SUCCESS; uint32_t lum_buffer; //return NRF_SUCCESS; //SparkFunTSL2561_init(); err_code = SparkFunTSL2561_bring_the_light(&lum_buffer); //err_code = SparkFunMS1_read(&lum_buffer); if (err_code != NRF_SUCCESS) { lum_printf("lum: SparkFunTSL2561_bring_the_light failed.\r\n"); return err_code; } char buf[12]; sprintf(buf, "%d,%d,%d,%d,\n", DEVICE_ID,SENSOR_LUM_ID,(int)lum_buffer,000); log2sd(buf, "TEMP.txt"); lum_printf("Luminosity: %d\r\n", (int)lum_buffer); err_code = ble_ambient_sensor_update(m_lum.m_amb, (uint8_t *) &lum_buffer, AMB_LUM_MAX_PACKET_VALUE, BLE_AMBIENT_LUM); check_ble_service_err_code(err_code); return NRF_SUCCESS; }
uint32_t lum_reset_configs(){ uint32_t err_code = NRF_SUCCESS; //Set service to default configurations err_code = ble_ambient_config_update(m_lum.m_amb, LUM_INITIAL_CONFIG, BLE_AMBIENT_LUM); if(err_code != NRF_SUCCESS){ lum_printf("ble_ambient_config_update() for LUM failed.\r\n"); return err_code; } err_code = lum_configs_update(); if(err_code != NRF_SUCCESS){ lum_printf("lum_configs_update() failed.\r\n"); return err_code; } //Reset sensor values uint8_t lum_buffer[AMB_LUM_MAX_PACKET_VALUE]; for(uint8_t i = 0; i < AMB_LUM_MAX_PACKET_VALUE; i++) lum_buffer[i] = INVALID_SENSOR_VALUE; check_ble_service_err_code( ble_ambient_sensor_update(m_lum.m_amb, lum_buffer, AMB_LUM_MAX_PACKET_VALUE, BLE_AMBIENT_LUM)); return NRF_SUCCESS; }
uint32_t hum_values_handler() { uint32_t err_code = NRF_SUCCESS; int32_t hum_buffer; err_code = bme280_read_humidity(&hum_buffer); if (err_code != NRF_SUCCESS) { // hum_printf("hum: bme280_read_pressure() failed.\r\n"); return err_code; } char val[20]; add_zeroes((int)hum_buffer, val); char buf[20]; sprintf(buf, ",%s", val); log2sd(buf, "READINGS.txt"); // hum_printf("Humidity: %d\r\n", (int)hum_buffer); // hum_printf("li\n"); //err_code = ble_ambient_sensor_update(m_hum.m_amb, (uint8_t *) &hum_buffer, //AMB_HUM_MAX_PACKET_VALUE, BLE_AMBIENT_HUM); check_ble_service_err_code(err_code); return NRF_SUCCESS; }
uint32_t rain_values_handler() { uint32_t err_code; uint8_t rain_buffer; err_code = SparkFunMS1_read1(&rain_buffer); char buf[12]; sprintf(buf, ",%d", (int)err_code); //bool, has no zeroes. log2sd(buf, "READINGS.txt"); // rain_printf("li\n"); // rain_printf("Rain: %d value: %d \r\n", (int)err_code,(int)rain_buffer); err_code = ble_ambient_sensor_update(m_rain.m_amb, (uint8_t *) &err_code, AMB_RAIN_MAX_PACKET_VALUE, BLE_AMBIENT_RAIN); check_ble_service_err_code(err_code); return NRF_SUCCESS; }
uint32_t temp_values_handler() { uint32_t err_code = NRF_SUCCESS; int32_t temp_buffer; err_code = bme280_read_temperature(&temp_buffer); if (err_code != NRF_SUCCESS) { temp_printf("temp: bme280_read_temperature() failed.\r\n"); return err_code; } char buf[12]; sprintf(buf, "%d,%d,%d,%d,\n", DEVICE_ID,SENSOR_TEMP_ID,(int)temp_buffer,000); log2sd(buf, "TEMP.txt"); lerCartao(); temp_printf("Temperature: %d\n", (int)temp_buffer); err_code = ble_ambient_sensor_update(m_temp.m_amb, (uint8_t *) &temp_buffer, AMB_TEMP_MAX_PACKET_VALUE, BLE_AMBIENT_TEMP); check_ble_service_err_code(err_code); return NRF_SUCCESS; }