main.c 1.2 KB

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