improve stability
This commit is contained in:
parent
88aef600c8
commit
0fb6e34958
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
@ -7,7 +7,9 @@
|
|||||||
"outputs.h": "c",
|
"outputs.h": "c",
|
||||||
"task.h": "c",
|
"task.h": "c",
|
||||||
"metrics.h": "c",
|
"metrics.h": "c",
|
||||||
"freertos.h": "c"
|
"freertos.h": "c",
|
||||||
|
"compare": "c",
|
||||||
|
"inputs.h": "c"
|
||||||
},
|
},
|
||||||
"idf.openOcdConfigs": [
|
"idf.openOcdConfigs": [
|
||||||
"board/esp32-wrover-kit-3.3v.cfg"
|
"board/esp32-wrover-kit-3.3v.cfg"
|
||||||
|
@ -20,6 +20,7 @@ onewire_addr_t uOneWireAddresses[MAX_DN18B20_SENSORS];
|
|||||||
float fDS18B20Temps[MAX_DN18B20_SENSORS];
|
float fDS18B20Temps[MAX_DN18B20_SENSORS];
|
||||||
size_t sSensorCount = 0U;
|
size_t sSensorCount = 0U;
|
||||||
|
|
||||||
|
static SemaphoreHandle_t xMutexAccessInputs = NULL;
|
||||||
static eBurnerErrorState sBurnerErrorState;
|
static eBurnerErrorState sBurnerErrorState;
|
||||||
static float fChamperTemperature;
|
static float fChamperTemperature;
|
||||||
static float fOutdoorTemperature;
|
static float fOutdoorTemperature;
|
||||||
@ -41,6 +42,13 @@ void initInputs(void)
|
|||||||
|
|
||||||
gpio_config(&ioConfBurnerFault);
|
gpio_config(&ioConfBurnerFault);
|
||||||
|
|
||||||
|
xMutexAccessInputs = xSemaphoreCreateBinary();
|
||||||
|
if (xMutexAccessInputs == NULL)
|
||||||
|
{
|
||||||
|
ESP_LOGE(TAG, "Unable to create mutex");
|
||||||
|
}
|
||||||
|
xSemaphoreGive(xMutexAccessInputs);
|
||||||
|
|
||||||
BaseType_t taskCreated = xTaskCreate(
|
BaseType_t taskCreated = xTaskCreate(
|
||||||
taskInput, // Function to implement the task
|
taskInput, // Function to implement the task
|
||||||
"taskInput", // Task name
|
"taskInput", // Task name
|
||||||
@ -105,23 +113,27 @@ void taskInput(void *pvParameters)
|
|||||||
{
|
{
|
||||||
float temp_c = fDS18B20Temps[j];
|
float temp_c = fDS18B20Temps[j];
|
||||||
ESP_LOGI(TAG, "Sensor: %08" PRIx64 " reports %.3f°C", (uint64_t)uOneWireAddresses[j], temp_c);
|
ESP_LOGI(TAG, "Sensor: %08" PRIx64 " reports %.3f°C", (uint64_t)uOneWireAddresses[j], temp_c);
|
||||||
|
if (xSemaphoreTake(xMutexAccessInputs, portMAX_DELAY) == pdTRUE)
|
||||||
switch ((uint64_t)uOneWireAddresses[j])
|
|
||||||
{
|
{
|
||||||
case ((uint64_t)uChamperTempSensorAddr):
|
switch ((uint64_t)uOneWireAddresses[j])
|
||||||
fChamperTemperature = temp_c;
|
{
|
||||||
break;
|
case ((uint64_t)uChamperTempSensorAddr):
|
||||||
case ((uint64_t)uOutdoorTempSensorAddr):
|
fChamperTemperature = temp_c;
|
||||||
fOutdoorTemperature = temp_c;
|
break;
|
||||||
break;
|
case ((uint64_t)uOutdoorTempSensorAddr):
|
||||||
case ((uint64_t)uInletFlowTempSensorAddr):
|
fOutdoorTemperature = temp_c;
|
||||||
fInletFlowTemperature = temp_c;
|
break;
|
||||||
break;
|
case ((uint64_t)uInletFlowTempSensorAddr):
|
||||||
case ((uint64_t)uReturnFlowTempSensorAddr):
|
fInletFlowTemperature = temp_c;
|
||||||
fReturnFlowTemperature = temp_c;
|
break;
|
||||||
break;
|
case ((uint64_t)uReturnFlowTempSensorAddr):
|
||||||
default:
|
fReturnFlowTemperature = temp_c;
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
xSemaphoreGive(xMutexAccessInputs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -131,21 +143,51 @@ void taskInput(void *pvParameters)
|
|||||||
|
|
||||||
float getChamberTemperature(void)
|
float getChamberTemperature(void)
|
||||||
{
|
{
|
||||||
return fChamperTemperature;
|
float ret = 0.0f;
|
||||||
|
if (xSemaphoreTake(xMutexAccessInputs, portMAX_DELAY) == pdTRUE)
|
||||||
|
{
|
||||||
|
ret = fChamperTemperature;
|
||||||
|
xSemaphoreGive(xMutexAccessInputs);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
float getOutdoorTemperature(void)
|
float getOutdoorTemperature(void)
|
||||||
{
|
{
|
||||||
return fOutdoorTemperature;
|
float ret = 0.0f;
|
||||||
|
if (xSemaphoreTake(xMutexAccessInputs, portMAX_DELAY) == pdTRUE)
|
||||||
|
{
|
||||||
|
ret = fOutdoorTemperature;
|
||||||
|
xSemaphoreGive(xMutexAccessInputs);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
float getInletFlowTemperature(void)
|
float getInletFlowTemperature(void)
|
||||||
{
|
{
|
||||||
return fInletFlowTemperature;
|
float ret = 0.0f;
|
||||||
|
if (xSemaphoreTake(xMutexAccessInputs, portMAX_DELAY) == pdTRUE)
|
||||||
|
{
|
||||||
|
ret = fInletFlowTemperature;
|
||||||
|
xSemaphoreGive(xMutexAccessInputs);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
float getReturnFlowTemperature(void)
|
float getReturnFlowTemperature(void)
|
||||||
{
|
{
|
||||||
return fReturnFlowTemperature;
|
float ret = 0.0f;
|
||||||
|
if (xSemaphoreTake(xMutexAccessInputs, portMAX_DELAY) == pdTRUE)
|
||||||
|
{
|
||||||
|
ret = fReturnFlowTemperature;
|
||||||
|
xSemaphoreGive(xMutexAccessInputs);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
eBurnerErrorState getBurnerError(void)
|
eBurnerErrorState getBurnerError(void)
|
||||||
{
|
{
|
||||||
return sBurnerErrorState;
|
eBurnerErrorState ret = FAULT;
|
||||||
|
if (xSemaphoreTake(xMutexAccessInputs, portMAX_DELAY) == pdTRUE)
|
||||||
|
{
|
||||||
|
ret = sBurnerErrorState;
|
||||||
|
xSemaphoreGive(xMutexAccessInputs);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
@ -30,6 +30,9 @@ static sMetric aMetrics[METRIC_MAX_COUNT];
|
|||||||
static uint16_t u16MetricCounter = 0U;
|
static uint16_t u16MetricCounter = 0U;
|
||||||
|
|
||||||
void taskMetrics(void *pvParameters);
|
void taskMetrics(void *pvParameters);
|
||||||
|
void connect_wifi(void);
|
||||||
|
httpd_handle_t setup_server(void);
|
||||||
|
esp_err_t get_metrics_handler(httpd_req_t *req);
|
||||||
|
|
||||||
void initMetrics(void)
|
void initMetrics(void)
|
||||||
{
|
{
|
||||||
@ -39,7 +42,7 @@ void initMetrics(void)
|
|||||||
BaseType_t taskCreated = xTaskCreate(
|
BaseType_t taskCreated = xTaskCreate(
|
||||||
taskMetrics, // Function to implement the task
|
taskMetrics, // Function to implement the task
|
||||||
"taskMetrics", // Task name
|
"taskMetrics", // Task name
|
||||||
2048, // Stack size (in words, not bytes)
|
4096, // Stack size (in words, not bytes)
|
||||||
NULL, // Parameters to the task function (none in this case)
|
NULL, // Parameters to the task function (none in this case)
|
||||||
5, // Task priority (higher number = higher priority)
|
5, // Task priority (higher number = higher priority)
|
||||||
NULL // Task handle (optional)
|
NULL // Task handle (optional)
|
||||||
@ -268,24 +271,22 @@ esp_err_t get_metrics_handler(httpd_req_t *req)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
httpd_uri_t uri_get = {
|
|
||||||
.uri = "/metrics",
|
|
||||||
.method = HTTP_GET,
|
|
||||||
.handler = get_metrics_handler,
|
|
||||||
.user_ctx = NULL};
|
|
||||||
|
|
||||||
httpd_handle_t setup_server(void)
|
httpd_handle_t setup_server(void)
|
||||||
{
|
{
|
||||||
httpd_config_t config = HTTPD_DEFAULT_CONFIG();
|
httpd_config_t config = HTTPD_DEFAULT_CONFIG();
|
||||||
config.server_port = 9100;
|
config.server_port = 9100;
|
||||||
httpd_handle_t server = NULL;
|
httpd_handle_t server = NULL;
|
||||||
|
|
||||||
|
httpd_uri_t uri_get = {
|
||||||
|
.uri = "/metrics",
|
||||||
|
.method = HTTP_GET,
|
||||||
|
.handler = get_metrics_handler,
|
||||||
|
.user_ctx = NULL};
|
||||||
|
|
||||||
xMutexAccessMetricResponse = xSemaphoreCreateBinary();
|
xMutexAccessMetricResponse = xSemaphoreCreateBinary();
|
||||||
if (xMutexAccessMetricResponse == NULL)
|
if (xMutexAccessMetricResponse == NULL)
|
||||||
{
|
{
|
||||||
ESP_LOGE(TAG, "Unable to create mutex for metric response");
|
ESP_LOGE(TAG, "Unable to create mutex for metric response");
|
||||||
vTaskDelay(pdMS_TO_TICKS(300 * 60)); // wait 5min before restart
|
|
||||||
esp_restart();
|
|
||||||
}
|
}
|
||||||
xSemaphoreGive(xMutexAccessMetricResponse);
|
xSemaphoreGive(xMutexAccessMetricResponse);
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#define WIFI_CONNECTED_BIT BIT0
|
#define WIFI_CONNECTED_BIT BIT0
|
||||||
#define WIFI_FAIL_BIT BIT1
|
#define WIFI_FAIL_BIT BIT1
|
||||||
#define HTML_RESPONSE_SIZE 256U
|
#define HTML_RESPONSE_SIZE 512U
|
||||||
#define METRIC_NAME_MAX_SIZE 64U
|
#define METRIC_NAME_MAX_SIZE 64U
|
||||||
#define METRIC_MAX_COUNT 32U
|
#define METRIC_MAX_COUNT 32U
|
||||||
|
|
||||||
@ -15,7 +15,4 @@ typedef struct _metric
|
|||||||
} sMetric;
|
} sMetric;
|
||||||
|
|
||||||
void initMetrics(void);
|
void initMetrics(void);
|
||||||
|
|
||||||
void connect_wifi(void);
|
|
||||||
httpd_handle_t setup_server(void);
|
|
||||||
void vSetMetrics(sMetric *paMetrics, uint16_t u16Size);
|
void vSetMetrics(sMetric *paMetrics, uint16_t u16Size);
|
@ -5,9 +5,11 @@
|
|||||||
|
|
||||||
#include "outputs.h"
|
#include "outputs.h"
|
||||||
|
|
||||||
|
static const char *TAG = "smart-oil-heater-control-system-outputs";
|
||||||
const uint8_t uCirculationPumpGpioPin = 27U;
|
const uint8_t uCirculationPumpGpioPin = 27U;
|
||||||
const uint8_t uBurnerGpioPin = 14U;
|
const uint8_t uBurnerGpioPin = 14U;
|
||||||
|
|
||||||
|
static SemaphoreHandle_t xMutexAccessOutputs = NULL;
|
||||||
static eOutput sCirculationPumpState;
|
static eOutput sCirculationPumpState;
|
||||||
static eOutput sBurnerState;
|
static eOutput sBurnerState;
|
||||||
|
|
||||||
@ -30,6 +32,13 @@ void initOutputs(void)
|
|||||||
};
|
};
|
||||||
gpio_config(&ioConfCirculationPump);
|
gpio_config(&ioConfCirculationPump);
|
||||||
gpio_config(&ioConfBurner);
|
gpio_config(&ioConfBurner);
|
||||||
|
|
||||||
|
xMutexAccessOutputs = xSemaphoreCreateBinary();
|
||||||
|
if (xMutexAccessOutputs == NULL)
|
||||||
|
{
|
||||||
|
ESP_LOGE(TAG, "Unable to create mutex");
|
||||||
|
}
|
||||||
|
xSemaphoreGive(xMutexAccessOutputs);
|
||||||
}
|
}
|
||||||
|
|
||||||
eOutput getCirculationPumpState(void)
|
eOutput getCirculationPumpState(void)
|
||||||
@ -39,35 +48,49 @@ eOutput getCirculationPumpState(void)
|
|||||||
|
|
||||||
void setCirculationPumpState(eOutput in)
|
void setCirculationPumpState(eOutput in)
|
||||||
{
|
{
|
||||||
sCirculationPumpState = in;
|
if (xSemaphoreTake(xMutexAccessOutputs, portMAX_DELAY) == pdTRUE)
|
||||||
switch (sCirculationPumpState)
|
|
||||||
{
|
{
|
||||||
case ENABLED:
|
sCirculationPumpState = in;
|
||||||
gpio_set_level(uCirculationPumpGpioPin, 1U); // Switch on Circulation Pump
|
switch (sCirculationPumpState)
|
||||||
break;
|
{
|
||||||
case DISABLED:
|
case ENABLED:
|
||||||
gpio_set_level(uCirculationPumpGpioPin, 0U); // Switch off Circulation Pump
|
gpio_set_level(uCirculationPumpGpioPin, 1U); // Switch on Circulation Pump
|
||||||
default:
|
break;
|
||||||
break;
|
case DISABLED:
|
||||||
|
gpio_set_level(uCirculationPumpGpioPin, 0U); // Switch off Circulation Pump
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
xSemaphoreGive(xMutexAccessOutputs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
eOutput getBurnerState(void)
|
eOutput getBurnerState(void)
|
||||||
{
|
{
|
||||||
return sBurnerState;
|
eOutput ret = ENABLED;
|
||||||
|
if (xSemaphoreTake(xMutexAccessOutputs, portMAX_DELAY) == pdTRUE)
|
||||||
|
{
|
||||||
|
ret = sBurnerState;
|
||||||
|
xSemaphoreGive(xMutexAccessOutputs);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setBurnerState(eOutput in)
|
void setBurnerState(eOutput in)
|
||||||
{
|
{
|
||||||
sBurnerState = in;
|
if (xSemaphoreTake(xMutexAccessOutputs, portMAX_DELAY) == pdTRUE)
|
||||||
switch (sBurnerState)
|
|
||||||
{
|
{
|
||||||
case ENABLED:
|
sBurnerState = in;
|
||||||
gpio_set_level(uBurnerGpioPin, 0U); // Switch on Burner
|
switch (sBurnerState)
|
||||||
break;
|
{
|
||||||
case DISABLED:
|
case ENABLED:
|
||||||
gpio_set_level(uBurnerGpioPin, 1U); // Switch off Burner
|
gpio_set_level(uBurnerGpioPin, 0U); // Switch on Burner
|
||||||
default:
|
break;
|
||||||
break;
|
case DISABLED:
|
||||||
|
gpio_set_level(uBurnerGpioPin, 1U); // Switch off Burner
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
xSemaphoreGive(xMutexAccessOutputs);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user