main.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include "freertos/FreeRTOS.h"
  2. #include "freertos/task.h"
  3. #include "esp_log.h"
  4. #include "config.h"
  5. #include "wifi.h"
  6. #include "mqtt.h"
  7. #include "readTemps.h"
  8. #include "rxTimer.h"
  9. #include "transceiver.h"
  10. #include "receiver.h"
  11. #include "lux.h"
  12. // Chip info:
  13. // This is esp32 chip with 2 CPU cores, WiFi/BT/BLE, silicon revision 1, 4MB external flash
  14. void getChipInfo(void) {
  15. esp_chip_info_t chip_info;
  16. esp_chip_info(&chip_info);
  17. ESP_LOGI("MAIN", "Model: %s", chip_info.model == CHIP_ESP32 ? "ESP32" : "Unknown");
  18. ESP_LOGI("MAIN", "Features: WiFi%s%s, %d cores",
  19. (chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "",
  20. (chip_info.features & CHIP_FEATURE_BLE) ? "/BLE" : "",
  21. chip_info.cores);
  22. ESP_LOGI("MAIN", "Revision: %d", chip_info.revision);
  23. }
  24. void app_main(void)
  25. {
  26. ESP_LOGI("MAIN", "GarageTransceiver ESP32. Core:%d",xPortGetCoreID());
  27. getChipInfo();
  28. // Wait for stable environment
  29. vTaskDelay(2000.0 / portTICK_PERIOD_MS);
  30. #ifdef RX_TIMER_ENABLED
  31. rxTimerInit(); // First we start the Timer (which samples Rx and handles uS-delays)
  32. #endif
  33. #ifdef TRANCEIVER_ENABLED
  34. initTransceiver(); // Init the transceiver
  35. initReceiver(); // Init the receiver
  36. #endif
  37. #ifdef ENABLE_DS18B20
  38. initTempReadings();
  39. #endif
  40. #ifdef WIFI_ENABLED
  41. initWifi(); // Init WIFI
  42. #endif
  43. #ifdef MQTT_ENABLED
  44. mqtt_init();
  45. #endif
  46. #ifdef ENABLE_LUX_SENSOR
  47. init_tsl2561();
  48. #endif
  49. TickType_t vLastWakeTime = xTaskGetTickCount();
  50. // Do an initial delay to make the different tasks to work out of sync to each other (not send all data at same time)
  51. vTaskDelayUntil( &vLastWakeTime, 30000 / portTICK_PERIOD_MS );
  52. // ---------------- MAIN WHILE -------------------
  53. while(1) {
  54. vTaskDelayUntil( &vLastWakeTime, 60000 / portTICK_PERIOD_MS );
  55. // Do periodic work here, if needed
  56. }
  57. vTaskDelete(NULL);
  58. }