main.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #include <string>
  2. #include "freertos/FreeRTOS.h"
  3. #include "freertos/task.h"
  4. #include "freertos/event_groups.h"
  5. #include "driver/gpio.h"
  6. #include "sdkconfig.h"
  7. // SD-Card ////////////////////
  8. #include "nvs_flash.h"
  9. #include "esp_vfs_fat.h"
  10. #include "sdmmc_cmd.h"
  11. #include "driver/sdmmc_host.h"
  12. #include "driver/sdmmc_defs.h"
  13. ///////////////////////////////
  14. #include "ClassLogFile.h"
  15. #include "connect_wlan.h"
  16. #include "server_tflite.h"
  17. #include "server_file.h"
  18. #include "server_ota.h"
  19. #include "time_sntp.h"
  20. #include "ClassControllCamera.h"
  21. #include "server_main.h"
  22. #include "server_camera.h"
  23. #include "server_GPIO.h"
  24. static const char *TAGMAIN = "connect_wlan_main";
  25. #define FLASH_GPIO GPIO_NUM_4
  26. void Init_NVS_SDCard()
  27. {
  28. esp_err_t ret = nvs_flash_init();
  29. if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
  30. ESP_ERROR_CHECK(nvs_flash_erase());
  31. ret = nvs_flash_init();
  32. }
  33. ESP_LOGI(TAGMAIN, "Initializing SD card");
  34. sdmmc_host_t host = SDMMC_HOST_DEFAULT();
  35. host.flags = SDMMC_HOST_FLAG_1BIT;
  36. // sdmmc_host_t host = SDMMC_HOST_SLOT_1();
  37. // host.flags = SDMMC_HOST_FLAG_1BIT;
  38. sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
  39. slot_config.width = 1; // 1 line SD mode
  40. esp_vfs_fat_sdmmc_mount_config_t mount_config = { };
  41. mount_config.format_if_mount_failed = false;
  42. mount_config.max_files = 5;
  43. gpio_set_pull_mode((gpio_num_t) 15, GPIO_PULLUP_ONLY); // CMD, needed in 4- and 1- line modes
  44. gpio_set_pull_mode((gpio_num_t) 2, GPIO_PULLUP_ONLY); // D0, needed in 4- and 1-line modes
  45. sdmmc_card_t* card;
  46. ret = esp_vfs_fat_sdmmc_mount("/sdcard", &host, &slot_config, &mount_config, &card);
  47. if (ret != ESP_OK) {
  48. if (ret == ESP_FAIL) {
  49. ESP_LOGE(TAGMAIN, "Failed to mount filesystem. If you want the card to be formatted, set format_if_mount_failed = true.");
  50. } else {
  51. ESP_LOGE(TAGMAIN, "Failed to initialize the card (%d). Make sure SD card lines have pull-up resistors in place.", ret);
  52. }
  53. return;
  54. }
  55. sdmmc_card_print_info(stdout, card);
  56. // Init the GPIO
  57. // Flash ausschalten
  58. gpio_pad_select_gpio(FLASH_GPIO);
  59. gpio_set_direction(FLASH_GPIO, GPIO_MODE_OUTPUT);
  60. gpio_set_level(FLASH_GPIO, 0);
  61. }
  62. extern "C" void app_main(void)
  63. {
  64. printf("Do Reset Camera\n");
  65. PowerResetCamera();
  66. Camera.InitCam();
  67. Camera.LightOnOff(false);
  68. Init_NVS_SDCard();
  69. CheckOTAUpdate();
  70. LoadWlanFromFile("/sdcard/wlan.ini");
  71. ConnectToWLAN();
  72. printf("\nNetparameter: IP: %s - GW: %s - NetMask %s\n", getIPAddress().c_str(), getGW().c_str(), getNetMask().c_str());
  73. TickType_t xDelay;
  74. xDelay = 2000 / portTICK_PERIOD_MS;
  75. printf("Autoflow: sleep for : %ldms\n", (long) xDelay);
  76. // LogFile.WriteToFile("Startsequence 06");
  77. vTaskDelay( xDelay );
  78. // LogFile.WriteToFile("Startsequence 07");
  79. setup_time();
  80. LogFile.WriteToFile("=============================================================================================");
  81. LogFile.WriteToFile("=================================== Main Started ============================================");
  82. LogFile.WriteToFile("=============================================================================================");
  83. LogFile.SwitchOnOff(false);
  84. std::string zw = gettimestring("%Y%m%d-%H%M%S");
  85. printf("time %s\n", zw.c_str());
  86. // Camera.InitCam();
  87. // Camera.LightOnOff(false);
  88. xDelay = 2000 / portTICK_PERIOD_MS;
  89. printf("Autoflow: sleep for : %ldms\n", (long) xDelay);
  90. vTaskDelay( xDelay );
  91. server = start_webserver();
  92. register_server_camera_uri(server);
  93. register_server_tflite_uri(server);
  94. register_server_file_uri(server, "/sdcard");
  95. register_server_ota_sdcard_uri(server);
  96. register_server_GPIO_uri(server);
  97. register_server_main_uri(server, "/sdcard");
  98. TFliteDoAutoStart();
  99. }