1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- #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)
- {
- char txt[50];
- 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);
- #ifdef ENABLE_KWH_COUNTER
- kWhCounter_init();
- #endif
- #ifdef WIFI_ENABLED
- initWifi(); // Init WIFI
- #endif
- #ifdef MQTT_ENABLED
- mqtt_init();
- #endif
- const TickType_t xFreq = 5000 / portTICK_PERIOD_MS;
- TickType_t vLastWakeTime = xTaskGetTickCount();
- // ---------------- MAIN WHILE -------------------
- while(1) {
- vTaskDelayUntil( &vLastWakeTime, 2000/portTICK_PERIOD_MS );
- readTemps();
- vTaskDelayUntil( &vLastWakeTime, xFreq );
- #ifdef HTTP_ENABLED
- http_rest_with_url();
- #endif
- vTaskDelayUntil( &vLastWakeTime, xFreq );
- sprintf(txt,"%u",kWh_cnt);
- #ifdef MQTT_ENABLED
- sendMQTTMessage("basement/boiler/onTime", txt);
- #endif
- #ifdef ENABLE_DS18B20
- readTemps();
- #endif
- }
- vTaskDelete(NULL);
- }
|