Air quality sensor
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
esp-airsensor/main/app_main.c

73 lines
2.0 KiB

#include <sdkconfig.h>
#include <console/console.h>
#include <console/console_ioimpl.h>
#include "esp_wifi.h"
#include "esp_event.h"
#include "esp_log.h"
#include "esp_system.h"
#include "nvs_flash.h"
#include "driver/adc.h"
#include "application.h"
#include "settings.h"
#include "console/console_server.h"
#include "web/websrv.h"
#include "wifi_conn.h"
#include "console/register_cmds.h"
#include "periph_init.h"
#include "voc_sensor.h"
#include "tasks.h"
#include "co2_sensor.h"
static const char *TAG = "main";
void app_main(void) {
ESP_ERROR_CHECK(nvs_flash_init());
ESP_ERROR_CHECK(esp_register_shutdown_handler(cspemu_run_shutdown_handlers));
ESP_ERROR_CHECK(esp_event_loop_create_default());
settings_init();
settings_load();
// Start IDF service for pin change interrupts
ESP_ERROR_CHECK(gpio_install_isr_service(0));
ESP_LOGD(TAG, "initing netif");
ESP_ERROR_CHECK(esp_netif_init());
if (g_Settings.wifi_enabled && (g_Settings.sta_enabled || g_Settings.ap_enabled)) {
initialise_wifi();
websrv_init();
g_State.wifi_inited = true;
} else {
// initialise the bare minimum so wifi config can be changed
ESP_LOGD(TAG, "initing wifi");
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
ESP_LOGD(TAG, "set storage, set sta");
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_FLASH));
g_State.wifi_inited = true;
}
periph_init();
vTaskDelay(pdMS_TO_TICKS(1000));
xTaskCreate(voc_read_task, "VOC", 4096, NULL, PRIO_NORMAL, NULL);
xTaskCreate(co2_read_task, "CO2", 4096, NULL, PRIO_NORMAL, NULL);
console_init(NULL);
register_console_commands();
console_setup_uart_stdio();
ESP_ERROR_CHECK(console_start_stdio(NULL, NULL));
telnetsrv_start(CONSOLE_TELNET_PORT);
ESP_LOGI(TAG, "Startup finished, free heap = %u, cmds %"PRIu32, esp_get_free_heap_size(), console_count_commands());
}