120 lines
2.9 KiB
C
120 lines
2.9 KiB
C
#include <stdio.h>
|
|
#include "esp_log.h"
|
|
#include "driver/i2c.h"
|
|
#include <esp_system.h>
|
|
#include <bmp280.h>
|
|
#include <dht.h>
|
|
#include <aht.h>
|
|
#include <veml7700.h>
|
|
#include <string.h>
|
|
#include <freertos/FreeRTOS.h>
|
|
#include <freertos/task.h>
|
|
#include "freertos/timers.h"
|
|
|
|
#include "http_metrics.h"
|
|
#include "outputs.h"
|
|
#include "inputs.h"
|
|
|
|
#define I2C_MASTER_SCL 19
|
|
#define I2C_MASTER_SDA 18
|
|
|
|
static const char *TAG = "smart-oil-heater-control-system";
|
|
|
|
void app_main(void)
|
|
{
|
|
ESP_LOGI(TAG, "starting ...");
|
|
|
|
// Initialize NVS
|
|
esp_err_t ret = nvs_flash_init();
|
|
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND)
|
|
{
|
|
ESP_ERROR_CHECK(nvs_flash_erase());
|
|
ret = nvs_flash_init();
|
|
}
|
|
ESP_ERROR_CHECK(ret);
|
|
|
|
connect_wifi(); // will return if successful
|
|
setup_server();
|
|
|
|
sMetric aMetrics[METRIC_MAX_COUNT];
|
|
|
|
/*Sensor Init*/
|
|
ESP_ERROR_CHECK(i2cdev_init());
|
|
|
|
initOutputs();
|
|
initInputs();
|
|
|
|
ESP_LOGI(TAG, "running");
|
|
|
|
while (1)
|
|
{
|
|
ESP_LOGI(TAG, "\n");
|
|
vTaskDelay(pdMS_TO_TICKS(5000));
|
|
uint16_t u16MetricCounter = 0U;
|
|
|
|
/*Wifi RSSI*/
|
|
wifi_ap_record_t ap;
|
|
esp_wifi_sta_get_ap_info(&ap);
|
|
// printf("WiFi RSSI: %d\n", ap.rssi);
|
|
strcpy(aMetrics[u16MetricCounter].caMetricName, "wifi_rssi");
|
|
aMetrics[0].fMetricValue = ap.rssi;
|
|
u16MetricCounter++;
|
|
|
|
vSetMetrics(aMetrics, u16MetricCounter);
|
|
|
|
if (getBurnerError() == FAULT)
|
|
{
|
|
ESP_LOGI(TAG, "Burner FAULT");
|
|
}
|
|
else
|
|
{
|
|
ESP_LOGI(TAG, "Burner OK");
|
|
}
|
|
|
|
/*
|
|
setCirculationPumpState(ENABLED);
|
|
setBurnerState(ENABLED);
|
|
|
|
if (getBurnerState() == ENABLED)
|
|
{
|
|
ESP_LOGI(TAG, "Burner ENABLED");
|
|
}
|
|
else
|
|
{
|
|
ESP_LOGI(TAG, "Burner DISABLED");
|
|
}
|
|
|
|
if (getCirculationPumpState() == ENABLED)
|
|
{
|
|
ESP_LOGI(TAG, "CirculationPump ENABLED");
|
|
}
|
|
else
|
|
{
|
|
ESP_LOGI(TAG, "CirculationPump DISABLED");
|
|
}
|
|
|
|
ESP_LOGI(TAG,"\n");
|
|
vTaskDelay(pdMS_TO_TICKS(2000));
|
|
setCirculationPumpState(DISABLED);
|
|
setBurnerState(DISABLED);
|
|
|
|
if (getBurnerState() == ENABLED)
|
|
{
|
|
ESP_LOGI(TAG, "Burner ENABLED");
|
|
}
|
|
else
|
|
{
|
|
ESP_LOGI(TAG, "Burner DISABLED");
|
|
}
|
|
|
|
if (getCirculationPumpState() == ENABLED)
|
|
{
|
|
ESP_LOGI(TAG, "CirculationPump ENABLED");
|
|
}
|
|
else
|
|
{
|
|
ESP_LOGI(TAG, "CirculationPump DISABLED");
|
|
}
|
|
*/
|
|
}
|
|
} |