esp32s2_fh4_test_board/main/app_main.c
yangxy ace9248046 ✏️ 添加(sensor APP):添加sensor APP功能,未完成
✏️ 添加(sensor drv):添加bmp280驱动代码,未完成
2022-09-30 18:32:07 +08:00

80 lines
2.2 KiB
C

/* Hello World Example
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_spi_flash.h"
#include "nvs_flash.h"
#include "app_task_hello.h"
#include "app_task_wifi.h"
#include "app_task_mqtt.h"
#include "app_task_sensors.h"
#include "app_main.h"
static app_main_handle_t sg_app_main_handle = {0};
static void _init_esp()
{
// Initialize NVS
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK( ret );
}
void app_main(void)
{
app_task_wifi_t wifi_info = {0};
printf("Hello world!\n");
vTaskDelay(10);
_init_esp();
// app_hello_task_start();
app_task_wifi_start();
app_task_mqtt_start();
app_task_sensors_start();
/* Print chip information */
esp_chip_info_t chip_info;
esp_chip_info(&chip_info);
printf("This is %s chip with %d CPU core(s), WiFi%s%s, ",
CONFIG_IDF_TARGET,
chip_info.cores,
(chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "",
(chip_info.features & CHIP_FEATURE_BLE) ? "/BLE" : "");
printf("silicon revision %d, ", chip_info.revision);
printf("%dMB %s flash\n", spi_flash_get_chip_size() / (1024 * 1024),
(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");
printf("Minimum free heap size: %d bytes\n", esp_get_minimum_free_heap_size());
for (int i = 10; ; ) {
// printf("Restarting in %d seconds...\n", i);
app_task_wifi_get_info(&wifi_info);
sg_app_main_handle.have_network = wifi_info.is_wifi_conneted;
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
printf("Restarting now.\n");
fflush(stdout);
esp_restart();
}
uint8_t app_main_handle_get_nework_state()
{
return sg_app_main_handle.have_network;
}