123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- #include "freertos/FreeRTOS.h"
- #include "freertos/task.h"
- #include "esp_log.h"
- #include "config.h"
- #include "wifi.h"
- #include "mqtt.h"
- #include "kWhCounter.h"
- #include "http_client.h"
- #include "readTemps.h"
- // Chip info:
- // This is esp32 chip with 2 CPU cores, WiFi/BT/BLE, silicon revision 1, 4MB external flash
- void app_main(void)
- {
- ESP_LOGI("MAIN", "HomeEnergyMeter ESP32. Core:%d",xPortGetCoreID());
- gpio_reset_pin(VVB_RELAY_OUTPUT_IO);
- gpio_set_direction(VVB_RELAY_OUTPUT_IO, GPIO_MODE_OUTPUT);
- // Wait for stable environment
- vTaskDelay(2000.0 / portTICK_PERIOD_MS);
- #ifdef ENABLE_DS18B20
- initTempReadings();
- #endif
- #ifdef ENABLE_KWH_COUNTER
- kWhCounter_init();
- #endif
- #ifdef WIFI_ENABLED
- initWifi(); // Init WIFI
- #endif
- #ifdef MQTT_ENABLED
- mqtt_init();
- #endif
- TickType_t vLastWakeTime = xTaskGetTickCount();
- // Do an initial delay to make the different tasks to work out of sync to each other (not send all data at same time)
- vTaskDelayUntil( &vLastWakeTime, 30000 / portTICK_PERIOD_MS );
- // ---------------- MAIN WHILE -------------------
- while(1) {
- vTaskDelayUntil( &vLastWakeTime, 60000 / portTICK_PERIOD_MS );
- http_rest_with_url();
- }
- vTaskDelete(NULL);
- }
|