read temperatur via 1-Wire
This commit is contained in:
		| @ -57,7 +57,8 @@ Safety <|-- HTTP_Metrics | ||||
|  | ||||
|  | ||||
| | Function| ESP32 | ES32C14 | | ||||
| |------------------|-----------------|------------------| | ||||
| | CirculationPump   | IO27  | Relay 1 NO1               | | ||||
| | Burner            | IO14  | Relay 1 NC2               | | ||||
| | Burner Fault      | IO19  | Digital Input IN1         | | ||||
| |-----------------------|-------|---------------------------| | ||||
| | CirculationPump       | IO27  | Relay 1 NO1               | | ||||
| | Burner                | IO14  | Relay 1 NC2               | | ||||
| | Burner Fault          | IO19  | Digital Input IN1         | | ||||
| | Temperature DS10B20   | IO04  | 1-Wire                    | | ||||
|  | ||||
| @ -2,12 +2,30 @@ | ||||
| #include "freertos/task.h" | ||||
| #include "driver/gpio.h" | ||||
| #include "esp_log.h" | ||||
| #include <ds18x20.h> | ||||
|  | ||||
| #include "inputs.h" | ||||
|  | ||||
| #define MAX_DN18B20_SENSORS 4U | ||||
|  | ||||
| static const char *TAG = "smart-oil-heater-control-system-inputs"; | ||||
| const uint8_t uBurnerFaultPin = 19U; | ||||
| const uint8_t uDS18B20Pin = 4U; | ||||
| const onewire_addr_t uChamperTempSensorAddr = 0x3e0000001754be28; | ||||
| const onewire_addr_t uOutdoorTempSensorAddr = 0x880000001648e328; | ||||
| const onewire_addr_t uInletFlowTempSensorAddr = 0xe59cdef51e64ff28; | ||||
| const onewire_addr_t uReturnFlowTempSensorAddr = 0xa7a8e1531f64ff28; | ||||
|  | ||||
| onewire_addr_t uOneWireAddresses[MAX_DN18B20_SENSORS]; | ||||
| float fDS18B20Temps[MAX_DN18B20_SENSORS]; | ||||
| size_t sSensorCount = 0U; | ||||
|  | ||||
| static eBurnerErrorState sBurnerErrorState; | ||||
| static float fChamperTemperature; | ||||
| static float fOutdoorTemperature; | ||||
| static float fInletFlowTemperature; | ||||
| static float fReturnFlowTemperature; | ||||
|  | ||||
| void loop(void *pvParameters); | ||||
|  | ||||
| void initInputs(void) | ||||
| @ -44,11 +62,10 @@ void initInputs(void) | ||||
|  | ||||
| void loop(void *pvParameters) | ||||
| { | ||||
|     // This task will run in a loop | ||||
|     while (1) | ||||
|     { | ||||
|         ESP_LOGI(TAG, "Running task Input..."); | ||||
|         vTaskDelay(1000 / portTICK_PERIOD_MS); // Delay for 1 second | ||||
|         vTaskDelay(1000U / portTICK_PERIOD_MS); | ||||
|  | ||||
|         if (gpio_get_level(uBurnerFaultPin) == 1) | ||||
|         { | ||||
| @ -58,24 +75,75 @@ void loop(void *pvParameters) | ||||
|         { | ||||
|             sBurnerErrorState = NO_ERROR; | ||||
|         } | ||||
|  | ||||
|         if (ds18x20_scan_devices(uDS18B20Pin, uOneWireAddresses, MAX_DN18B20_SENSORS, &sSensorCount) != ESP_OK) | ||||
|         { | ||||
|             ESP_LOGE(TAG, "1-Wire device scan error!"); | ||||
|         } | ||||
|  | ||||
|         if (!sSensorCount) | ||||
|         { | ||||
|             ESP_LOGW(TAG, "No 1-Wire devices detected!"); | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             ESP_LOGI(TAG, "%d 1-Wire devices detected", sSensorCount); | ||||
|  | ||||
|             if (sSensorCount > MAX_DN18B20_SENSORS) | ||||
|             { | ||||
|                 sSensorCount = MAX_DN18B20_SENSORS; | ||||
|                 ESP_LOGW(TAG, "More 1-Wire devices found than expected!"); | ||||
|             } | ||||
|  | ||||
|             if (ds18x20_measure_and_read_multi(uDS18B20Pin, uOneWireAddresses, sSensorCount, fDS18B20Temps) != ESP_OK) | ||||
|             { | ||||
|                 ESP_LOGE(TAG, "1-Wire devices read error"); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 for (int j = 0; j < sSensorCount; j++) | ||||
|                 { | ||||
|                     float temp_c = fDS18B20Temps[j]; | ||||
|                     ESP_LOGI(TAG, "Sensor: %08" PRIx64 " reports %.3f°C", (uint64_t)uOneWireAddresses[j], temp_c); | ||||
|  | ||||
|                     switch ((uint64_t)uOneWireAddresses[j]) | ||||
|                     { | ||||
|                     case ((uint64_t)uChamperTempSensorAddr): | ||||
|                         fChamperTemperature = temp_c; | ||||
|                         break; | ||||
|                     case ((uint64_t)uOutdoorTempSensorAddr): | ||||
|                         fOutdoorTemperature = temp_c; | ||||
|                         break; | ||||
|                     case ((uint64_t)uInletFlowTempSensorAddr): | ||||
|                         fInletFlowTemperature = temp_c; | ||||
|                         break; | ||||
|                     case ((uint64_t)uReturnFlowTempSensorAddr): | ||||
|                         fReturnFlowTemperature = temp_c; | ||||
|                         break; | ||||
|                     default: | ||||
|                         break; | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| float getChamberTemperature(void) | ||||
| { | ||||
|     return 42.42; | ||||
|     return fChamperTemperature; | ||||
| } | ||||
| float getOutdoorTemperature(void) | ||||
| { | ||||
|     return 42.42; | ||||
|     return fOutdoorTemperature; | ||||
| } | ||||
| float getInletFlowTemperature(void) | ||||
| { | ||||
|     return 42.42; | ||||
|     return fInletFlowTemperature; | ||||
| } | ||||
| float getReturnFlowTemperature(void) | ||||
| { | ||||
|     return 42.42; | ||||
|     return fReturnFlowTemperature; | ||||
| } | ||||
| eBurnerErrorState getBurnerError(void) | ||||
| { | ||||
|  | ||||
		Reference in New Issue
	
	Block a user