1
0

main.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. // Chip info:
  9. // This is esp32 chip with 2 CPU cores, WiFi/BT/BLE, silicon revision 1, 4MB external flash
  10. void app_main(void)
  11. {
  12. ESP_LOGI("MAIN", "GarageTransceiver ESP32. Core:%d",xPortGetCoreID());
  13. // Wait for stable environment
  14. vTaskDelay(2000.0 / portTICK_PERIOD_MS);
  15. #ifdef ENABLE_DS18B20
  16. initTempReadings();
  17. #endif
  18. #ifdef ENABLE_KWH_COUNTER
  19. kWhCounter_init();
  20. #endif
  21. #ifdef WIFI_ENABLED
  22. initWifi(); // Init WIFI
  23. #endif
  24. #ifdef MQTT_ENABLED
  25. mqtt_init();
  26. #endif
  27. TickType_t vLastWakeTime = xTaskGetTickCount();
  28. // Do an initial delay to make the different tasks to work out of sync to each other (not send all data at same time)
  29. vTaskDelayUntil( &vLastWakeTime, 30000 / portTICK_PERIOD_MS );
  30. // ---------------- MAIN WHILE -------------------
  31. while(1) {
  32. vTaskDelayUntil( &vLastWakeTime, 60000 / portTICK_PERIOD_MS );
  33. // Do periodic work here, if needed
  34. }
  35. vTaskDelete(NULL);
  36. }