main.cpp 4.1 KB

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