main.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* OpenSSL client test
  2. This example code is in the Public Domain (or CC0 licensed, at your option.)
  3. Unless required by applicable law or agreed to in writing, this
  4. software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  5. CONDITIONS OF ANY KIND, either express or implied.
  6. */
  7. #include <stdio.h>
  8. #include <stddef.h>
  9. #include <string.h>
  10. #include "esp_system.h"
  11. #include "nvs_flash.h"
  12. #include "esp_event.h"
  13. #include "esp_netif.h"
  14. #include "esp_log.h"
  15. #include "protocol_examples_common.h"
  16. static const char *TAG = "OPENSSL_TEST";
  17. void connection_test(char *line);
  18. static void get_string(char *line, size_t size)
  19. {
  20. int count = 0;
  21. while (count < size) {
  22. int c = fgetc(stdin);
  23. if (c == '\n') {
  24. line[count] = '\0';
  25. break;
  26. } else if (c > 0 && c < 127) {
  27. line[count] = c;
  28. ++count;
  29. }
  30. vTaskDelay(10 / portTICK_PERIOD_MS);
  31. }
  32. }
  33. void app_main(void)
  34. {
  35. char line[256];
  36. ESP_LOGI(TAG, "[APP] Free memory: %d bytes", esp_get_free_heap_size());
  37. ESP_LOGI(TAG, "[APP] IDF version: %s", esp_get_idf_version());
  38. esp_log_level_set("*", ESP_LOG_INFO);
  39. esp_log_level_set("OPENSSL_CLIENT", ESP_LOG_VERBOSE);
  40. esp_log_level_set("TRANSPORT_BASE", ESP_LOG_VERBOSE);
  41. esp_log_level_set("TRANSPORT", ESP_LOG_VERBOSE);
  42. esp_log_level_set("OUTBOX", ESP_LOG_VERBOSE);
  43. ESP_ERROR_CHECK(nvs_flash_init());
  44. ESP_ERROR_CHECK(esp_netif_init());
  45. ESP_ERROR_CHECK(esp_event_loop_create_default());
  46. /* This helper function configures Wi-Fi or Ethernet, as selected in menuconfig.
  47. * Read "Establishing Wi-Fi or Ethernet Connection" section in
  48. * examples/protocols/README.md for more information about this function.
  49. */
  50. ESP_ERROR_CHECK(example_connect());
  51. while (1) {
  52. get_string(line, sizeof(line));
  53. if (memcmp(line, "conn", 4) == 0) {
  54. // line starting with "conn" indicate connection tests
  55. connection_test(line);
  56. get_string(line, sizeof(line));
  57. continue;
  58. }
  59. }
  60. }