main.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. #include "ClassLogFile.h"
  8. //#include "esp_wifi.h"
  9. //#include "protocol_examples_common.h"
  10. #include "connect_wlan.h"
  11. #include <esp_http_server.h>
  12. #include "lwip/err.h"
  13. #include "lwip/sockets.h"
  14. #include "lwip/sys.h"
  15. #include "lwip/netdb.h"
  16. #include "lwip/dns.h"
  17. #include <sys/unistd.h>
  18. #include <sys/stat.h>
  19. #include "esp_log.h"
  20. #include "esp_system.h"
  21. #include "esp_event.h"
  22. #include "esp_event_loop.h"
  23. #include "nvs_flash.h"
  24. #include "esp_err.h"
  25. #include "esp_vfs_fat.h"
  26. #include "driver/sdmmc_host.h"
  27. #include "driver/sdmmc_defs.h"
  28. #include "sdmmc_cmd.h"
  29. #include "server_main.h"
  30. #include "server_camera.h"
  31. #include "server_tflite.h"
  32. #include "server_file.h"
  33. #include "server_ota.h"
  34. #include "time_sntp.h"
  35. #include "ClassControllCamera.h"
  36. #include "freertos/FreeRTOS.h"
  37. #include "freertos/task.h"
  38. #include "freertos/event_groups.h"
  39. #include "freertos/FreeRTOS.h"
  40. // SD-Card
  41. #include "nvs_flash.h"
  42. #include "esp_vfs_fat.h"
  43. #include "sdmmc_cmd.h"
  44. #include "server_main.h"
  45. #include "server_camera.h"
  46. #include "ClassControllCamera.h"
  47. #include "connect_wlan.h"
  48. #include "time_sntp.h"
  49. static const char *TAGMAIN = "connect_wlan_main";
  50. #define FLASH_GPIO GPIO_NUM_4
  51. void Init_NVS_SDCard()
  52. {
  53. esp_err_t ret = nvs_flash_init();
  54. if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
  55. ESP_ERROR_CHECK(nvs_flash_erase());
  56. ret = nvs_flash_init();
  57. }
  58. ESP_LOGI(TAGMAIN, "Initializing SD card");
  59. sdmmc_host_t host = SDMMC_HOST_DEFAULT();
  60. host.flags = SDMMC_HOST_FLAG_1BIT;
  61. sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
  62. esp_vfs_fat_sdmmc_mount_config_t mount_config = { };
  63. mount_config.format_if_mount_failed = false;
  64. mount_config.max_files = 5;
  65. sdmmc_card_t* card;
  66. ret = esp_vfs_fat_sdmmc_mount("/sdcard", &host, &slot_config, &mount_config, &card);
  67. if (ret != ESP_OK) {
  68. if (ret == ESP_FAIL) {
  69. ESP_LOGE(TAGMAIN, "Failed to mount filesystem. If you want the card to be formatted, set format_if_mount_failed = true.");
  70. } else {
  71. ESP_LOGE(TAGMAIN, "Failed to initialize the card (%d). Make sure SD card lines have pull-up resistors in place.", ret);
  72. }
  73. return;
  74. }
  75. sdmmc_card_print_info(stdout, card);
  76. // Init the GPIO
  77. // Flash ausschalten
  78. gpio_pad_select_gpio(FLASH_GPIO);
  79. gpio_set_direction(FLASH_GPIO, GPIO_MODE_OUTPUT);
  80. gpio_set_level(FLASH_GPIO, 0);
  81. }
  82. extern "C" void app_main()
  83. {
  84. printf("Do Reset Camera\n");
  85. PowerResetCamera();
  86. // LogFile.WriteToFile("Startsequence 01");
  87. Init_NVS_SDCard();
  88. LogFile.WriteToFile("Startsequence 02");
  89. CheckOTAUpdate();
  90. LogFile.WriteToFile("Startsequence 03");
  91. std::string ssid = "";
  92. std::string password = "";
  93. LoadWlanFromFile("/sdcard/wlan.ini", ssid, password);
  94. LogFile.WriteToFile("Startsequence 04");
  95. printf("WLan: %s, %s\n", ssid.c_str(), password.c_str());
  96. initialise_wifi(ssid, password);
  97. LogFile.WriteToFile("Startsequence 05");
  98. TickType_t xDelay;
  99. xDelay = 2000 / portTICK_PERIOD_MS;
  100. printf("Autoflow: sleep for : %ldms\n", (long) xDelay);
  101. LogFile.WriteToFile("Startsequence 06");
  102. vTaskDelay( xDelay );
  103. LogFile.WriteToFile("Startsequence 07");
  104. setup_time();
  105. LogFile.WriteToFile("======================== Main Started ================================");
  106. std::string zw = gettimestring("%Y%m%d-%H%M%S");
  107. printf("time %s\n", zw.c_str());
  108. Camera.InitCam();
  109. Camera.LightOnOff(false);
  110. xDelay = 2000 / portTICK_PERIOD_MS;
  111. printf("Autoflow: sleep for : %ldms\n", (long) xDelay);
  112. vTaskDelay( xDelay );
  113. server = start_webserver();
  114. register_server_camera_uri(server);
  115. register_server_tflite_uri(server);
  116. register_server_file_uri(server, "/sdcard");
  117. register_server_ota_sdcard_uri(server);
  118. register_server_main_uri(server, "/sdcard");
  119. TFliteDoAutoStart();
  120. }