sensor off during adv+shorter adv interval
This commit is contained in:
parent
92d36acb47
commit
d8cbfd323d
@ -86,8 +86,9 @@ struct ble_hs_adv_fields adv_fields = {
|
||||
struct ble_gap_adv_params adv_params = {
|
||||
.conn_mode = BLE_GAP_CONN_MODE_UND,
|
||||
.disc_mode = BLE_GAP_DISC_MODE_GEN,
|
||||
.itvl_min = 0x4000,
|
||||
.itvl_max = 0x4000,
|
||||
.itvl_min = 1000,
|
||||
.itvl_max = 2000,
|
||||
//.itvl_max = 0x4000,
|
||||
};
|
||||
|
||||
struct ble_gap_upd_params conn_params = {
|
||||
@ -277,6 +278,7 @@ static int gatt_svr_chr_access_batt_level(uint16_t conn_handle, uint16_t attr_ha
|
||||
}
|
||||
|
||||
static void ble_advertise(void){
|
||||
main_app_conf->sensor->enabled = false;
|
||||
ESP_ERROR_CHECK(ble_gap_adv_set_fields(&adv_fields));
|
||||
ESP_ERROR_CHECK(ble_gap_adv_start(ble_addr_type, NULL, BLE_HS_FOREVER, &adv_params, ble_gap_event, NULL));
|
||||
}
|
||||
@ -290,6 +292,7 @@ static int ble_gap_event(struct ble_gap_event *event, void* arg){
|
||||
else {
|
||||
conn_handle = event->connect.conn_handle;
|
||||
ESP_ERROR_CHECK(ble_gap_update_params(event->connect.conn_handle, &conn_params));
|
||||
main_app_conf->sensor->enabled = true;
|
||||
}
|
||||
break;
|
||||
case BLE_GAP_EVENT_DISCONNECT:
|
||||
|
@ -5,7 +5,7 @@ name,data,string,CO2Sense
|
||||
wireless_conf,data,u8,4
|
||||
ap_ssid,data,string,CO2Sense
|
||||
ap_pass,data,string,testtest
|
||||
sensor_conf,data,u16,22
|
||||
sensor_conf,data,u16,122
|
||||
#
|
||||
leds,namespace,,
|
||||
led_nb,data,u8,3
|
||||
|
|
@ -47,7 +47,6 @@ void app_main(void){
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_pm_configure(&pm_config));
|
||||
|
||||
|
||||
configuration_data_t* conf = malloc(sizeof(configuration_data_t));
|
||||
init_conf_from_nvs(conf);
|
||||
|
||||
@ -77,7 +76,50 @@ void app_main(void){
|
||||
|
||||
init_scd4x();
|
||||
scd4x_power_down();
|
||||
switch(conf->sensor->mode){
|
||||
if(conf->sensor->mode & SCD4X_CAPTURE_ENABLED){
|
||||
TaskHandle_t sensor_fetch_handle;
|
||||
xTaskCreate(fetch_sensor_task, "FETCH_SENSOR", 4096, conf, tskIDLE_PRIORITY, &sensor_fetch_handle);
|
||||
}
|
||||
|
||||
while(1){
|
||||
/*int32_t x,y,z;
|
||||
MMC56x3_get_mag_field(&x, &y, &z);
|
||||
float bx, by, bz;
|
||||
MMC56x3_to_mG(x, y, z, &bx, &by, &bz);
|
||||
ESP_LOGI("MAIN", "BField x %ld, y %ld, z %ld", x, y, z);
|
||||
ESP_LOGI("MAIN", "BField x %f mG, y %f mG, z %f mG", bx, by, bz);*/
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
|
||||
void fetch_sensor_task(void* pvParameters){
|
||||
configuration_data_t* mainConf = (configuration_data_t*) pvParameters;
|
||||
scd4x_config_t* conf = mainConf->sensor;
|
||||
scd4x_data_t* measures = conf->measure;
|
||||
uint8_t sensorStarted = false;
|
||||
while(1){
|
||||
ESP_LOGI("MAIN", "witing for %d sec", conf->delay);
|
||||
vTaskDelay(conf->delay * 1000 / portTICK_PERIOD_MS);
|
||||
if(!conf->enabled){
|
||||
if(sensorStarted){
|
||||
sensorStarted = false;
|
||||
scd4x_power_down();
|
||||
}
|
||||
else{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if(conf->enabled && !sensorStarted){
|
||||
scd4x_wake_up();
|
||||
for(int i=0; i<5; i++){
|
||||
uint16_t s0, s1, s2;
|
||||
int16_t res=scd4x_get_serial_number(&s0, &s1, &s2);
|
||||
if(res == 0) break;
|
||||
vTaskDelay(500 / portTICK_PERIOD_MS);
|
||||
ESP_LOGI("MAIN", "get serial, res %d; serial %d %d %d", res, s0, s1, s2);
|
||||
}
|
||||
sensorStarted = true;
|
||||
switch(conf->mode){
|
||||
case SCD4X_NORMAL_MODE:
|
||||
ESP_ERROR_CHECK(scd4x_start_periodic_measurement());
|
||||
ESP_LOGI("scd4x init","started in normal mode");
|
||||
@ -87,32 +129,16 @@ void app_main(void){
|
||||
ESP_LOGI("scd4x init","started in low power mode");
|
||||
break;
|
||||
}
|
||||
if(conf->sensor->mode & SCD4X_CAPTURE_ENABLED){
|
||||
TaskHandle_t sensor_fetch_handle;
|
||||
xTaskCreate(fetch_sensor_task, "FETCH_SENSOR", 4096, conf, tskIDLE_PRIORITY, &sensor_fetch_handle);
|
||||
}
|
||||
|
||||
while(1){
|
||||
int32_t x,y,z;
|
||||
MMC56x3_get_mag_field(&x, &y, &z);
|
||||
float bx, by, bz;
|
||||
MMC56x3_to_mG(x, y, z, &bx, &by, &bz);
|
||||
ESP_LOGI("MAIN", "BField x %ld, y %ld, z %ld", x, y, z);
|
||||
ESP_LOGI("MAIN", "BField x %f mG, y %f mG, z %f mG", bx, by, bz);
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
|
||||
void fetch_sensor_task(void* pvParameters){
|
||||
configuration_data_t* mainConf = (configuration_data_t*) pvParameters;
|
||||
scd4x_config_t* conf = mainConf->sensor;
|
||||
scd4x_data_t* measures = conf->measure;
|
||||
while(1){
|
||||
if(conf->mode == SCD4X_SS_MODE) scd4x_measure_single_shot();
|
||||
vTaskDelay(conf->delay * 1000 / portTICK_PERIOD_MS);
|
||||
ESP_LOGI("MAIN", "reading sensor");
|
||||
uint16_t dataReady;
|
||||
scd4x_get_data_ready_status(&dataReady);
|
||||
if(!(dataReady & 0x07FF)) continue;
|
||||
if(!(dataReady & 0x07FF)){
|
||||
ESP_LOGI("MAIN", "no new sensor data");
|
||||
continue;
|
||||
}
|
||||
int16_t error = scd4x_read_measurement(&measures->co2, &measures->temperature, &measures->humidity);
|
||||
if (error)
|
||||
ESP_LOGE("sensor fetch", "Error executing scd4x_read_measurement(): %i\n", error);
|
||||
|
Loading…
x
Reference in New Issue
Block a user